Skip to content

Commit 9243f7e

Browse files
Add tests for IncludingInherited for controllers and actions
1 parent 0285a8a commit 9243f7e

File tree

4 files changed

+37
-19
lines changed

4 files changed

+37
-19
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Setups.Controllers;
77
using Xunit;
88
using System;
9+
using Microsoft.AspNetCore.Authorization;
910

1011
public class ActionAttributesTestBuilderTests
1112
{
@@ -118,5 +119,17 @@ public void PassingForShouldThrowExceptionWithIncorrectAttributeWithPredicate()
118119
},
119120
"When calling OtherAttributes action in MvcController expected action to have ActionNameAttribute, but in fact such was not found.");
120121
}
122+
123+
[Fact]
124+
public void IncludingInheritedShouldIncludeAllCustomInheritedAttributesFromBaseMethodsAndNotThrowException()
125+
{
126+
MyController<InheritControllerAttributes>
127+
.Instance()
128+
.Calling(c=> c.MethodA())
129+
.ShouldHave()
130+
.ActionAttributes(attributes => attributes.IncludingInherited()
131+
.ContainingAttributeOfType<HttpPostAttribute>()
132+
.ContainingAttributeOfType<AuthorizeAttribute>());
133+
}
121134
}
122135
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void PassingForShouldThrowExceptionWithIncorrectAttributeWithPredicate()
111111
[Fact]
112112
public void IncludingInheritedShouldIncludeAllCustomInheritedAttributesFromBaseClassesAndNotThrowException()
113113
{
114-
MyController<InheritAttributesController>
114+
MyController<InheritControllerAttributes>
115115
.Instance()
116116
.ShouldHave()
117117
.Attributes(attributes => attributes.IncludingInherited()
@@ -126,7 +126,7 @@ public void TryingToAssertInheritedAttributesWithoutIncludingInheritedShouldThro
126126
Test.AssertException<AttributeAssertionException>(
127127
() =>
128128
{
129-
MyController<InheritAttributesController>
129+
MyController<InheritControllerAttributes>
130130
.Instance()
131131
.ShouldHave()
132132
.Attributes(attributes => attributes//.IncludingInherited()

test/MyTested.AspNetCore.Mvc.Test.Setups/Controllers/InheritAttributesController.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace MyTested.AspNetCore.Mvc.Test.Setups.Controllers
2+
{
3+
using System;
4+
using Microsoft.AspNetCore.Authorization;
5+
using Microsoft.AspNetCore.Mvc;
6+
7+
[ResponseCache]
8+
public class InheritControllerAttributes : InheritAttributesBaseController
9+
{
10+
public override uint MethodA()
11+
=> 10;
12+
}
13+
14+
[AllowAnonymous]
15+
[ValidateAntiForgeryToken]
16+
public abstract class InheritAttributesBaseController : ControllerBase
17+
{
18+
[Authorize]
19+
[HttpPost]
20+
public abstract uint MethodA();
21+
}
22+
}

0 commit comments

Comments
 (0)