Skip to content

Commit 3a06797

Browse files
authored
Merge pull request #316 - Added ModelState tests
Added ModelState tests
2 parents eb80fed + 4ec7318 commit 3a06797

File tree

18 files changed

+933
-11
lines changed

18 files changed

+933
-11
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace MyTested.AspNetCore.Mvc.Test.PluginsTests
2+
{
3+
using System;
4+
using Microsoft.Extensions.Caching.Memory;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Plugins;
7+
using Xunit;
8+
9+
public class CachingTestPluginTest
10+
{
11+
[Fact]
12+
public void ShouldThrowArgumentNullExceptionWithInvalidServiceCollection()
13+
{
14+
var testPlugin = new CachingTestPlugin();
15+
16+
Assert.Throws<NullReferenceException>(() => testPlugin.ServiceRegistrationDelegate(null));
17+
}
18+
19+
[Fact]
20+
public void ShouldInvokeMethodOfTypeVoidWithValidServiceCollection()
21+
{
22+
var testPlugin = new CachingTestPlugin();
23+
var serviceCollection = new ServiceCollection();
24+
25+
testPlugin.ServiceRegistrationDelegate(serviceCollection);
26+
27+
var methodReturnType = testPlugin.ServiceRegistrationDelegate.Method.ReturnType.Name;
28+
29+
Assert.True(methodReturnType == "Void");
30+
Assert.Contains(serviceCollection, s => s.ServiceType == typeof(IMemoryCache));
31+
}
32+
}
33+
}

test/MyTested.AspNetCore.Mvc.Controllers.Test/MyTested.AspNetCore.Mvc.Controllers.Test.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@
3434
<PackageReference Include="xunit" Version="2.4.1" />
3535
</ItemGroup>
3636

37+
<ItemGroup>
38+
<Folder Include="PluginsTests\" />
39+
</ItemGroup>
40+
3741
</Project>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
namespace MyTested.AspNetCore.Mvc.Test.PluginsTests
2+
{
3+
using System;
4+
using Microsoft.AspNetCore.Mvc.Internal;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.Extensions.Options;
7+
using Plugins;
8+
using Xunit;
9+
10+
public class ControllersTestPluginTest
11+
{
12+
[Fact]
13+
public void ShouldHavePriorityWithDefaultValue()
14+
{
15+
var testPlugin = new ControllersTestPlugin();
16+
17+
Assert.IsAssignableFrom<IDefaultRegistrationPlugin>(testPlugin);
18+
Assert.NotNull(testPlugin);
19+
Assert.Equal(-10000, testPlugin.Priority);
20+
}
21+
22+
[Fact]
23+
public void ShouldThrowArgumentNullExceptionWithInvalidServiceCollection()
24+
{
25+
var testPlugin = new ControllersTestPlugin();
26+
27+
Assert.Throws<ArgumentNullException>(() => testPlugin.DefaultServiceRegistrationDelegate(null));
28+
Assert.Throws<NullReferenceException>(() => testPlugin.ServiceRegistrationDelegate(null));
29+
}
30+
31+
[Fact]
32+
public void ShouldInvokeMethodOfTypeVoidWithValidServiceCollectionForDefaultRegistration()
33+
{
34+
var testPlugin = new ControllersTestPlugin();
35+
var serviceCollection = new ServiceCollection();
36+
37+
testPlugin.DefaultServiceRegistrationDelegate(serviceCollection);
38+
39+
var methodReturnType = testPlugin.DefaultServiceRegistrationDelegate.Method.ReturnType.Name;
40+
41+
Assert.True(methodReturnType == "Void");
42+
Assert.Contains(serviceCollection, s => s.ServiceType == typeof(MiddlewareFilterBuilder));
43+
}
44+
45+
[Fact]
46+
public void ShouldInvokeMethodOfTypeVoidWithValidServiceCollection()
47+
{
48+
var testPlugin = new ControllersTestPlugin();
49+
var serviceCollection = new ServiceCollection();
50+
51+
testPlugin.ServiceRegistrationDelegate(serviceCollection);
52+
53+
var methodReturnType = testPlugin.ServiceRegistrationDelegate.Method.ReturnType.Name;
54+
55+
Assert.True(methodReturnType == "Void");
56+
Assert.Contains(serviceCollection, s => s.ServiceType == typeof(IOptions<>));
57+
}
58+
}
59+
}
60+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
namespace MyTested.AspNetCore.Mvc.Test.PluginTests
2+
{
3+
using System;
4+
using Microsoft.AspNetCore.Mvc.Formatters.Json.Internal;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Plugins;
7+
using Xunit;
8+
9+
public class ViewActionResultTestPluginTest
10+
{
11+
[Fact]
12+
public void ShouldHavePriorityWithDefaultValue()
13+
{
14+
var testPlugin = new ViewActionResultsTestPlugin();
15+
16+
Assert.IsAssignableFrom<IDefaultRegistrationPlugin>(testPlugin);
17+
Assert.NotNull(testPlugin);
18+
Assert.Equal(-1000, testPlugin.Priority);
19+
}
20+
21+
[Fact]
22+
public void ShouldThrowArgumentNullExceptionWithInvalidServiceCollection()
23+
{
24+
var testPlugin = new ViewActionResultsTestPlugin();
25+
26+
Assert.Throws<ArgumentNullException>(() => testPlugin.DefaultServiceRegistrationDelegate(null));
27+
}
28+
29+
[Fact]
30+
public void ShouldInvokeMethodOfTypeVoidWithValidServiceCollection()
31+
{
32+
var testPlugin = new ViewActionResultsTestPlugin();
33+
var serviceCollection = new ServiceCollection();
34+
35+
testPlugin.DefaultServiceRegistrationDelegate(serviceCollection);
36+
37+
var methodReturnType = testPlugin.DefaultServiceRegistrationDelegate.Method.ReturnType.Name;
38+
39+
Assert.True(methodReturnType == "Void");
40+
Assert.Contains(serviceCollection, s => s.ServiceType == typeof(JsonResultExecutor));
41+
}
42+
}
43+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
namespace MyTested.AspNetCore.Mvc.Test.PluginsTests
2+
{
3+
using System;
4+
using Microsoft.AspNetCore.Mvc.DataAnnotations;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Plugins;
7+
using Xunit;
8+
9+
public class DataAnnotationsTestPluginTest
10+
{
11+
[Fact]
12+
public void ShouldHavePriorityWithDefaultValue()
13+
{
14+
var testPlugin = new DataAnnotationsTestPlugin();
15+
16+
Assert.IsAssignableFrom<IDefaultRegistrationPlugin>(testPlugin);
17+
Assert.NotNull(testPlugin);
18+
Assert.Equal(-2000, testPlugin.Priority);
19+
}
20+
21+
[Fact]
22+
public void ShouldThrowArgumentNullExceptionWithInvalidServiceCollection()
23+
{
24+
var testPlugin = new DataAnnotationsTestPlugin();
25+
26+
Assert.Throws<ArgumentNullException>(() => testPlugin.DefaultServiceRegistrationDelegate(null));
27+
}
28+
29+
[Fact]
30+
public void ShouldInvokeMethodOfTypeVoidWithValidServiceCollection()
31+
{
32+
var testPlugin = new DataAnnotationsTestPlugin();
33+
var serviceCollection = new ServiceCollection();
34+
35+
testPlugin.DefaultServiceRegistrationDelegate(serviceCollection);
36+
37+
var methodReturnType = testPlugin.DefaultServiceRegistrationDelegate.Method.ReturnType.Name;
38+
39+
Assert.True(methodReturnType == "Void");
40+
Assert.Contains(serviceCollection, s => s.ServiceType == typeof(IValidationAttributeAdapterProvider));
41+
}
42+
}
43+
}
44+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
namespace MyTested.AspNetCore.Mvc.Test.PluginsTests
2+
{
3+
using System;
4+
using Setups;
5+
using Setups.Common;
6+
using Microsoft.EntityFrameworkCore;
7+
using Microsoft.Extensions.DependencyInjection;
8+
using Plugins;
9+
using Xunit;
10+
11+
public class EntityFrameworkCoreTestPluginTest
12+
{
13+
[Fact]
14+
public void ShouldThrowArgumentNullExceptionWithInvalidServiceCollection()
15+
{
16+
var testPlugin = new EntityFrameworkCoreTestPlugin();
17+
18+
Assert.Throws<ArgumentNullException>(() => testPlugin.ServiceRegistrationDelegate(null));
19+
}
20+
21+
[Fact]
22+
public void ShouldInvokeMethodOfTypeVoidWithValidServiceCollection()
23+
{
24+
var testPlugin = new EntityFrameworkCoreTestPlugin();
25+
var serviceCollection = new ServiceCollection();
26+
serviceCollection.AddDbContext<CustomDbContext>(options => options.UseInMemoryDatabase(TestObjectFactory.TestDatabaseName));
27+
28+
testPlugin.ServiceRegistrationDelegate(serviceCollection);
29+
30+
var methodReturnType = testPlugin.ServiceRegistrationDelegate.Method.ReturnType.Name;
31+
32+
Assert.True(methodReturnType == "Void");
33+
Assert.Contains(serviceCollection, s => s.ServiceType == typeof(DbContextOptions));
34+
}
35+
}
36+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
namespace MyTested.AspNetCore.Mvc.Test.PluginsTests
2+
{
3+
using System;
4+
using Microsoft.AspNetCore.Mvc.Formatters.Json.Internal;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.Extensions.Options;
7+
using Plugins;
8+
using Xunit;
9+
10+
public class HttpTestPluginTest
11+
{
12+
[Fact]
13+
public void ShouldHavePriorityWithDefaultValue()
14+
{
15+
var testPlugin = new HttpTestPlugin();
16+
17+
Assert.IsAssignableFrom<IDefaultRegistrationPlugin>(testPlugin);
18+
Assert.NotNull(testPlugin);
19+
Assert.Equal(-9000, testPlugin.Priority);
20+
}
21+
22+
[Fact]
23+
public void ShouldThrowArgumentNullExceptionWithInvalidServiceCollection()
24+
{
25+
var testPlugin = new HttpTestPlugin();
26+
27+
Assert.Throws<ArgumentNullException>(() => testPlugin.DefaultServiceRegistrationDelegate(null));
28+
Assert.Throws<NullReferenceException>(() => testPlugin.ServiceRegistrationDelegate(null));
29+
}
30+
31+
[Fact]
32+
public void ShouldInvokeMethodOfTypeVoidWithValidServiceCollectionForDefaultRegistration()
33+
{
34+
var testPlugin = new HttpTestPlugin();
35+
var serviceCollection = new ServiceCollection();
36+
37+
testPlugin.DefaultServiceRegistrationDelegate(serviceCollection);
38+
39+
var methodReturnType = testPlugin.DefaultServiceRegistrationDelegate.Method.ReturnType.Name;
40+
41+
Assert.True(methodReturnType == "Void");
42+
Assert.Contains(serviceCollection, s => s.ServiceType == typeof(JsonResultExecutor));
43+
}
44+
45+
[Fact]
46+
public void ShouldInvokeMethodOfTypeVoidWithValidServiceCollection()
47+
{
48+
var testPlugin = new HttpTestPlugin();
49+
var serviceCollection = new ServiceCollection();
50+
51+
testPlugin.ServiceRegistrationDelegate(serviceCollection);
52+
53+
var methodReturnType = testPlugin.ServiceRegistrationDelegate.Method.ReturnType.Name;
54+
55+
Assert.True(methodReturnType == "Void");
56+
Assert.Contains(serviceCollection, s => s.ServiceType == typeof(IOptions<>));
57+
58+
}
59+
}
60+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
namespace MyTested.AspNetCore.Mvc.Test.PluginsTests
2+
{
3+
using System;
4+
using Microsoft.AspNetCore.Mvc.Cors;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Plugins;
7+
using Xunit;
8+
9+
public class LiteTestPluginTest
10+
{
11+
[Fact]
12+
public void ShouldHavePriorityWithDefaultValue()
13+
{
14+
var testPlugin = new LiteTestPlugin();
15+
16+
Assert.IsAssignableFrom<IDefaultRegistrationPlugin>(testPlugin);
17+
Assert.NotNull(testPlugin);
18+
Assert.Equal(0, testPlugin.Priority);
19+
}
20+
21+
[Fact]
22+
public void ShouldThrowArgumentNullExceptionWithInvalidServiceCollection()
23+
{
24+
var testPlugin = new LiteTestPlugin();
25+
26+
Assert.Throws<ArgumentNullException>(() => testPlugin.DefaultServiceRegistrationDelegate(null));
27+
}
28+
29+
[Fact]
30+
public void ShouldInvokeMethodOfTypeVoidWithValidServiceCollection()
31+
{
32+
var testPlugin = new LiteTestPlugin();
33+
var serviceCollection = new ServiceCollection();
34+
35+
testPlugin.DefaultServiceRegistrationDelegate(serviceCollection);
36+
37+
var methodReturnType = testPlugin.DefaultServiceRegistrationDelegate.Method.ReturnType.Name;
38+
39+
Assert.True(methodReturnType == "Void");
40+
Assert.Contains(serviceCollection, s => s.ServiceType == typeof(CorsAuthorizationFilter));
41+
}
42+
}
43+
}

test/MyTested.AspNetCore.Mvc.ModelState.Test/BuildersTests/ActionsTests/ShouldHaveTests/ShouldHaveModelStateTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
namespace MyTested.AspNetCore.Mvc.Test.BuildersTests.ActionsTests.ShouldHaveTests
22
{
33
using Exceptions;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using Plugins;
46
using Setups;
57
using Setups.Controllers;
68
using Setups.ViewComponents;

0 commit comments

Comments
 (0)