Skip to content

Commit 468442e

Browse files
authored
Merge pull request #323 - #289 make controller ShouldHave more accessible
#289 make controller ShouldHave more accessible
2 parents e01eca3 + 0121d11 commit 468442e

File tree

13 files changed

+16
-151
lines changed

13 files changed

+16
-151
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ An attribute declaration test validates controller and action attribute declarat
400400
```c#
401401
// Tests for specific controller attributes - Area and Authorize.
402402
MyController<MyMvcController>
403-
.Instance()
404403
.ShouldHave()
405404
.Attributes(attributes => attributes
406405
.SpecifyingArea(ControllerConstants.AdministratorArea)

samples/Blog/Blog.Test/Controllers/Admin/ArticlesControllerTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public class ArticlesControllerTest
1818
[Fact]
1919
public void ControllerShouldBeInAdminArea()
2020
=> MyController<ArticlesController>
21-
.Instance()
2221
.ShouldHave()
2322
.Attributes(attrs => attrs
2423
.SpecifyingArea(ControllerConstants.AdministratorArea)

src/MyTested.AspNetCore.Mvc.Controllers/MyController.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,13 @@ public static IControllerBuilder<TController> Instance(Func<TController> constru
104104
public new static IVoidActionResultTestBuilder Calling(Expression<Func<TController, Task>> actionCall)
105105
=> Instance()
106106
.Calling(actionCall);
107+
108+
/// <summary>
109+
/// Used for testing controller additional details.
110+
/// </summary>
111+
/// <returns>Test builder of <see cref="IControllerTestBuilder"/> type.</returns>
112+
public new static IControllerTestBuilder ShouldHave()
113+
=> Instance()
114+
.ShouldHave();
107115
}
108116
}

src/MyTested.AspNetCore.Mvc.ViewComponents/MyViewComponent.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,13 @@ public static IViewComponentBuilder<TViewComponent> Instance(TViewComponent view
6363
/// <returns>Test builder of <see cref="IViewComponentBuilder{TViewComponent}"/> type.</returns>
6464
public static IViewComponentBuilder<TViewComponent> Instance(Func<TViewComponent> construction)
6565
=> new MyViewComponent<TViewComponent>(construction);
66+
67+
/// <summary>
68+
/// Used for testing view component additional details.
69+
/// </summary>
70+
/// <returns>Test builder of <see cref="IViewComponentTestBuilder"/> type.</returns>
71+
public new static IViewComponentTestBuilder ShouldHave()
72+
=> Instance()
73+
.ShouldHave();
6674
}
6775
}

test/MyTested.AspNetCore.Mvc.Controllers.Attributes.Test/BuildersTests/AttributesTests/ControllerAttributesTestBuilderTests.cs

Lines changed: 0 additions & 111 deletions
Large diffs are not rendered by default.

test/MyTested.AspNetCore.Mvc.Controllers.Test/BuildersTests/AndTests/AndProvideTestBuilderTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public void AndProvideShouldReturnProperController()
2828
public void AndProvideTheControllerAttributesShouldReturnProperAttributes()
2929
{
3030
MyController<MvcController>
31-
.Instance()
3231
.ShouldHave()
3332
.Attributes()
3433
.ShouldPassForThe<ControllerAttributes>(attributes =>

test/MyTested.AspNetCore.Mvc.Controllers.Test/BuildersTests/AttributesTests/ControllerAttributesTestBuilderTests.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class ControllerAttributesTestBuilderTests
1414
public void ContainingAttributeOfTypeShouldNotThrowExceptionWithControllerWithTheAttribute()
1515
{
1616
MyController<MvcController>
17-
.Instance()
1817
.ShouldHave()
1918
.Attributes(attributes => attributes.ContainingAttributeOfType<AuthorizeAttribute>());
2019
}
@@ -26,7 +25,6 @@ public void ContainingAttributeOfTypeShouldThrowExceptionWithControllerWithoutTh
2625
() =>
2726
{
2827
MyController<MvcController>
29-
.Instance()
3028
.ShouldHave()
3129
.Attributes(attributes => attributes.ContainingAttributeOfType<AllowAnonymousAttribute>());
3230
},
@@ -37,7 +35,6 @@ public void ContainingAttributeOfTypeShouldThrowExceptionWithControllerWithoutTh
3735
public void PassingForShouldNotThrowExceptionWithCorrectAssertions()
3836
{
3937
MyController<MvcController>
40-
.Instance()
4138
.ShouldHave()
4239
.Attributes(attributes => attributes
4340
.PassingFor<AuthorizeAttribute>(authorize => Assert.Equal("Admin,Moderator", authorize.Roles)));
@@ -50,7 +47,6 @@ public void PassingForShouldThrowExceptionWithIncorrectAssertions()
5047
() =>
5148
{
5249
MyController<MvcController>
53-
.Instance()
5450
.ShouldHave()
5551
.Attributes(attributes => attributes
5652
.PassingFor<AuthorizeAttribute>(authorize => Assert.Equal("Admin", authorize.Roles)));
@@ -64,7 +60,6 @@ public void PassingForShouldThrowExceptionWithIncorrectAttribute()
6460
() =>
6561
{
6662
MyController<MvcController>
67-
.Instance()
6863
.ShouldHave()
6964
.Attributes(attributes => attributes
7065
.PassingFor<ActionNameAttribute>(authorize => Assert.Equal("Admin", authorize.Name)));
@@ -76,7 +71,6 @@ public void PassingForShouldThrowExceptionWithIncorrectAttribute()
7671
public void PassingForShouldNotThrowExceptionWithCorrectPredicate()
7772
{
7873
MyController<MvcController>
79-
.Instance()
8074
.ShouldHave()
8175
.Attributes(attributes => attributes
8276
.PassingFor<AuthorizeAttribute>(authorize => authorize.Roles == "Admin,Moderator"));
@@ -89,7 +83,6 @@ public void PassingForShouldThrowExceptionWithIncorrectPredicate()
8983
() =>
9084
{
9185
MyController<MvcController>
92-
.Instance()
9386
.ShouldHave()
9487
.Attributes(attributes => attributes
9588
.PassingFor<AuthorizeAttribute>(authorize => authorize.Roles == "Admin"));
@@ -104,7 +97,6 @@ public void PassingForShouldThrowExceptionWithIncorrectAttributeWithPredicate()
10497
() =>
10598
{
10699
MyController<MvcController>
107-
.Instance()
108100
.ShouldHave()
109101
.Attributes(attributes => attributes
110102
.PassingFor<AuthorizeAttribute>(authorize => authorize.Roles == "Admin,Moderator")

test/MyTested.AspNetCore.Mvc.Controllers.Test/BuildersTests/ControllersTests/ControllerTestBuilderTests.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public class ControllerTestBuilderTests
1111
public void NoAttributesShouldNotThrowExceptionWithControllerContainingNoAttributes()
1212
{
1313
MyController<NoAttributesController>
14-
.Instance()
1514
.ShouldHave()
1615
.NoAttributes();
1716
}
@@ -23,7 +22,6 @@ public void NoAttributesShouldThrowExceptionWithControllerContainingAttributes()
2322
() =>
2423
{
2524
MyController<MvcController>
26-
.Instance()
2725
.ShouldHave()
2826
.NoAttributes();
2927
},
@@ -34,7 +32,6 @@ public void NoAttributesShouldThrowExceptionWithControllerContainingAttributes()
3432
public void AttributesShouldNotThrowExceptionWithControllerContainingAttributes()
3533
{
3634
MyController<MvcController>
37-
.Instance()
3835
.ShouldHave()
3936
.Attributes();
4037
}
@@ -46,7 +43,6 @@ public void AttributesShouldThrowExceptionWithControllerContainingNoAttributes()
4643
() =>
4744
{
4845
MyController<NoAttributesController>
49-
.Instance()
5046
.ShouldHave()
5147
.Attributes();
5248
},
@@ -57,7 +53,6 @@ public void AttributesShouldThrowExceptionWithControllerContainingNoAttributes()
5753
public void AttributesShouldNotThrowExceptionWithControllerContainingNumberOfAttributes()
5854
{
5955
MyController<MvcController>
60-
.Instance()
6156
.ShouldHave()
6257
.Attributes(withTotalNumberOf: 4);
6358
}
@@ -69,7 +64,6 @@ public void AttributesShouldThrowExceptionWithControllerContainingNumberOfAttrib
6964
() =>
7065
{
7166
MyController<MvcController>
72-
.Instance()
7367
.ShouldHave()
7468
.Attributes(withTotalNumberOf: 10);
7569
},
@@ -83,7 +77,6 @@ public void AttributesShouldThrowExceptionWithControllerContainingNumberOfAttrib
8377
() =>
8478
{
8579
MyController<MvcController>
86-
.Instance()
8780
.ShouldHave()
8881
.Attributes(withTotalNumberOf: 1);
8982
},

test/MyTested.AspNetCore.Mvc.ViewComponents.Attributes.Test/BuildersTests/AttributesTests/ViewComponentAttributesTestBuilderTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public void ChangingViewComponentNameToShouldThrowExceptionWithViewComponentWith
5151
public void IndicatingControllerShouldNotThrowExceptionWithTheAttribute()
5252
{
5353
MyViewComponent<AttributesComponent>
54-
.Instance()
5554
.ShouldHave()
5655
.Attributes(attributes => attributes
5756
.IndicatingViewComponentExplicitly());
@@ -64,7 +63,6 @@ public void DisablingActionCallShouldThrowExceptionWithActionWithoutTheAttribute
6463
() =>
6564
{
6665
MyViewComponent<ComponentWithCustomAttribute>
67-
.Instance()
6866
.ShouldHave()
6967
.Attributes(attributes => attributes
7068
.IndicatingViewComponentExplicitly());

test/MyTested.AspNetCore.Mvc.ViewComponents.Test/BuildersTests/AttributesTests/ViewComponentAttributesTestBuilderTests.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public void ContainingAttributeOfTypeShouldThrowExceptionWithViewComponentWithou
3939
public void PassingForShouldNotThrowExceptionWithCorrectAssertions()
4040
{
4141
MyViewComponent<AttributesComponent>
42-
.Instance()
4342
.ShouldHave()
4443
.Attributes(attributes => attributes
4544
.PassingFor<ViewComponentAttribute>(vc => Assert.Equal("Test", vc.Name)));
@@ -52,7 +51,6 @@ public void PassingForShouldThrowExceptionWithIncorrectAssertions()
5251
() =>
5352
{
5453
MyViewComponent<AttributesComponent>
55-
.Instance()
5654
.ShouldHave()
5755
.Attributes(attributes => attributes
5856
.PassingFor<ViewComponentAttribute>(route => Assert.Equal("Invalid", route.Name)));
@@ -66,7 +64,6 @@ public void PassingForShouldThrowExceptionWithIncorrectAttribute()
6664
() =>
6765
{
6866
MyViewComponent<AttributesComponent>
69-
.Instance()
7067
.ShouldHave()
7168
.Attributes(attributes => attributes
7269
.PassingFor<ActionNameAttribute>(authorize => Assert.Equal("Admin", authorize.Name)));
@@ -78,7 +75,6 @@ public void PassingForShouldThrowExceptionWithIncorrectAttribute()
7875
public void PassingForShouldNotThrowExceptionWithCorrectPredicate()
7976
{
8077
MyViewComponent<AttributesComponent>
81-
.Instance()
8278
.ShouldHave()
8379
.Attributes(attributes => attributes
8480
.PassingFor<ViewComponentAttribute>(route => route.Name == "Test"));
@@ -91,7 +87,6 @@ public void PassingForShouldThrowExceptionWithIncorrectPredicate()
9187
() =>
9288
{
9389
MyViewComponent<AttributesComponent>
94-
.Instance()
9590
.ShouldHave()
9691
.Attributes(attributes => attributes
9792
.PassingFor<ViewComponentAttribute>(vc => vc.Name == "Invalid"));
@@ -106,7 +101,6 @@ public void PassingForShouldThrowExceptionWithIncorrectAttributeWithPredicate()
106101
() =>
107102
{
108103
MyViewComponent<AttributesComponent>
109-
.Instance()
110104
.ShouldHave()
111105
.Attributes(attributes => attributes
112106
.PassingFor<ActionNameAttribute>(vc => vc.Name == "Admin"));

0 commit comments

Comments
 (0)