Skip to content

Commit 29af45d

Browse files
committed
Merge branch 'version-3.1' of github.com:ivaylokenov/MyTested.AspNetCore.Mvc into version-3.1
2 parents 2723968 + 1e661ad commit 29af45d

File tree

18 files changed

+378
-66
lines changed

18 files changed

+378
-66
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
<table>
2020
<tbody>
2121
<tr>
22+
<td align="center" valign="middle">
23+
<a href="https://bit.ly/ciu-zuehlke" target="_blank">
24+
<img width="148px" src="https://user-images.githubusercontent.com/3391906/84595391-4ec75080-ae60-11ea-8bc4-2b5e4b17a345.jpg">
25+
</a>
26+
</td>
2227
<td align="center" valign="middle">
2328
<a href="https://softuni.org/" target="_blank">
2429
<img width="148px" src="https://softuni.foundation/wp-content/uploads/2017/08/SoftUni_Foundation_Logo_Oneline-1.png">
@@ -52,6 +57,25 @@
5257
</tbody>
5358
</table>
5459

60+
## Special Sponsors
61+
62+
<table>
63+
<tbody>
64+
<tr>
65+
<td align="center" valign="middle">
66+
<a href="http://bit.ly/bellatrixsolutions" target="_blank">
67+
<img width="148px" src="https://user-images.githubusercontent.com/3391906/68993273-d4f5c700-087e-11ea-9b39-e173733fcbfb.png" alt="The Ultimate Cross-Platform .NET Framework">
68+
</a>
69+
</td>
70+
<td align="center" valign="middle">
71+
<a href="https://www.jetbrains.com/?from=MyTestedASP.NET" target="_blank">
72+
<img width="148px" src="https://user-images.githubusercontent.com/3391906/72542498-ee21f080-388c-11ea-92ac-0b0153028933.png" alt="JetBrains">
73+
</a>
74+
</td>
75+
</tr>
76+
</tbody>
77+
</table>
78+
5579
## Project Description
5680

5781
**MyTested.AspNetCore.Mvc** is a strongly-typed unit testing library providing an easy fluent interface to test the [ASP.NET Core](https://github.com/aspnet/AspNetCore) framework, perfectly suitable for both MVC and API scenarios. It is testing framework agnostic so that you can combine it with a test runner of your choice (e.g. [xUnit](https://github.com/xunit/xunit), [NUnit](https://github.com/nunit/nunit), etc.).

docs/_docfx/tutorial/helpers.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ public void AddressAndPaymentShouldRerurnRedirectWithValidData(
186186

187187
Running this test will give us the following strange error message:
188188

189-
``` When calling AddressAndPayment action in CheckoutController expected redirect result to have resolved location to '/Checkout/Complete/1', but in fact received '/Home/Complete/1'.
189+
```
190+
When calling AddressAndPayment action in CheckoutController expected redirect result to have resolved location to '/Checkout/Complete/1', but in fact received '/Home/Complete/1'.
190191
```
191192

192193
The problem is that the request path is empty which makes the action route data being invalid. For that reason, we are receiving wrong redirection location. The fix is easy - just call **"WithRouteData"**:

docs/_docfx/tutorial/routing.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ The simplest route test possible:
5151

5252
```c#
5353
[Fact]
54-
public void GetErrorActionShouldBeRoutedSuccessfuly()
54+
public void GetErrorActionShouldBeRoutedSuccessfully()
5555
=> MyRouting
5656
.Configuration()
5757
.ShouldMap("/Home/Error")
@@ -71,11 +71,11 @@ public async Task<IActionResult> AddToCart(int id)
7171
}
7272
```
7373

74-
Create **"ShoppingCartRouteTest""** class and add the following test:
74+
Create **"ShoppingCartRouteTest"** class and add the following test:
7575

7676
```c#
7777
[Fact]
78-
public void GetAddToCartActionShouldBeRoutedSuccessfuly()
78+
public void GetAddToCartActionShouldBeRoutedSuccessfully()
7979
=> MyRouting
8080
.Configuration()
8181
.ShouldMap("/ShoppingCart/AddToCart/1")
@@ -91,11 +91,11 @@ public async Task<IActionResult> Browse(string genre)
9191
}
9292
```
9393

94-
Create **"StoreRouteTest""** class and add the following test:
94+
Create **"StoreRouteTest"** class and add the following test:
9595

9696
```c#
9797
[Fact]
98-
public void GetBrowseActionShouldBeRoutedSuccessfuly()
98+
public void GetBrowseActionShouldBeRoutedSuccessfully()
9999
=> MyRouting
100100
.Configuration()
101101
.ShouldMap("/Store/Browse?genre=HipHop")
@@ -125,7 +125,7 @@ We do not want to test the **"MusicStoreContext"** and the **"IMemoryCache"** ac
125125

126126
```c#
127127
[Fact]
128-
public void GetIndexActionShouldBeRoutedSuccessfuly()
128+
public void GetIndexActionShouldBeRoutedSuccessfully()
129129
=> MyRouting
130130
.Configuration()
131131
.ShouldMap("/Home")
@@ -154,7 +154,7 @@ The following test will fail right away:
154154

155155
```c#
156156
[Fact]
157-
public void PostRemoveFromCartActionShouldBeRoutedSuccessfuly()
157+
public void PostRemoveFromCartActionShouldBeRoutedSuccessfully()
158158
=> MyRouting
159159
.Configuration()
160160
.ShouldMap("/ShoppingCart/RemoveFromCart/1")
@@ -167,7 +167,7 @@ We are testing with HTTP Get request while the action is restricted only for HTT
167167

168168
```c#
169169
[Fact]
170-
public void PostRemoveFromCartActionShouldBeRoutedSuccessfuly()
170+
public void PostRemoveFromCartActionShouldBeRoutedSuccessfully()
171171
=> MyRouting
172172
.Configuration()
173173
.ShouldMap(request => request // <---
@@ -225,7 +225,7 @@ Let's update the test to make it pass:
225225

226226
```c#
227227
[Fact]
228-
public void PostRemoveFromCartActionShouldBeRoutedSuccessfuly()
228+
public void PostRemoveFromCartActionShouldBeRoutedSuccessfully()
229229
=> MyRouting
230230
.Configuration()
231231
.ShouldMap(request => request
@@ -245,7 +245,7 @@ Let's test a **"CheckoutController"** action, because all actions in that contro
245245

246246
```c#
247247
[Fact]
248-
public void GetAddressAndPaymentActionShouldBeRoutedSuccessfuly()
248+
public void GetAddressAndPaymentActionShouldBeRoutedSuccessfully()
249249
=> MyRouting
250250
.Configuration()
251251
.ShouldMap(request => request
@@ -290,7 +290,7 @@ Let's test that route! In **"Routing"**, create an **"Admin"** folder. In it cre
290290

291291
```c#
292292
[Fact]
293-
public void GetIndexActionShouldBeRoutedSuccessfuly()
293+
public void GetIndexActionShouldBeRoutedSuccessfully()
294294
=> MyRouting
295295
.Configuration()
296296
.ShouldMap(request => request
@@ -320,7 +320,7 @@ The login view model should come from the request form so we may decide to ignor
320320

321321
```c#
322322
[Fact]
323-
public void PostLoginActionShouldBeRoutedSuccessfuly()
323+
public void PostLoginActionShouldBeRoutedSuccessfully()
324324
=> MyRouting
325325
.Configuration()
326326
.ShouldMap(request => request

docs/_docfx/tutorial/viewcomponents.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ MyViewComponent<CartSummaryComponent>
118118
.Instance()
119119
.WithSession(session => session
120120
.WithEntry("Session", "TestCart"))
121-
.WithData(db => db
122-
.WithEntities(entities => entities
123-
.AddRange(GetCartItems("TestCart", "TestAlbum"))))
121+
.WithData(CartItemData.GetMany("TestCart", "TestAlbum"))
124122
.InvokedWith(vc => vc.InvokeAsync()) // <---
125123
```
126124

@@ -133,9 +131,7 @@ MyViewComponent<CartSummaryComponent>
133131
.Instance()
134132
.WithSession(session => session
135133
.WithEntry("Session", "TestCart"))
136-
.WithData(db => db
137-
.WithEntities(entities => entities
138-
.AddRange(GetCartItems("TestCart", "TestAlbum"))))
134+
.WithData(CartItemData.GetMany("TestCart", "TestAlbum"))
139135
.InvokedWith(vc => vc.InvokeAsync())
140136
.ShouldHave() // <---
141137
.ViewBag(viewBag => viewBag

src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Contracts/Attributes/IBaseAttributesTestBuilder.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,12 @@ TAttributesTestBuilder PassingFor<TAttribute>(Action<TAttribute> assertions)
4141
/// <returns>The same attributes test builder.</returns>
4242
TAttributesTestBuilder PassingFor<TAttribute>(Func<TAttribute, bool> predicate)
4343
where TAttribute : Attribute;
44+
45+
46+
/// <summary>
47+
/// Adds inherited attributes.
48+
/// </summary>
49+
/// <returns>The same attributes test builder.</returns>
50+
TAttributesTestBuilder IncludingInherited();
4451
}
4552
}

src/MyTested.AspNetCore.Mvc.Abstractions/Internal/TestContexts/ComponentTestContext.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ public abstract class ComponentTestContext : HttpTestContext
2222

2323
public object Component => this.component ??= this.ComponentConstructionDelegate();
2424

25-
public IEnumerable<object> ComponentAttributes
26-
=> this.componentAttributes ??= Reflection.GetCustomAttributes(this.Component);
25+
public IEnumerable<object> ComponentAttributes
26+
{
27+
get => this.componentAttributes ??= Reflection.GetCustomAttributes(this.Component);
28+
private set => this.componentAttributes = value;
29+
}
2730

2831
public IDictionary<Type, object> AggregatedDependencies
2932
=> this.aggregatedDependencies ??= new Dictionary<Type, object>();
@@ -66,27 +69,20 @@ public LambdaExpression MethodCall
6669
public object MethodResult
6770
{
6871
get => this.methodResult;
69-
7072
set => this.methodResult = this.ConvertMethodResult(value);
7173
}
7274

73-
public IEnumerable<object> MethodAttributes
74-
=> this.methodAttributes ??= Reflection.GetCustomAttributes(this.Method);
75+
public IEnumerable<object> MethodAttributes
76+
{
77+
get => this.methodAttributes ??= Reflection.GetCustomAttributes(this.Method);
78+
private set => this.methodAttributes = value;
79+
}
7580

7681
public Exception CaughtException { get; set; }
7782

7883
public object Model
7984
{
80-
get
81-
{
82-
if (this.model == null)
83-
{
84-
return this.MethodResult;
85-
}
86-
87-
return this.model;
88-
}
89-
85+
get => this.model ?? this.MethodResult;
9086
set => this.model = value;
9187
}
9288

@@ -116,6 +112,12 @@ public void Apply<TMethodResult>(InvocationTestContext<TMethodResult> invocation
116112
this.CaughtException = invocationTestContext.CaughtException;
117113
}
118114

115+
public void IncludeInheritedComponentAttributes()
116+
=> this.ComponentAttributes = Reflection.GetCustomAttributes(this.Component, true);
117+
118+
public void IncludeInheritedMethodAttributes()
119+
=> this.MethodAttributes = Reflection.GetCustomAttributes(this.Method, true);
120+
119121
protected virtual object ConvertMethodResult(object convertibleMethodResult) => convertibleMethodResult;
120122
}
121123
}

0 commit comments

Comments
 (0)