diff --git a/src/libraries/System.Net.Primitives/ref/System.Net.Primitives.cs b/src/libraries/System.Net.Primitives/ref/System.Net.Primitives.cs index 770d0cd351a3b3..678a3e20bbc1f1 100644 --- a/src/libraries/System.Net.Primitives/ref/System.Net.Primitives.cs +++ b/src/libraries/System.Net.Primitives/ref/System.Net.Primitives.cs @@ -89,6 +89,8 @@ public void SetCookies(System.Uri uri, string cookieHeader) { } public partial class CookieException : System.FormatException, System.Runtime.Serialization.ISerializable { public CookieException() { } + public CookieException(string? message) { } + public CookieException(string? message, System.Exception? innerException) { } [System.ObsoleteAttribute("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId = "SYSLIB0051", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] protected CookieException(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext) { } diff --git a/src/libraries/System.Net.Primitives/src/System/Net/CookieException.cs b/src/libraries/System.Net.Primitives/src/System/Net/CookieException.cs index e53dcfda1d56b5..dcf3d401af6825 100644 --- a/src/libraries/System.Net.Primitives/src/System/Net/CookieException.cs +++ b/src/libraries/System.Net.Primitives/src/System/Net/CookieException.cs @@ -14,11 +14,21 @@ public CookieException() : base() { } - internal CookieException(string? message) : base(message) + /// + /// Initializes a new instance of the class with the specified error message. + /// + /// A that describes the error that occurred. + public CookieException(string? message) : base(message) { } - internal CookieException(string? message, Exception? inner) : base(message, inner) + /// + /// Initializes a new instance of the class with the specified error message + /// and a reference to the inner exception that is the cause of this exception. + /// + /// A that describes the error that occurred. + /// The exception that is the cause of the current exception. + public CookieException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/src/libraries/System.Net.Primitives/tests/UnitTests/CookieExceptionTest.cs b/src/libraries/System.Net.Primitives/tests/UnitTests/CookieExceptionTest.cs new file mode 100644 index 00000000000000..f376e08807ec01 --- /dev/null +++ b/src/libraries/System.Net.Primitives/tests/UnitTests/CookieExceptionTest.cs @@ -0,0 +1,28 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Xunit; + +namespace System.Net.Primitives.UnitTests.Tests; + +public sealed class CookieExceptionTest +{ + [Fact] + public void Constructor_Message() + { + var exception = new CookieException("Foo"); + Assert.Equal("Foo", exception.Message); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void Constructor_Message_InnerException(bool innerException) + { + var inner = innerException ? new Exception() : null; + var exception = new CookieException("Foo", inner); + + Assert.Equal("Foo", exception.Message); + Assert.Equal(inner, exception.InnerException); + } +} diff --git a/src/libraries/System.Net.Primitives/tests/UnitTests/Fakes/CookieException.cs b/src/libraries/System.Net.Primitives/tests/UnitTests/Fakes/CookieException.cs index 493a30752971f8..07387dc0d3e998 100644 --- a/src/libraries/System.Net.Primitives/tests/UnitTests/Fakes/CookieException.cs +++ b/src/libraries/System.Net.Primitives/tests/UnitTests/Fakes/CookieException.cs @@ -7,7 +7,7 @@ namespace System.Net public class CookieException : FormatException { public CookieException() : base() { } - internal CookieException(string message) : base(message) { } - internal CookieException(string message, Exception inner) : base(message, inner) { } + public CookieException(string message) : base(message) { } + public CookieException(string message, Exception inner) : base(message, inner) { } } } diff --git a/src/libraries/System.Net.Primitives/tests/UnitTests/System.Net.Primitives.UnitTests.Tests.csproj b/src/libraries/System.Net.Primitives/tests/UnitTests/System.Net.Primitives.UnitTests.Tests.csproj index 411c86ffecc2e2..44a857234a48a6 100644 --- a/src/libraries/System.Net.Primitives/tests/UnitTests/System.Net.Primitives.UnitTests.Tests.csproj +++ b/src/libraries/System.Net.Primitives/tests/UnitTests/System.Net.Primitives.UnitTests.Tests.csproj @@ -15,6 +15,7 @@ +