Skip to content

Commit 59dbd43

Browse files
authored
Merge pull request #338 - Changed attribute method names
Changed attribute method names
2 parents 24ac2ff + 52323fd commit 59dbd43

File tree

4 files changed

+74
-25
lines changed

4 files changed

+74
-25
lines changed

src/MyTested.AspNetCore.Mvc.Controllers.Attributes/ActionAttributesTestBuilderExtensions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,23 @@ public static class ActionAttributesTestBuilderExtensions
2424
/// </param>
2525
/// <param name="actionName">Expected overridden name of the action.</param>
2626
/// <returns>The same <see cref="IAndActionAttributesTestBuilder"/>.</returns>
27+
[Obsolete("This method will be removed in the next major version, please use SpecifyingActionName")]
2728
public static IAndActionAttributesTestBuilder ChangingActionNameTo(
2829
this IActionAttributesTestBuilder actionAttributesTestBuilder,
2930
string actionName)
31+
=> SpecifyingActionName(actionAttributesTestBuilder, actionName);
32+
33+
/// <summary>
34+
/// Tests whether the action attributes contain <see cref="ActionNameAttribute"/>.
35+
/// </summary>
36+
/// <param name="actionAttributesTestBuilder">
37+
/// Instance of <see cref="IActionAttributesTestBuilder"/> type.
38+
/// </param>
39+
/// <param name="actionName">Expected overridden name of the action.</param>
40+
/// <returns>The same <see cref="IAndActionAttributesTestBuilder"/>.</returns>
41+
public static IAndActionAttributesTestBuilder SpecifyingActionName(
42+
this IActionAttributesTestBuilder actionAttributesTestBuilder,
43+
string actionName)
3044
{
3145
var actualBuilder = (BaseAttributesTestBuilder<IAndActionAttributesTestBuilder>)actionAttributesTestBuilder;
3246

src/MyTested.AspNetCore.Mvc.Controllers.Attributes/ControllerActionAttributesTestBuilderExtensions.cs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,49 @@ public static class ControllerActionAttributesTestBuilderExtensions
2525
/// <param name="withName">Optional expected route name.</param>
2626
/// <param name="withOrder">Optional expected route order.</param>
2727
/// <returns>The same attributes test builder.</returns>
28+
[Obsolete("This method will be removed in the next major version, please use SpecifyingRoute")]
2829
public static TAttributesTestBuilder ChangingRouteTo<TAttributesTestBuilder>(
30+
this IControllerActionAttributesTestBuilder<TAttributesTestBuilder> controllerActionAttributesTestBuilder,
31+
string template,
32+
string withName = null,
33+
int? withOrder = null)
34+
where TAttributesTestBuilder : IControllerActionAttributesTestBuilder<TAttributesTestBuilder>
35+
=> SpecifyingRoute(controllerActionAttributesTestBuilder, template, withName, withOrder);
36+
37+
38+
/// <summary>
39+
/// Tests whether the collected attributes contain <see cref="RouteAttribute"/>.
40+
/// </summary>
41+
/// <param name="controllerActionAttributesTestBuilder">
42+
/// Instance of <see cref="IControllerActionAttributesTestBuilder{TAttributesTestBuilder}"/> type.
43+
/// </param>
44+
/// <param name="routeAttributeBuilder">Expected <see cref="RouteAttribute"/> builder.</param>
45+
/// <returns>The same attributes test builder.</returns>
46+
[Obsolete("This method will be removed in the next major version, please use SpecifyingRoute")]
47+
public static TAttributesTestBuilder ChangingRouteTo<TAttributesTestBuilder>(
48+
this IControllerActionAttributesTestBuilder<TAttributesTestBuilder> controllerActionAttributesTestBuilder,
49+
Action<IRouteAttributeTestBuilder> routeAttributeBuilder)
50+
where TAttributesTestBuilder : IControllerActionAttributesTestBuilder<TAttributesTestBuilder>
51+
=> SpecifyingRoute(controllerActionAttributesTestBuilder, routeAttributeBuilder);
52+
53+
/// <summary>
54+
/// Tests whether the collected attributes contain <see cref="RouteAttribute"/>.
55+
/// </summary>
56+
/// <param name="controllerActionAttributesTestBuilder">
57+
/// Instance of <see cref="IControllerActionAttributesTestBuilder{TAttributesTestBuilder}"/> type.
58+
/// </param>
59+
/// <param name="template">Expected overridden route template of the controller.</param>
60+
/// <param name="withName">Optional expected route name.</param>
61+
/// <param name="withOrder">Optional expected route order.</param>
62+
/// <returns>The same attributes test builder.</returns>
63+
public static TAttributesTestBuilder SpecifyingRoute<TAttributesTestBuilder>(
2964
this IControllerActionAttributesTestBuilder<TAttributesTestBuilder> controllerActionAttributesTestBuilder,
3065
string template,
3166
string withName = null,
3267
int? withOrder = null)
3368
where TAttributesTestBuilder : IControllerActionAttributesTestBuilder<TAttributesTestBuilder>
3469
=> controllerActionAttributesTestBuilder
35-
.ChangingRouteTo(route => route
70+
.SpecifyingRoute(route => route
3671
.WithTemplate(template)
3772
.WithName(withName)
3873
.WithOrder(withOrder ?? 0));
@@ -45,7 +80,7 @@ public static TAttributesTestBuilder ChangingRouteTo<TAttributesTestBuilder>(
4580
/// </param>
4681
/// <param name="routeAttributeBuilder">Expected <see cref="RouteAttribute"/> builder.</param>
4782
/// <returns>The same attributes test builder.</returns>
48-
public static TAttributesTestBuilder ChangingRouteTo<TAttributesTestBuilder>(
83+
public static TAttributesTestBuilder SpecifyingRoute<TAttributesTestBuilder>(
4984
this IControllerActionAttributesTestBuilder<TAttributesTestBuilder> controllerActionAttributesTestBuilder,
5085
Action<IRouteAttributeTestBuilder> routeAttributeBuilder)
5186
where TAttributesTestBuilder : IControllerActionAttributesTestBuilder<TAttributesTestBuilder>

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void ChangingRouteToShouldNotThrowExceptionWithActionWithTheAttribute()
2020
.Instance()
2121
.Calling(c => c.VariousAttributesAction())
2222
.ShouldHave()
23-
.ActionAttributes(attributes => attributes.ChangingRouteTo("/api/test"));
23+
.ActionAttributes(attributes => attributes.SpecifyingRoute("/api/test"));
2424
}
2525

2626
[Fact]
@@ -30,7 +30,7 @@ public void ChangingRouteToShouldNotThrowExceptionWithActionWithTheAttributeAndC
3030
.Instance()
3131
.Calling(c => c.VariousAttributesAction())
3232
.ShouldHave()
33-
.ActionAttributes(attributes => attributes.ChangingRouteTo("/api/Test"));
33+
.ActionAttributes(attributes => attributes.SpecifyingRoute("/api/Test"));
3434
}
3535

3636
[Fact]
@@ -43,7 +43,7 @@ public void ChangingRouteToShouldThrowExceptionWithActionWithTheAttributeAndWron
4343
.Instance()
4444
.Calling(c => c.VariousAttributesAction())
4545
.ShouldHave()
46-
.ActionAttributes(attributes => attributes.ChangingRouteTo("/api/another"));
46+
.ActionAttributes(attributes => attributes.SpecifyingRoute("/api/another"));
4747
},
4848
"When calling VariousAttributesAction action in MvcController expected action to have RouteAttribute with '/api/another' template, but in fact found '/api/test'.");
4949
}
@@ -55,7 +55,7 @@ public void ChangingRouteToShouldNotThrowExceptionWithActionWithTheAttributeAndC
5555
.Instance()
5656
.Calling(c => c.VariousAttributesAction())
5757
.ShouldHave()
58-
.ActionAttributes(attributes => attributes.ChangingRouteTo("/api/test", withName: "TestRoute"));
58+
.ActionAttributes(attributes => attributes.SpecifyingRoute("/api/test", withName: "TestRoute"));
5959
}
6060

6161
[Fact]
@@ -68,7 +68,7 @@ public void ChangingRouteToShouldThrowExceptionWithActionWithTheAttributeAndWron
6868
.Instance()
6969
.Calling(c => c.VariousAttributesAction())
7070
.ShouldHave()
71-
.ActionAttributes(attributes => attributes.ChangingRouteTo("/api/test", withName: "AnotherRoute"));
71+
.ActionAttributes(attributes => attributes.SpecifyingRoute("/api/test", withName: "AnotherRoute"));
7272
},
7373
"When calling VariousAttributesAction action in MvcController expected action to have RouteAttribute with 'AnotherRoute' name, but in fact found 'TestRoute'.");
7474
}
@@ -80,7 +80,7 @@ public void ChangingRouteToShouldNotThrowExceptionWithActionWithTheAttributeAndC
8080
.Instance()
8181
.Calling(c => c.VariousAttributesAction())
8282
.ShouldHave()
83-
.ActionAttributes(attributes => attributes.ChangingRouteTo("/api/test", withOrder: 1));
83+
.ActionAttributes(attributes => attributes.SpecifyingRoute("/api/test", withOrder: 1));
8484
}
8585

8686
[Fact]
@@ -93,7 +93,7 @@ public void ChangingRouteToShouldThrowExceptionWithActionWithTheAttributeAndWron
9393
.Instance()
9494
.Calling(c => c.VariousAttributesAction())
9595
.ShouldHave()
96-
.ActionAttributes(attributes => attributes.ChangingRouteTo("/api/test", withOrder: 2));
96+
.ActionAttributes(attributes => attributes.SpecifyingRoute("/api/test", withOrder: 2));
9797
},
9898
"When calling VariousAttributesAction action in MvcController expected action to have RouteAttribute with order of 2, but in fact found 1.");
9999
}
@@ -108,7 +108,7 @@ public void ChangingRouteToShouldThrowExceptionWithActionWithoutTheAttribute()
108108
.Instance()
109109
.Calling(c => c.NormalActionWithAttributes())
110110
.ShouldHave()
111-
.ActionAttributes(attributes => attributes.ChangingRouteTo("/api/test"));
111+
.ActionAttributes(attributes => attributes.SpecifyingRoute("/api/test"));
112112
},
113113
"When calling NormalActionWithAttributes action in MvcController expected action to have RouteAttribute, but in fact such was not found.");
114114
}
@@ -120,7 +120,7 @@ public void ChangingActionNameToShouldNotThrowExceptionWithActionWithTheAttribut
120120
.Instance()
121121
.Calling(c => c.VariousAttributesAction())
122122
.ShouldHave()
123-
.ActionAttributes(attributes => attributes.ChangingActionNameTo("NormalAction"));
123+
.ActionAttributes(attributes => attributes.SpecifyingActionName("NormalAction"));
124124
}
125125

126126
[Fact]
@@ -133,7 +133,7 @@ public void ChangingActionNameToShouldThrowExceptionWithActionWithTheAttributeAn
133133
.Instance()
134134
.Calling(c => c.VariousAttributesAction())
135135
.ShouldHave()
136-
.ActionAttributes(attributes => attributes.ChangingActionNameTo("AnotherAction"));
136+
.ActionAttributes(attributes => attributes.SpecifyingActionName("AnotherAction"));
137137
},
138138
"When calling VariousAttributesAction action in MvcController expected action to have ActionNameAttribute with 'AnotherAction' name, but in fact found 'NormalAction'.");
139139
}
@@ -148,7 +148,7 @@ public void ChangingActionNameToShouldThrowExceptionWithActionWithoutTheAttribut
148148
.Instance()
149149
.Calling(c => c.NormalActionWithAttributes())
150150
.ShouldHave()
151-
.ActionAttributes(attributes => attributes.ChangingActionNameTo("NormalAction"));
151+
.ActionAttributes(attributes => attributes.SpecifyingActionName("NormalAction"));
152152
},
153153
"When calling NormalActionWithAttributes action in MvcController expected action to have ActionNameAttribute, but in fact such was not found.");
154154
}
@@ -1850,7 +1850,7 @@ public void WithNoShouldWorkCorrectly()
18501850
.Instance()
18511851
.Calling(c => c.EmptyActionWithParameters(With.No<int>(), With.No<RequestModel>()))
18521852
.ShouldHave()
1853-
.ActionAttributes(attributes => attributes.ChangingActionNameTo("Test"));
1853+
.ActionAttributes(attributes => attributes.SpecifyingActionName("Test"));
18541854
}
18551855

18561856
[Fact]
@@ -1865,7 +1865,7 @@ public void AndAlsoShouldWorkCorrectly()
18651865
.AllowingAnonymousRequests()
18661866
.AndAlso()
18671867
.DisablingActionCall()
1868-
.ChangingActionNameTo("NormalAction"));
1868+
.SpecifyingActionName("NormalAction"));
18691869
}
18701870
}
18711871
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ public void ChangingRouteToShouldNotThrowExceptionWithControllerWithTheAttribute
1616
{
1717
MyController<AttributesController>
1818
.ShouldHave()
19-
.Attributes(attributes => attributes.ChangingRouteTo("api/test"));
19+
.Attributes(attributes => attributes.SpecifyingRoute("api/test"));
2020
}
2121

2222
[Fact]
2323
public void ChangingRouteToShouldNotThrowExceptionWithControllerWithTheAttributeAndCaseDifference()
2424
{
2525
MyController<AttributesController>
2626
.ShouldHave()
27-
.Attributes(attributes => attributes.ChangingRouteTo("api/Test"));
27+
.Attributes(attributes => attributes.SpecifyingRoute("api/Test"));
2828
}
2929

3030
[Fact]
@@ -33,7 +33,7 @@ public void ChangingRouteToShouldNotThrowExceptionWithControllerWithTheAttribute
3333
MyController<AttributesController>
3434
.ShouldHave()
3535
.Attributes(attributes => attributes
36-
.ChangingRouteTo(route => route
36+
.SpecifyingRoute(route => route
3737
.WithOrder(1)
3838
.AndAlso()
3939
.WithName("TestRouteAttributes")
@@ -49,7 +49,7 @@ public void ChangingRouteToShouldThrowExceptionWithControllerWithTheAttributeAnd
4949
{
5050
MyController<AttributesController>
5151
.ShouldHave()
52-
.Attributes(attributes => attributes.ChangingRouteTo("api/another"));
52+
.Attributes(attributes => attributes.SpecifyingRoute("api/another"));
5353
},
5454
"When testing AttributesController was expected to have RouteAttribute with 'api/another' template, but in fact found 'api/test'.");
5555
}
@@ -59,7 +59,7 @@ public void ChangingRouteToShouldNotThrowExceptionWithControllerWithTheAttribute
5959
{
6060
MyController<AttributesController>
6161
.ShouldHave()
62-
.Attributes(attributes => attributes.ChangingRouteTo("api/test", withName: "TestRouteAttributes"));
62+
.Attributes(attributes => attributes.SpecifyingRoute("api/test", withName: "TestRouteAttributes"));
6363
}
6464

6565
[Fact]
@@ -70,7 +70,7 @@ public void ChangingRouteToShouldThrowExceptionWithActionWithTheAttributeAndWron
7070
{
7171
MyController<AttributesController>
7272
.ShouldHave()
73-
.Attributes(attributes => attributes.ChangingRouteTo("api/test", withName: "AnotherRoute"));
73+
.Attributes(attributes => attributes.SpecifyingRoute("api/test", withName: "AnotherRoute"));
7474
},
7575
"When testing AttributesController was expected to have RouteAttribute with 'AnotherRoute' name, but in fact found 'TestRouteAttributes'.");
7676
}
@@ -80,7 +80,7 @@ public void ChangingRouteToShouldNotThrowExceptionWithActionWithTheAttributeAndC
8080
{
8181
MyController<AttributesController>
8282
.ShouldHave()
83-
.Attributes(attributes => attributes.ChangingRouteTo("api/test", withOrder: 1));
83+
.Attributes(attributes => attributes.SpecifyingRoute("api/test", withOrder: 1));
8484
}
8585

8686
[Fact]
@@ -91,7 +91,7 @@ public void ChangingRouteToShouldThrowExceptionWithActionWithTheAttributeAndWron
9191
{
9292
MyController<AttributesController>
9393
.ShouldHave()
94-
.Attributes(attributes => attributes.ChangingRouteTo("api/test", withOrder: 2));
94+
.Attributes(attributes => attributes.SpecifyingRoute("api/test", withOrder: 2));
9595
},
9696
"When testing AttributesController was expected to have RouteAttribute with order of 2, but in fact found 1.");
9797
}
@@ -104,7 +104,7 @@ public void ChangingRouteToShouldThrowExceptionWithActionWithoutTheAttribute()
104104
{
105105
MyController<AreaController>
106106
.ShouldHave()
107-
.Attributes(attributes => attributes.ChangingRouteTo("api/test"));
107+
.Attributes(attributes => attributes.SpecifyingRoute("api/test"));
108108
},
109109
"When testing AreaController was expected to have RouteAttribute, but in fact such was not found.");
110110
}
@@ -1496,7 +1496,7 @@ public void AndAlsoShouldWorkCorrectly()
14961496
=> attributes
14971497
.AllowingAnonymousRequests()
14981498
.AndAlso()
1499-
.ChangingRouteTo("api/test"));
1499+
.SpecifyingRoute("api/test"));
15001500
}
15011501
}
15021502
}

0 commit comments

Comments
 (0)