Skip to content

Commit 7e6755b

Browse files
committed
Added tests for OfType methods in FileTestBuilderTests (#148)
1 parent 50ce7d6 commit 7e6755b

File tree

1 file changed

+49
-3
lines changed
  • test/MyTested.AspNetCore.Mvc.DataAnnotations.Test/BuildersTests/ActionResultsTests/FileTests

1 file changed

+49
-3
lines changed

test/MyTested.AspNetCore.Mvc.DataAnnotations.Test/BuildersTests/ActionResultsTests/FileTests/FileTestBuilderTests.cs

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void WithFileProviderShouldThrowExceptionWithInvalidFileProvider()
5454
}
5555

5656
[Fact]
57-
public void WithFileProviderOfTypeShouldNotThrowExceptionWithValidFileProvider()
57+
public void WithFileProviderOfTypeShouldNotThrowExceptionWithValidFileProviderForGeneric()
5858
{
5959
MyController<MvcController>
6060
.Instance()
@@ -66,7 +66,19 @@ public void WithFileProviderOfTypeShouldNotThrowExceptionWithValidFileProvider()
6666
}
6767

6868
[Fact]
69-
public void WithFileProviderOfTypeShouldThrowExceptionWithInvalidFileProvider()
69+
public void WithFileProviderOfTypeShouldNotThrowExceptionWithValidFileProvider()
70+
{
71+
MyController<MvcController>
72+
.Instance()
73+
.WithoutValidation()
74+
.Calling(c => c.FileWithFileProvider(null))
75+
.ShouldReturn()
76+
.File(file => file
77+
.WithFileProviderOfType(typeof(CustomFileProvider)));
78+
}
79+
80+
[Fact]
81+
public void WithFileProviderOfTypeShouldThrowExceptionWithInvalidFileProviderForGeneric()
7082
{
7183
Test.AssertException<FileResultAssertionException>(
7284
() =>
@@ -83,7 +95,24 @@ public void WithFileProviderOfTypeShouldThrowExceptionWithInvalidFileProvider()
8395
}
8496

8597
[Fact]
86-
public void WithFileProviderOfTypeShouldNotThrowExceptionWithNullFileProvider()
98+
public void WithFileProviderOfTypeShouldThrowExceptionWithInvalidFileProvider()
99+
{
100+
Test.AssertException<FileResultAssertionException>(
101+
() =>
102+
{
103+
MyController<MvcController>
104+
.Instance()
105+
.WithoutValidation()
106+
.Calling(c => c.FileWithFileProvider(null))
107+
.ShouldReturn()
108+
.File(file => file
109+
.WithFileProviderOfType(typeof(IFileProvider)));
110+
},
111+
"When calling FileWithFileProvider action in MvcController expected file result provider to be of IFileProvider type, but instead received CustomFileProvider.");
112+
}
113+
114+
[Fact]
115+
public void WithFileProviderOfTypeShouldNotThrowExceptionWithNullFileProviderForGeneric()
87116
{
88117
Test.AssertException<FileResultAssertionException>(
89118
() =>
@@ -98,5 +127,22 @@ public void WithFileProviderOfTypeShouldNotThrowExceptionWithNullFileProvider()
98127
},
99128
"When calling FileWithNullProvider action in MvcController expected file result provider to be of CustomFileProvider type, but instead received null.");
100129
}
130+
131+
[Fact]
132+
public void WithFileProviderOfTypeShouldNotThrowExceptionWithNullFileProvider()
133+
{
134+
Test.AssertException<FileResultAssertionException>(
135+
() =>
136+
{
137+
MyController<MvcController>
138+
.Instance()
139+
.WithoutValidation()
140+
.Calling(c => c.FileWithNullProvider())
141+
.ShouldReturn()
142+
.File(file => file
143+
.WithFileProviderOfType(typeof(CustomFileProvider)));
144+
},
145+
"When calling FileWithNullProvider action in MvcController expected file result provider to be of CustomFileProvider type, but instead received null.");
146+
}
101147
}
102148
}

0 commit comments

Comments
 (0)