Skip to content

Commit 61fae43

Browse files
committed
Added ExcludeAttribute unit tests
1 parent a8da307 commit 61fae43

File tree

4 files changed

+134
-4
lines changed

4 files changed

+134
-4
lines changed

src/Tests/AutoTest.ArgumentNullException.Tests/AutoTest.ArgumentNullException.Tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
<Compile Include="SpecimenProviderShould.cs" />
9797
<Compile Include="TestNullArguments.cs" />
9898
<Compile Include="Filter\IsClassOrStructShould.cs" />
99+
<Compile Include="Xunit\ExcludeAttributeShould.cs" />
99100
<Compile Include="Xunit\ExcludeAllAttributeShould.cs" />
100101
<Compile Include="Xunit\IncludeAttributeShould.cs" />
101102
</ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
namespace AutoTest.ArgNullEx.Xunit
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Reflection;
7+
using AutoTest.ArgNullEx.Filter;
8+
using Moq;
9+
using global::Xunit;
10+
using global::Xunit.Extensions;
11+
12+
public class ExcludeAttributeShould
13+
{
14+
[Theory, AutoMock]
15+
public void BeACustomization(ExcludeAttribute sut)
16+
{
17+
// Assert
18+
Assert.IsAssignableFrom<IArgNullExCustomization>(sut);
19+
Assert.IsAssignableFrom<CustomizeAttribute>(sut);
20+
}
21+
22+
[Theory, AutoMock]
23+
public void ReturnSelfCustomization(ExcludeAttribute sut, MethodInfo method)
24+
{
25+
// Act
26+
IArgNullExCustomization customization = sut.GetCustomization(method);
27+
28+
// Assert
29+
Assert.Same(sut, customization);
30+
}
31+
32+
[Theory, AutoMock]
33+
public void ExcludeParameter(
34+
ExcludeAttribute sut,
35+
MethodInfo method,
36+
List<IFilter> filters,
37+
List<RegexRule> regexRules,
38+
Mock<IRegexFilter> regexFilterMock,
39+
Mock<IArgumentNullExceptionFixture> fixtureMock)
40+
{
41+
// Arrange
42+
regexFilterMock.SetupGet(r => r.Rules).Returns(regexRules);
43+
filters.Add(regexFilterMock.Object);
44+
fixtureMock.SetupGet(f => f.Filters).Returns(filters);
45+
List<RegexRule> existingRules = regexRules.ToList();
46+
47+
// Act
48+
IArgNullExCustomization customization = sut.GetCustomization(method);
49+
customization.Customize(fixtureMock.Object);
50+
51+
// Assert
52+
Assert.Equal(existingRules.Count + 1, regexRules.Count);
53+
Assert.False(existingRules.Except(regexRules).Any());
54+
}
55+
56+
[Theory, AutoMock]
57+
public void ExcludeMethod(
58+
ExcludeAttribute sut,
59+
MethodInfo method,
60+
List<IFilter> filters,
61+
List<RegexRule> regexRules,
62+
Mock<IRegexFilter> regexFilterMock,
63+
Mock<IArgumentNullExceptionFixture> fixtureMock)
64+
{
65+
// Arrange
66+
regexFilterMock.SetupGet(r => r.Rules).Returns(regexRules);
67+
filters.Add(regexFilterMock.Object);
68+
fixtureMock.SetupGet(f => f.Filters).Returns(filters);
69+
List<RegexRule> existingRules = regexRules.ToList();
70+
71+
// Act
72+
sut.Parameter = null;
73+
IArgNullExCustomization customization = sut.GetCustomization(method);
74+
customization.Customize(fixtureMock.Object);
75+
76+
// Assert
77+
Assert.Equal(existingRules.Count + 1, regexRules.Count);
78+
Assert.False(existingRules.Except(regexRules).Any());
79+
}
80+
81+
[Theory, AutoMock]
82+
public void ExcludeType(
83+
ExcludeAttribute sut,
84+
MethodInfo method,
85+
List<IFilter> filters,
86+
List<RegexRule> regexRules,
87+
Mock<IRegexFilter> regexFilterMock,
88+
Mock<IArgumentNullExceptionFixture> fixtureMock)
89+
{
90+
// Arrange
91+
regexFilterMock.SetupGet(r => r.Rules).Returns(regexRules);
92+
filters.Add(regexFilterMock.Object);
93+
fixtureMock.SetupGet(f => f.Filters).Returns(filters);
94+
List<RegexRule> existingRules = regexRules.ToList();
95+
96+
// Act
97+
sut.Parameter = null;
98+
sut.Method = null;
99+
IArgNullExCustomization customization = sut.GetCustomization(method);
100+
customization.Customize(fixtureMock.Object);
101+
102+
// Assert
103+
Assert.Equal(existingRules.Count + 1, regexRules.Count);
104+
Assert.False(existingRules.Except(regexRules).Any());
105+
}
106+
107+
[Theory, AutoMock]
108+
public void ThrowsIfNothingSpecified(
109+
ExcludeAttribute sut,
110+
MethodInfo method,
111+
List<IFilter> filters,
112+
List<RegexRule> regexRules,
113+
Mock<IRegexFilter> regexFilterMock,
114+
Mock<IArgumentNullExceptionFixture> fixtureMock)
115+
{
116+
// Arrange
117+
regexFilterMock.SetupGet(r => r.Rules).Returns(regexRules);
118+
filters.Add(regexFilterMock.Object);
119+
fixtureMock.SetupGet(f => f.Filters).Returns(filters);
120+
121+
// Act
122+
sut.Parameter = null;
123+
sut.Method = null;
124+
sut.Type = null;
125+
IArgNullExCustomization customization = sut.GetCustomization(method);
126+
Assert.Throws<InvalidOperationException>(() => customization.Customize(fixtureMock.Object));
127+
}
128+
}
129+
}

src/Tests/AutoTest.ArgumentNullException.Tests/Xunit/IncludeAttributeShould.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void ReturnSelfCustomization(IncludeAttribute sut, MethodInfo method)
3030
}
3131

3232
[Theory, AutoMock]
33-
public void ExcludeAllTypesAndIndludeParameter(
33+
public void ExcludeAllTypesAndIncludeParameter(
3434
IncludeAttribute sut,
3535
MethodInfo method,
3636
List<IFilter> filters,
@@ -55,7 +55,7 @@ public void ExcludeAllTypesAndIndludeParameter(
5555
}
5656

5757
[Theory, AutoMock]
58-
public void ExcludeAllTypesAndIndludeMethod(
58+
public void ExcludeAllTypesAndIncludeMethod(
5959
IncludeAttribute sut,
6060
MethodInfo method,
6161
List<IFilter> filters,
@@ -81,7 +81,7 @@ public void ExcludeAllTypesAndIndludeMethod(
8181
}
8282

8383
[Theory, AutoMock]
84-
public void ExcludeAllTypesAndIndludeType(
84+
public void ExcludeAllTypesAndIncludeType(
8585
IncludeAttribute sut,
8686
MethodInfo method,
8787
List<IFilter> filters,

src/Tests/ExecuteCodeCoverage.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
::"-filter:+[AutoTest.ArgumentNullException]* +[AutoTest.ArgumentNullException.Xunit]* +[AutoTest.ExampleLibrary]* -[AutoTest.ArgumentNullException.Xunit]System.Threading.Tasks.* -[AutoTest.ArgumentNullException]*ReflectionDiscoverableCollection*"
66
::"-output:C:\git\AutoTest.ArgumentNullException\src\Tests\CoverageResults.xml"
77

8-
"%~dp0..\packages\OpenCover.4.5.1604\OpenCover.Console.exe" -register:user "-target:C:\git\AutoTest.ArgumentNullException\src\packages\xunit.runners.1.9.1\tools\xunit.console.clr4.exe" "-targetargs:C:\git\AutoTest.ArgumentNullException\src\Tests\Tests.xunit" "-filter:+[AutoTest.ArgumentNullException]* +[AutoTest.ArgumentNullException.Xunit]* +[AutoTest.ExampleLibrary]* -[AutoTest.ArgumentNullException.Xunit]System.Threading.Tasks.* -[AutoTest.ArgumentNullException]*ReflectionDiscoverableCollection*" "-output:C:\git\AutoTest.ArgumentNullException\src\Tests\CoverageResults.xml"
8+
"%~dp0..\packages\OpenCover.4.5.1604\OpenCover.Console.exe" -register:user "-target:C:\git\AutoTest.ArgumentNullException\src\packages\xunit.runners.1.9.1\tools\xunit.console.clr4.exe" "-targetargs:C:\git\AutoTest.ArgumentNullException\src\Tests\Tests.xunit" "-filter:+[AutoTest.ArgumentNullException]* +[AutoTest.ArgumentNullException.Xunit]* -[AutoTest.ArgumentNullException.Xunit]System.Threading.Tasks.* -[AutoTest.ArgumentNullException]*ReflectionDiscoverableCollection*" "-output:C:\git\AutoTest.ArgumentNullException\src\Tests\CoverageResults.xml"
99

1010
::"%~dp0..\packages\ReportGenerator.1.8.1.0\ReportGenerator.exe"
1111
::"C:\git\AutoTest.ArgumentNullException\src\Tests\CoverageResults.xml"

0 commit comments

Comments
 (0)