Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 328fdcc

Browse files
the-dwyerdavidsh
authored andcommitted
Increase code coverage for System.Net.Security (#26044)
* Improve code coverage for System.IO.FileSystem.AccessControl * Added check on parameter names for ArgumentNullExceptions and only passing in one null parameter * add tests for gets and sets that do not throw exceptions * renamed tests with returns valid object and removed set tests * use temp directory and file * use temp directory and file * use TempDirectory and TempFile from Common code * remove reference that is not needed * call extension method from object * increase code coverage * Increase code coverage System.Net.Security * requested changes from Priya91 * change requested by danmosemsft
1 parent 026501b commit 328fdcc

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

src/System.Net.Security/tests/UnitTests/System.Net.Security.Unit.Tests.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
<Compile Include="SslApplicationProtocolTests.cs" />
2525
<Compile Include="SslAuthenticationOptionsTests.cs" />
2626
<Compile Include="SslStreamAllowedProtocolsTest.cs" />
27+
<Compile Include="System\Security\Authentication\AuthenticationExceptionTest.cs" />
2728
<Compile Include="System\Security\Authentication\ExtendedProtection\ExtendedProtectionPolicyTest.cs" />
29+
<Compile Include="System\Security\Authentication\InvalidCredentialExceptionTest.cs" />
2830
<Compile Include="TlsAlertsMatchWindowsInterop.cs" />
2931
<!-- Fakes -->
3032
<Compile Include="Fakes\FakeSslState.cs" />
@@ -84,4 +86,4 @@
8486
<Reference Include="System.Threading.Tasks" />
8587
</ItemGroup>
8688
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
87-
</Project>
89+
</Project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Security.Authentication;
6+
using Xunit;
7+
8+
namespace System.Net.Security.Tests
9+
{
10+
public class AuthenticationExceptionTest
11+
{
12+
[Fact]
13+
public void Constructor_NoParameter_DefaultMessageIsNotNull()
14+
{
15+
AuthenticationException authenticationException = new AuthenticationException();
16+
17+
Assert.NotNull(authenticationException.Message);
18+
}
19+
20+
[Fact]
21+
public void Constructor_String_PassedInMessageCorrect()
22+
{
23+
const string passedInMessage = "base was called";
24+
25+
AuthenticationException authenticationException = new AuthenticationException(passedInMessage);
26+
27+
Assert.Equal(passedInMessage, authenticationException.Message);
28+
}
29+
30+
[Fact]
31+
public void Constructor_String_Exception_MessagesCorrect()
32+
{
33+
const string passedInMessage = "base was called";
34+
const string innerExceptionMessage = "this is the inner exception message";
35+
36+
AuthenticationException authenticationException = new AuthenticationException(passedInMessage, new Exception(innerExceptionMessage));
37+
38+
Assert.Equal(passedInMessage, authenticationException.Message);
39+
Assert.Equal(innerExceptionMessage, authenticationException.InnerException.Message);
40+
}
41+
}
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Security.Authentication;
6+
using Xunit;
7+
8+
namespace System.Net.Security.Tests
9+
{
10+
public class InvalidCredentialExceptionTest
11+
{
12+
[Fact]
13+
public void Constructor_NoParameter_DefaultMessageIsNotNull()
14+
{
15+
InvalidCredentialException invalidCredentialException = new InvalidCredentialException();
16+
17+
Assert.NotNull(invalidCredentialException.Message);
18+
}
19+
20+
[Fact]
21+
public void Constructor_String_PassedInMessageCorrect()
22+
{
23+
const string passedInMessage = "base was called";
24+
25+
InvalidCredentialException invalidCredentialException = new InvalidCredentialException(passedInMessage);
26+
27+
Assert.Equal(passedInMessage, invalidCredentialException.Message);
28+
}
29+
30+
[Fact]
31+
public void Constructor_String_Exception_MessagesCorrect()
32+
{
33+
const string passedInMessage = "base was called";
34+
const string innerExceptionMessage = "this is the inner exception message";
35+
36+
InvalidCredentialException invalidCredentialException = new InvalidCredentialException(passedInMessage, new Exception(innerExceptionMessage));
37+
38+
Assert.Equal(passedInMessage, invalidCredentialException.Message);
39+
Assert.Equal(innerExceptionMessage, invalidCredentialException.InnerException.Message);
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)