Skip to content

Commit 5d0b2bd

Browse files
committed
Added unit tests for ViewComponents in plugins (#66)
1 parent 7643730 commit 5d0b2bd

File tree

87 files changed

+20802
-296
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+20802
-296
lines changed

MyTested.AspNetCore.Mvc.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MyTested.AspNetCore.Mvc.Vie
118118
EndProject
119119
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MyTested.AspNetCore.Mvc.ViewComponents.Test", "test\MyTested.AspNetCore.Mvc.ViewComponents.Test\MyTested.AspNetCore.Mvc.ViewComponents.Test.xproj", "{16FC9EF0-F27E-4814-9FAC-C2054314CE9E}"
120120
EndProject
121+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MyTested.AspNetCore.Mvc.ModelState", "src\MyTested.AspNetCore.Mvc.ModelState\MyTested.AspNetCore.Mvc.ModelState.xproj", "{13A781F9-8766-4016-B72E-FA7E61DCF85F}"
122+
EndProject
123+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MyTested.AspNetCore.Mvc.ModelState.Test", "test\MyTested.AspNetCore.Mvc.ModelState.Test\MyTested.AspNetCore.Mvc.ModelState.Test.xproj", "{85915D02-3635-4BF3-9795-9FAD378AFE94}"
124+
EndProject
121125
Global
122126
GlobalSection(SolutionConfigurationPlatforms) = preSolution
123127
Debug|Any CPU = Debug|Any CPU
@@ -324,6 +328,14 @@ Global
324328
{16FC9EF0-F27E-4814-9FAC-C2054314CE9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
325329
{16FC9EF0-F27E-4814-9FAC-C2054314CE9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
326330
{16FC9EF0-F27E-4814-9FAC-C2054314CE9E}.Release|Any CPU.Build.0 = Release|Any CPU
331+
{13A781F9-8766-4016-B72E-FA7E61DCF85F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
332+
{13A781F9-8766-4016-B72E-FA7E61DCF85F}.Debug|Any CPU.Build.0 = Debug|Any CPU
333+
{13A781F9-8766-4016-B72E-FA7E61DCF85F}.Release|Any CPU.ActiveCfg = Release|Any CPU
334+
{13A781F9-8766-4016-B72E-FA7E61DCF85F}.Release|Any CPU.Build.0 = Release|Any CPU
335+
{85915D02-3635-4BF3-9795-9FAD378AFE94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
336+
{85915D02-3635-4BF3-9795-9FAD378AFE94}.Debug|Any CPU.Build.0 = Debug|Any CPU
337+
{85915D02-3635-4BF3-9795-9FAD378AFE94}.Release|Any CPU.ActiveCfg = Release|Any CPU
338+
{85915D02-3635-4BF3-9795-9FAD378AFE94}.Release|Any CPU.Build.0 = Release|Any CPU
327339
EndGlobalSection
328340
GlobalSection(SolutionProperties) = preSolution
329341
HideSolutionNode = FALSE
@@ -381,5 +393,7 @@ Global
381393
{F298003E-AB7F-4C30-98B6-F5C9838152C6} = {D140FA14-A6C2-4279-8A41-35BC55279DA8}
382394
{40CF14D6-7937-4143-9A02-A6E638F36C82} = {09353A03-2B0C-496B-8EB1-2CB6A22D758B}
383395
{16FC9EF0-F27E-4814-9FAC-C2054314CE9E} = {D140FA14-A6C2-4279-8A41-35BC55279DA8}
396+
{13A781F9-8766-4016-B72E-FA7E61DCF85F} = {09353A03-2B0C-496B-8EB1-2CB6A22D758B}
397+
{85915D02-3635-4BF3-9795-9FAD378AFE94} = {D140FA14-A6C2-4279-8A41-35BC55279DA8}
384398
EndGlobalSection
385399
EndGlobal

samples/MusicStore/MusicStore.Test/project.lock.json

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4424,7 +4424,8 @@
44244424
"framework": ".NETStandard,Version=v1.6",
44254425
"dependencies": {
44264426
"Microsoft.AspNetCore.Mvc.DataAnnotations": "1.0.0",
4427-
"MyTested.AspNetCore.Mvc.Core": "1.0.0"
4427+
"MyTested.AspNetCore.Mvc.Core": "1.0.0",
4428+
"MyTested.AspNetCore.Mvc.ModelState": "1.0.0"
44284429
},
44294430
"compile": {
44304431
"netstandard1.6/MyTested.AspNetCore.Mvc.DataAnnotations.dll": {}
@@ -4488,6 +4489,20 @@
44884489
"netstandard1.4/MyTested.AspNetCore.Mvc.Licensing.dll": {}
44894490
}
44904491
},
4492+
"MyTested.AspNetCore.Mvc.ModelState/1.0.0-preview-final": {
4493+
"type": "project",
4494+
"framework": ".NETStandard,Version=v1.6",
4495+
"dependencies": {
4496+
"Microsoft.AspNetCore.Mvc.DataAnnotations": "1.0.0",
4497+
"MyTested.AspNetCore.Mvc.Abstractions": "1.0.0"
4498+
},
4499+
"compile": {
4500+
"netstandard1.6/MyTested.AspNetCore.Mvc.ModelState.dll": {}
4501+
},
4502+
"runtime": {
4503+
"netstandard1.6/MyTested.AspNetCore.Mvc.ModelState.dll": {}
4504+
}
4505+
},
44914506
"MyTested.AspNetCore.Mvc.Options/1.0.0-preview-final": {
44924507
"type": "project",
44934508
"framework": ".NETStandard,Version=v1.6",
@@ -6914,7 +6929,8 @@
69146929
"framework": ".NETFramework,Version=v4.5.1",
69156930
"dependencies": {
69166931
"Microsoft.AspNetCore.Mvc.DataAnnotations": "1.0.0",
6917-
"MyTested.AspNetCore.Mvc.Core": "1.0.0"
6932+
"MyTested.AspNetCore.Mvc.Core": "1.0.0",
6933+
"MyTested.AspNetCore.Mvc.ModelState": "1.0.0"
69186934
},
69196935
"compile": {
69206936
"net451/MyTested.AspNetCore.Mvc.DataAnnotations.dll": {}
@@ -6974,6 +6990,20 @@
69746990
"net451/MyTested.AspNetCore.Mvc.Licensing.dll": {}
69756991
}
69766992
},
6993+
"MyTested.AspNetCore.Mvc.ModelState/1.0.0-preview-final": {
6994+
"type": "project",
6995+
"framework": ".NETFramework,Version=v4.5.1",
6996+
"dependencies": {
6997+
"Microsoft.AspNetCore.Mvc.DataAnnotations": "1.0.0",
6998+
"MyTested.AspNetCore.Mvc.Abstractions": "1.0.0"
6999+
},
7000+
"compile": {
7001+
"net451/MyTested.AspNetCore.Mvc.ModelState.dll": {}
7002+
},
7003+
"runtime": {
7004+
"net451/MyTested.AspNetCore.Mvc.ModelState.dll": {}
7005+
}
7006+
},
69777007
"MyTested.AspNetCore.Mvc.Options/1.0.0-preview-final": {
69787008
"type": "project",
69797009
"framework": ".NETFramework,Version=v4.5.1",
@@ -13774,6 +13804,11 @@
1377413804
"path": "../../../src/MyTested.AspNetCore.Mvc.Licensing/project.json",
1377513805
"msbuildProject": "../../../src/MyTested.AspNetCore.Mvc.Licensing/MyTested.AspNetCore.Mvc.Licensing.xproj"
1377613806
},
13807+
"MyTested.AspNetCore.Mvc.ModelState/1.0.0-preview-final": {
13808+
"type": "project",
13809+
"path": "../../../src/MyTested.AspNetCore.Mvc.ModelState/project.json",
13810+
"msbuildProject": "../../../src/MyTested.AspNetCore.Mvc.ModelState/MyTested.AspNetCore.Mvc.ModelState.xproj"
13811+
},
1377713812
"MyTested.AspNetCore.Mvc.Options/1.0.0-preview-final": {
1377813813
"type": "project",
1377913814
"path": "../../../src/MyTested.AspNetCore.Mvc.Options/project.json",

src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Base/BaseTestBuilderWithComponent.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,5 @@ public IAndTestBuilder ShouldPassForThe<TComponent>(Func<TComponent, bool> predi
6969

7070
return new AndTestBuilder(this.TestContext);
7171
}
72-
73-
protected IAndTestBuilder NewAndTestBuilder() => new AndTestBuilder(this.TestContext);
7472
}
7573
}

src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Data/BaseDataProviderTestBuilder.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,8 @@ protected void ValidateContainingEntries(IDictionary<string, object> entries)
154154
protected void ThrowNewDataProviderAssertionException(string propertyName, string expectedValue, string actualValue)
155155
{
156156
throw new DataProviderAssertionException(string.Format(
157-
"When calling {0} action in {1} expected {2} {3}, but {4}.",
158-
this.TestContext.MethodName,
159-
this.TestContext.Component.GetName(),
157+
"{0} {1} {2}, but {3}.",
158+
this.TestContext.ExceptionMessagePrefix,
160159
propertyName,
161160
expectedValue,
162161
actualValue));

src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Data/DataProviderEntryTestBuilder.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Internal.TestContexts;
88
using Utilities;
99
using Utilities.Validators;
10-
using Utilities.Extensions;
1110
using Exceptions;
1211

1312
/// <summary>
@@ -98,9 +97,8 @@ internal ICollection<Action<object>> GetDataProviderEntryValidations()
9897
internal void ThrowNewDataProviderAssertionException(string expectedValue, string actualValue)
9998
{
10099
throw new DataProviderAssertionException(string.Format(
101-
"When calling {0} action in {1} expected {2} {3}, but {4}.",
102-
this.TestContext.MethodName,
103-
this.TestContext.Component.GetName(),
100+
"{0} {1} {2}, but {3}.",
101+
this.TestContext.ExceptionMessagePrefix,
104102
this.dataProviderName,
105103
expectedValue,
106104
actualValue));

src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Models/ModelErrorTestBuilder{TModel}.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public void ThrowNewModelErrorAssertionException(string messageFormat, string er
3838
{
3939
throw new ModelErrorAssertionException(string.Format(
4040
messageFormat,
41-
this.TestContext.MethodName,
42-
this.TestContext.Component.GetName(),
41+
this.TestContext.ExceptionMessagePrefix,
4342
errorKey));
4443
}
4544
}

src/MyTested.AspNetCore.Mvc.Abstractions/Internal/TestContexts/InvocationTestContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
public class InvocationTestContext<TResult>
1111
{
1212
/// <summary>
13-
/// Initializes a new instance of the <see cref="InvocationTestContext{TActionResult}"/> class.
13+
/// Initializes a new instance of the <see cref="InvocationTestContext{TResult}"/> class.
1414
/// </summary>
1515
/// <param name="methodName">Name of the method.</param>
1616
/// <param name="methodCall"><see cref="LambdaExpression"/> representing the method call.</param>

src/MyTested.AspNetCore.Mvc.Abstractions/Utilities/Validators/DataProviderValidator.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace MyTested.AspNetCore.Mvc.Utilities.Validators
22
{
33
using Exceptions;
4-
using Extensions;
54
using Internal.TestContexts;
65

76
public static class DataProviderValidator
@@ -35,9 +34,8 @@ public static void ThrowNewDataProviderAssertionException(
3534
string actualValue)
3635
{
3736
throw new DataProviderAssertionException(string.Format(
38-
"When calling {0} action in {1} expected to have {2}{3}, but {4}.",
39-
testContext.MethodName,
40-
testContext.Component.GetName(),
37+
"{0} to have {1}{2}, but {3}.",
38+
testContext.ExceptionMessagePrefix,
4139
name,
4240
expectedValue,
4341
actualValue));

src/MyTested.AspNetCore.Mvc.Caching/Builders/Data/MemoryCacheEntryTestBuilder.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,8 @@ internal ICollection<Action<ICacheEntry, ICacheEntry>> GetMemoryCacheEntryMockVa
162162
internal void ThrowNewDataProviderAssertionException(string expectedValue, string actualValue)
163163
{
164164
throw new DataProviderAssertionException(string.Format(
165-
"When calling {0} action in {1} expected memory cache {2}, but {3}.",
166-
this.TestContext.MethodName,
167-
this.TestContext.Component.GetName(),
165+
"{0} memory cache {1}, but {2}.",
166+
this.TestContext.ExceptionMessagePrefix,
168167
expectedValue,
169168
actualValue));
170169
}

src/MyTested.AspNetCore.Mvc.Caching/Builders/Data/MemoryCacheTestBuilder.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,8 @@ private object GetValue(object key)
216216
private void ThrowNewDataProviderAssertionException(string propertyName, string expectedValue, string actualValue)
217217
{
218218
throw new DataProviderAssertionException(string.Format(
219-
"When calling {0} action in {1} expected {2} {3}, but {4}.",
220-
this.TestContext.MethodName,
221-
this.TestContext.Component.GetName(),
219+
"{0} {1} {2}, but {3}.",
220+
this.TestContext.ExceptionMessagePrefix,
222221
propertyName,
223222
expectedValue,
224223
actualValue));

0 commit comments

Comments
 (0)