Skip to content

Commit f758987

Browse files
committed
Fixed all failing tests and reacted to route changes
1 parent 98cb647 commit f758987

File tree

21 files changed

+100
-86
lines changed

21 files changed

+100
-86
lines changed

samples/ApplicationParts/ApplicationParts.Test/RouteTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace ApplicationParts.Test
22
{
3-
using ApplicationParts.Controllers;
3+
using Controllers;
44
using MyTested.AspNetCore.Mvc;
55
using Xunit;
66

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
namespace ApplicationParts.Test
22
{
33
using Microsoft.AspNetCore.Hosting;
4-
using Microsoft.EntityFrameworkCore;
5-
using Microsoft.Extensions.DependencyInjection;
64
using Web;
7-
using Web.Data;
85

96
public class TestStartup : Startup
107
{
118
public TestStartup(IHostingEnvironment env)
129
: base(env)
1310
{
1411
}
15-
16-
public void ConfigureTestServices(IServiceCollection services)
17-
{
18-
base.ConfigureServices(services);
19-
20-
services.AddDbContext<ApplicationDbContext>(opts => opts.UseInMemoryDatabase());
21-
}
2212
}
2313
}

samples/MusicStore/MusicStore.Test/Controllers/ShoppingCartControllerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void AddToCartShouldAddItemsToCart()
8484
.WithDbContext(db => db
8585
.WithEntities<MusicStoreContext>(entities => entities
8686
.AddRange(CreateTestAlbums(itemPrice: 10))))
87-
.Calling(c => c.AddToCart(albumId, CancellationToken.None))
87+
.Calling(c => c.AddToCart(albumId))
8888
.ShouldReturn()
8989
.Redirect()
9090
.To<ShoppingCartController>(c => c.Index())

samples/MusicStore/MusicStore.Test/Routes/ShoppingCartRouteTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void AddToCartShouldBeRoutedCorrectly()
2222
MyMvc
2323
.Routes()
2424
.ShouldMap("/ShoppingCart/AddToCart/1")
25-
.To<ShoppingCartController>(c => c.AddToCart(1, With.Any<CancellationToken>()));
25+
.To<ShoppingCartController>(c => c.AddToCart(1));
2626
}
2727

2828
[Fact]

samples/MusicStore/MusicStore.Web/Controllers/HomeController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public HomeController(IOptions<AppSettings> options)
1818
{
1919
_appSettings = options.Value;
2020
}
21+
2122
//
2223
// GET: /Home/
2324
public async Task<IActionResult> Index(

samples/MusicStore/MusicStore.Web/Controllers/ShoppingCartController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public async Task<IActionResult> Index()
4141
//
4242
// GET: /ShoppingCart/AddToCart/5
4343

44-
public async Task<IActionResult> AddToCart(int id, CancellationToken requestAborted)
44+
public async Task<IActionResult> AddToCart(int id)
4545
{
4646
// Retrieve the album from the database
4747
var addedAlbum = await DbContext.Albums
@@ -52,7 +52,7 @@ public async Task<IActionResult> AddToCart(int id, CancellationToken requestAbor
5252

5353
await cart.AddToCart(addedAlbum);
5454

55-
await DbContext.SaveChangesAsync(requestAborted);
55+
await DbContext.SaveChangesAsync();
5656
_logger.LogInformation("Album {albumId} was added to the cart.", addedAlbum.AlbumId);
5757

5858
// Go back to the main store page for more shopping

src/MyTested.AspNetCore.Mvc.Core/Internal/Application/TestApplication.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ private static void PrepareRouteServices(IServiceCollection serviceCollection)
420420
private static void PrepareApplicationAndRoutes(StartupMethods startupMethods)
421421
{
422422
var applicationBuilder = new MockedApplicationBuilder(serviceProvider);
423-
423+
424424
startupMethods?.ConfigureDelegate?.Invoke(applicationBuilder);
425425

426426
AdditionalApplicationConfiguration?.Invoke(applicationBuilder);

src/MyTested.AspNetCore.Mvc.Core/Internal/Routes/InternalRouteResolver.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,21 @@ public static ResolvedRouteContext Resolve(IServiceProvider services, IRouter ro
3737
}
3838

3939
var actionSelector = services.GetRequiredService<IActionSelector>();
40-
var actionInvokerFactory = services.GetRequiredService<IActionInvokerFactory>();
4140

4241
ActionDescriptor actionDescriptor;
4342
try
4443
{
44+
var actions = routeContext
45+
.RouteData
46+
.Routers
47+
.OfType<MvcAttributeRouteHandler>()
48+
.FirstOrDefault()
49+
?.Actions
50+
?? actionSelector.SelectCandidates(routeContext);
51+
4552
actionDescriptor = actionSelector.SelectBestCandidate(
4653
routeContext,
47-
actionSelector.SelectCandidates(routeContext));
54+
actions);
4855
}
4956
catch (Exception ex)
5057
{
@@ -64,6 +71,8 @@ public static ResolvedRouteContext Resolve(IServiceProvider services, IRouter ro
6471
throw new InvalidOperationException("Only controller actions are supported by the route testing.");
6572
}
6673

74+
var actionInvokerFactory = services.GetRequiredService<IActionInvokerFactory>();
75+
6776
var invoker = actionInvokerFactory.CreateInvoker(actionContext);
6877
var modelBindingActionInvoker = invoker as IModelBindingActionInvoker;
6978
if (modelBindingActionInvoker == null)

test/MyTested.AspNetCore.Mvc.Core.Test/BuildersTests/ActionResultsTests/CreatedTests/CreatedTestBuilderTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -907,11 +907,11 @@ public void ContainingOutputFormattersShouldThrowExceptionWithIncorrectValue()
907907
.Created()
908908
.ContainingOutputFormatters(new List<IOutputFormatter>
909909
{
910-
TestObjectFactory.GetOutputFormatter(),
911-
new CustomOutputFormatter()
910+
new CustomOutputFormatter(),
911+
new StringOutputFormatter()
912912
});
913913
},
914-
"When calling FullCreatedAction action in MvcController expected created result output formatters to contain formatter of HttpNotAcceptableOutputFormatter type, but none was found.");
914+
"When calling FullCreatedAction action in MvcController expected created result output formatters to contain formatter of StringOutputFormatter type, but none was found.");
915915
}
916916

917917
[Fact]

test/MyTested.AspNetCore.Mvc.Core.Test/BuildersTests/ActionResultsTests/HttpNotFoundTests/HttpNotFoundTestBuilderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,11 @@ public void ContainingOutputFormattersShouldThrowExceptionWithIncorrectValue()
385385
.NotFound()
386386
.ContainingOutputFormatters(new List<IOutputFormatter>
387387
{
388-
TestObjectFactory.GetOutputFormatter(),
388+
new StringOutputFormatter(),
389389
new CustomOutputFormatter()
390390
});
391391
},
392-
"When calling FullHttpNotFoundAction action in MvcController expected HTTP not found result output formatters to contain formatter of HttpNotAcceptableOutputFormatter type, but none was found.");
392+
"When calling FullHttpNotFoundAction action in MvcController expected HTTP not found result output formatters to contain formatter of StringOutputFormatter type, but none was found.");
393393
}
394394

395395
[Fact]

0 commit comments

Comments
 (0)