Skip to content

Commit 60218c2

Browse files
authored
Merge pull request #327 - Make InvokedWith More Accessible
Make InvokedWith More Accessible
2 parents e923fdf + d75e819 commit 60218c2

File tree

32 files changed

+23
-208
lines changed

32 files changed

+23
-208
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
namespace MyTested.AspNetCore.Mvc
22
{
33
using System;
4+
using System.Linq.Expressions;
5+
using System.Threading.Tasks;
6+
using Builders.Contracts.Invocations;
47
using Builders.Contracts.ViewComponents;
58
using Builders.ViewComponents;
69
using Internal.Application;
@@ -71,5 +74,25 @@ public static IViewComponentBuilder<TViewComponent> Instance(Func<TViewComponent
7174
public new static IViewComponentTestBuilder ShouldHave()
7275
=> Instance()
7376
.ShouldHave();
77+
78+
/// <summary>
79+
/// Indicates which view component method should be invoked and tested.
80+
/// </summary>
81+
/// <typeparam name="TInvocationResult">Type of result from the invocation.</typeparam>
82+
/// <param name="invocationCall">Method call expression indicating invoked method.</param>
83+
/// <returns>Test builder of <see cref="IViewComponentResultTestBuilder{TInvocationResult}"/> type.</returns>
84+
public new static IViewComponentResultTestBuilder<TInvocationResult> InvokedWith<TInvocationResult>(Expression<Func<TViewComponent, TInvocationResult>> invocationCall)
85+
=> Instance()
86+
.InvokedWith(invocationCall);
87+
88+
/// <summary>
89+
/// Indicates which view component method should be invoked and tested.
90+
/// </summary>
91+
/// <typeparam name="TInvocationResult">Type of result from the invocation.</typeparam>
92+
/// <param name="invocationCall">Method call expression indicating invoked asynchronous method.</param>
93+
/// <returns>Test builder of <see cref="IViewComponentResultTestBuilder{TInvocationResult}"/> type.</returns>
94+
public new static IViewComponentResultTestBuilder<TInvocationResult> InvokedWith<TInvocationResult>(Expression<Func<TViewComponent, Task<TInvocationResult>>> invocationCall)
95+
=> Instance()
96+
.InvokedWith(invocationCall);
7497
}
7598
}

test/MyTested.AspNetCore.Mvc.Caching.Test/BuildersTests/DataTests/MemoryCacheEntryDetailsTestBuilderTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public void WithValidShouldThrowExceptionWithIncorrectValuePredicate()
7878
public void WithValidShouldNotThrowExceptionWithViewComponentCorrectValuePredicate()
7979
{
8080
MyViewComponent<MemoryCacheValuesComponent>
81-
.Instance()
8281
.InvokedWith(c => c.Invoke())
8382
.ShouldHave()
8483
.MemoryCache(memoryCache => memoryCache
@@ -98,7 +97,6 @@ public void WithValidShouldThrowExceptionWithViewComponentIncorrectValuePredicat
9897
() =>
9998
{
10099
MyViewComponent<MemoryCacheValuesComponent>
101-
.Instance()
102100
.InvokedWith(c => c.Invoke())
103101
.ShouldHave()
104102
.MemoryCache(memoryCache => memoryCache

test/MyTested.AspNetCore.Mvc.Caching.Test/BuildersTests/InvocationsTests/ShouldHaveTests/ShouldHaveMemoryCacheTests.cs

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

test/MyTested.AspNetCore.Mvc.Caching.Test/ServicesTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public void MockMemoryCacheShouldBeDifferentForEveryViewComponentCallSynchronous
6868
.View();
6969

7070
MyViewComponent<MemoryCacheComponent>
71-
.Instance()
7271
.InvokedWith(c => c.Invoke())
7372
.ShouldReturn()
7473
.Content("No cache");

test/MyTested.AspNetCore.Mvc.EntityFrameworkCore.Test/BuildersTests/InvocationsTests/ShouldHaveTests/ShouldHaveDbContextTests.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public void DbContextShouldNotThrowExceptionWithCorrectAssertions()
2121
});
2222

2323
MyViewComponent<CreateDataComponent>
24-
.Instance()
2524
.InvokedWith(c => c.Invoke(new CustomModel { Id = 1, Name = "Test" }))
2625
.ShouldHave()
2726
.Data(dbContext => dbContext
@@ -47,7 +46,6 @@ public void DbContextShouldNotThrowExceptionWithCorrectPredicate()
4746
});
4847

4948
MyViewComponent<CreateDataComponent>
50-
.Instance()
5149
.InvokedWith(c => c.Invoke(new CustomModel { Id = 1, Name = "Test" }))
5250
.ShouldHave()
5351
.Data(dbContext => dbContext
@@ -70,7 +68,6 @@ public void DbContextShouldThrowExceptionWithIncorrectPredicate()
7068
});
7169

7270
MyViewComponent<CreateDataComponent>
73-
.Instance()
7471
.InvokedWith(c => c.Invoke(new CustomModel { Id = 1, Name = "Test" }))
7572
.ShouldHave()
7673
.Data(dbContext => dbContext
@@ -82,7 +79,6 @@ public void DbContextShouldThrowExceptionWithIncorrectPredicate()
8279
Test.AssertException<DataProviderAssertionException>(() =>
8380
{
8481
MyViewComponent<CreateDataComponent>
85-
.Instance()
8682
.InvokedWith(c => c.Invoke(new CustomModel { Id = 2, Name = "Test" }))
8783
.ShouldHave()
8884
.Data(dbContext => dbContext

test/MyTested.AspNetCore.Mvc.EntityFrameworkCore.Test/BuildersTests/ViewComponentsTests/ViewComponentBuilderTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public void WithEntitesShouldSetupDbContext()
6363
.Content("Invalid");
6464

6565
MyViewComponent<FindDataComponent>
66-
.Instance()
6766
.InvokedWith(c => c.Invoke(1))
6867
.ShouldReturn()
6968
.Content("Invalid");
@@ -111,7 +110,6 @@ public void WithSetShouldSetupDbContext()
111110
.Content("Invalid");
112111

113112
MyViewComponent<FindDataComponent>
114-
.Instance()
115113
.InvokedWith(c => c.Invoke(1))
116114
.ShouldReturn()
117115
.Content("Invalid");

test/MyTested.AspNetCore.Mvc.Helpers.Test/BuildersTests/InvocationsTests/ShouldReturnTests/ViewComponentShouldReturnViewTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public class ViewComponentShouldReturnViewTests
1010
public void ShouldReturnViewWithNameShouldNotThrowExceptionWithCorrectModel()
1111
{
1212
MyViewComponent<ViewResultComponent>
13-
.Instance()
1413
.InvokedWith(c => c.Invoke("model"))
1514
.ShouldReturn()
1615
.View(new ResponseModel { StringValue = "TestValue" });
@@ -20,7 +19,6 @@ public void ShouldReturnViewWithNameShouldNotThrowExceptionWithCorrectModel()
2019
public void ShouldReturnViewWithNameShouldNotThrowExceptionWithCorrectNameAndModel()
2120
{
2221
MyViewComponent<ViewResultComponent>
23-
.Instance()
2422
.InvokedWith(c => c.Invoke("All"))
2523
.ShouldReturn()
2624
.View("SomeView", new ResponseModel { IntegerValue = 10 });

test/MyTested.AspNetCore.Mvc.Http.Test/BuildersTests/HttpTests/HttpResponseTestBuilderTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,6 @@ public void WithJsonBodyAsStringShouldWorkCorrectly()
695695
public void ViewComponentInvocationShouldNotThrowExceptionWithCorrectResponse()
696696
{
697697
MyViewComponent<HttpResponseComponent>
698-
.Instance()
699698
.InvokedWith(c => c.Invoke())
700699
.ShouldHave()
701700
.HttpResponse(response => response
@@ -723,7 +722,6 @@ public void ViewComponentWithJsonBodyShouldThrowExceptionWithWrongBody()
723722
() =>
724723
{
725724
MyViewComponent<HttpResponseComponent>
726-
.Instance()
727725
.InvokedWith(c => c.Invoke())
728726
.ShouldHave()
729727
.HttpResponse(response => response.WithJsonBody(new RequestModel { Integer = 2, RequiredString = "Text" }));

test/MyTested.AspNetCore.Mvc.Http.Test/BuildersTests/ViewComponentsTests/ViewComponentBuilderTests.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ public void WithHttpContextSetupShouldPopulateContextProperties()
8787
public void WithRequestShouldNotWorkWithDefaultRequestAction()
8888
{
8989
MyViewComponent<HttpRequestComponent>
90-
.Instance()
9190
.InvokedWith(c => c.Invoke())
9291
.ShouldReturn()
9392
.Content();
@@ -122,7 +121,6 @@ public void WithRequestAsObjectShouldWorkWithSetRequestAction()
122121
public void HttpResponseAssertionsShouldWorkCorrectly()
123122
{
124123
MyViewComponent<NormalComponent>
125-
.Instance()
126124
.InvokedWith(c => c.Invoke())
127125
.ShouldReturn()
128126
.Content()
@@ -136,7 +134,6 @@ public void HttpResponseAssertionsShouldWorkCorrectly()
136134
public void HttpResponsePredicateShouldWorkCorrectly()
137135
{
138136
MyViewComponent<NormalComponent>
139-
.Instance()
140137
.InvokedWith(c => c.Invoke())
141138
.ShouldPassForThe<HttpResponse>(response => response != null);
142139
}
@@ -148,7 +145,6 @@ public void HttpResponsePredicateShouldThrowExceptionWithInvalidTest()
148145
() =>
149146
{
150147
MyViewComponent<NormalComponent>
151-
.Instance()
152148
.InvokedWith(c => c.Invoke())
153149
.ShouldPassForThe<HttpResponse>(response => response == null);
154150
},

test/MyTested.AspNetCore.Mvc.ModelState.Test/BuildersTests/ActionsTests/ShouldHaveTests/ShouldHaveModelStateTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ public void AndShouldWorkCorrectlyWithInvalidModelState()
146146
public void ShouldHaveValidModelStateShouldBeValidWithViewComponentValidModelState()
147147
{
148148
MyViewComponent<NormalComponent>
149-
.Instance()
150149
.InvokedWith(c => c.Invoke())
151150
.ShouldHave()
152151
.ValidModelState();
@@ -221,7 +220,6 @@ public void ShouldHaveInvalidModelStateShouldThrowExceptionWithValidViewComponen
221220
() =>
222221
{
223222
MyViewComponent<NormalComponent>
224-
.Instance()
225223
.InvokedWith(c => c.Invoke())
226224
.ShouldHave()
227225
.InvalidModelState();
@@ -236,7 +234,6 @@ public void ShouldHaveInvalidModelStateShouldThrowExceptionWithViewComponentMode
236234
() =>
237235
{
238236
MyViewComponent<NormalComponent>
239-
.Instance()
240237
.InvokedWith(c => c.Invoke())
241238
.ShouldHave()
242239
.InvalidModelState(withNumberOfErrors: 5);

0 commit comments

Comments
 (0)