Skip to content

Commit c14eaa7

Browse files
committed
add 100% coverage for the models
1 parent 18cee7a commit c14eaa7

5 files changed

Lines changed: 106 additions & 5 deletions

File tree

src/KK.AspNetCore.EasyAuthAuthentication/KK.AspNetCore.EasyAuthAuthentication.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<WarningsAsErrors>
2626
CS8600;CS8602;CS8603<!--The identifiers are all for nullable errors. See here: https://www.tabsoverspaces.com/233764-switch-to-errors-instead-of-warnings-for-nullable-reference-types-in-csharp-8-->
2727
</WarningsAsErrors>
28+
<EnableNETAnalyzers>true</EnableNETAnalyzers>
2829
</PropertyGroup>
2930

3031
<ItemGroup>

src/KK.AspNetCore.EasyAuthAuthentication/Services/LocalAuthMeService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly: InternalsVisibleTo("KK.AspNetCore.EasyAuthAuthentication.Test")]
14
namespace KK.AspNetCore.EasyAuthAuthentication.Services
25
{
36
using System;
@@ -11,8 +14,7 @@ namespace KK.AspNetCore.EasyAuthAuthentication.Services
1114
using Microsoft.AspNetCore.Http;
1215
using Microsoft.Extensions.Logging;
1316
using Newtonsoft.Json;
14-
using Newtonsoft.Json.Linq;
15-
17+
using Newtonsoft.Json.Linq;
1618
internal class LocalAuthMeService
1719
{
1820
public LocalAuthMeService(

test/KK.AspNetCore.EasyAuthAuthentication.Test/KK.AspNetCore.EasyAuthAuthentication.Test.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
1+
<Project Sdk="Microsoft.NET.Sdk">
32
<PropertyGroup>
43
<TargetFramework>netcoreapp3.1</TargetFramework>
5-
64
<IsPackable>false</IsPackable>
75
</PropertyGroup>
86

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
namespace KK.AspNetCore.EasyAuthAuthentication.Test.Models
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
using KK.AspNetCore.EasyAuthAuthentication.Models;
7+
using KK.AspNetCore.EasyAuthAuthentication.Services;
8+
using Xunit;
9+
10+
public class LocalProviderOptionTest
11+
{
12+
[Fact]
13+
public void TestIfTheEmptyCtorCreatesEmptyStrings() // not null!
14+
{
15+
// Arrange
16+
// Act
17+
var options = new LocalProviderOption();
18+
// Assert
19+
Assert.Equal(string.Empty, options.AuthEndpoint);
20+
Assert.Equal(string.Empty, options.NameClaimType);
21+
Assert.Equal(string.Empty, options.RoleClaimType);
22+
}
23+
24+
[Fact]
25+
public void ChangeNameClaimTypeIfItsNotAnEmptyString()
26+
{
27+
// Arrange
28+
var options = new LocalProviderOption();
29+
// Act
30+
options.ChangeModel(new LocalProviderOption()
31+
{
32+
NameClaimType = "not empty"
33+
});
34+
// assert
35+
Assert.Equal("not empty", options.NameClaimType);
36+
}
37+
[Fact]
38+
public void ChangeAuthEndpointIfItsNotAnEmptyString()
39+
{
40+
// Arrange
41+
var options = new LocalProviderOption();
42+
// Act
43+
options.ChangeModel(new LocalProviderOption()
44+
{
45+
AuthEndpoint = "not empty"
46+
});
47+
// assert
48+
Assert.Equal("not empty", options.AuthEndpoint);
49+
}
50+
[Fact]
51+
public void ChangeRoleClaimTypeIfItsNotAnEmptyString()
52+
{
53+
// Arrange
54+
var options = new LocalProviderOption();
55+
// Act
56+
options.ChangeModel(new LocalProviderOption()
57+
{
58+
RoleClaimType = "not empty"
59+
});
60+
// assert
61+
Assert.Equal("not empty", options.RoleClaimType);
62+
}
63+
[Fact]
64+
public void NothingChangegIfThereOnlyEmptyStrings()
65+
{
66+
// Arrange
67+
var options = new LocalProviderOption("endpoint", "claim", "role");
68+
// Act
69+
options.ChangeModel(new LocalProviderOption());
70+
// assert
71+
Assert.Equal("endpoint", options.AuthEndpoint);
72+
Assert.Equal("claim", options.NameClaimType);
73+
Assert.Equal("role", options.RoleClaimType);
74+
}
75+
76+
[Fact]
77+
public void GetProviderOptionsForLocalAuthMeService()
78+
{
79+
// Arrange
80+
var options = new LocalProviderOption("endpoint", "claim", "role");
81+
// Act;
82+
var providerOptions = options.GetProviderOptions();
83+
// Assert
84+
Assert.Equal(typeof(LocalAuthMeService).Name, providerOptions.ProviderName);
85+
Assert.Equal("claim", providerOptions.NameClaimType);
86+
Assert.Equal("role", providerOptions.RoleClaimType);
87+
}
88+
}
89+
}

test/KK.AspNetCore.EasyAuthAuthentication.Test/Models/ProviederOptionsTest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,16 @@ public void IfTheOptionsAreSetTheyShouldChanged()
8181
Assert.Equal("Pferd", options.RoleClaimType);
8282
Assert.Equal(providerName, options.ProviderName);
8383
}
84+
85+
[Fact]
86+
public void IfTheClaimTypeIsSetInCtorItMustBePresentInTheOptions()
87+
{
88+
// Arrange
89+
// Act
90+
var options = new ProviderOptions("this is a test provieder", "this is a test name claim type");
91+
// Assert
92+
Assert.Equal("this is a test provieder", options.ProviderName);
93+
Assert.Equal("this is a test name claim type", options.NameClaimType);
94+
}
8495
}
8596
}

0 commit comments

Comments
 (0)