Skip to content

Commit 98cb647

Browse files
committed
Fixed half of the failing unit tests after upgrading to 1.0.0
1 parent 923ad23 commit 98cb647

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
using Contracts;
77
using Microsoft.AspNetCore.Mvc;
88
using Microsoft.AspNetCore.Mvc.Controllers;
9-
using Microsoft.AspNetCore.Mvc.Filters;
10-
using Microsoft.AspNetCore.Mvc.Formatters;
119
using Microsoft.AspNetCore.Mvc.Internal;
1210
using Microsoft.AspNetCore.Mvc.ModelBinding;
13-
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
1411
using Microsoft.Extensions.Logging;
1512

1613
public class ModelBindingActionInvoker : ControllerActionInvoker, IModelBindingActionInvoker
1714
{
15+
private readonly IControllerFactory controllerFactory;
16+
private readonly IControllerArgumentBinder controllerArgumentBinder;
17+
private readonly ControllerContext controllerContext;
18+
1819
public ModelBindingActionInvoker(
1920
ControllerActionInvokerCache cache,
2021
IControllerFactory controllerFactory,
@@ -27,12 +28,22 @@ public ModelBindingActionInvoker(
2728
: base(cache, controllerFactory, controllerArgumentBinder, logger, diagnosticSource, actionContext, valueProviderFactories, maxModelValidationErrors)
2829
{
2930
this.BoundActionArguments = new Dictionary<string, object>();
31+
32+
this.controllerFactory = controllerFactory;
33+
this.controllerArgumentBinder = controllerArgumentBinder;
34+
35+
this.controllerContext = new ControllerContext(actionContext);
36+
this.controllerContext.ModelState.MaxAllowedErrors = maxModelValidationErrors;
37+
this.controllerContext.ValueProviderFactories = new List<IValueProviderFactory>(valueProviderFactories);
3038
}
3139

3240
public IDictionary<string, object> BoundActionArguments { get; private set; }
3341

3442
public override Task InvokeAsync()
3543
{
44+
var controller = this.controllerFactory.CreateController(this.controllerContext);
45+
this.controllerArgumentBinder.BindArgumentsAsync(controllerContext, controller, this.BoundActionArguments);
46+
3647
return TaskCache.CompletedTask;
3748
}
3849
}

src/MyTested.AspNetCore.Mvc.EntityFrameworkCore/Internal/ScopedInMemoryOptionsExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class ScopedInMemoryOptionsExtension : InMemoryOptionsExtension
1010
public override void ApplyServices(IServiceCollection services)
1111
{
1212
services
13-
.ReplaceLifetime<IInMemoryStore>(ServiceLifetime.Scoped)
13+
.ReplaceLifetime<IInMemoryStoreSource>(ServiceLifetime.Scoped)
1414
.ReplaceLifetime<InMemoryValueGeneratorCache>(ServiceLifetime.Scoped);
1515
}
1616
}

test/MyTested.AspNetCore.Mvc.Core.Test/BuildersTests/ActionResultsTests/BadRequestTests/BadRequestTestBuilderTests.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public void ContainingOutputFormattersShouldNotThrowExceptionWithCorrectParamete
446446
.Calling(c => c.FullHttpBadRequestAction())
447447
.ShouldReturn()
448448
.BadRequest()
449-
.ContainingOutputFormatters(new CustomOutputFormatter());
449+
.ContainingOutputFormatters(TestObjectFactory.GetOutputFormatter(), new CustomOutputFormatter());
450450
}
451451

452452
[Fact]
@@ -462,11 +462,11 @@ public void ContainingOutputFormattersShouldThrowExceptionWithIncorrectValue()
462462
.BadRequest()
463463
.ContainingOutputFormatters(new List<IOutputFormatter>
464464
{
465-
TestObjectFactory.GetOutputFormatter(),
466-
new CustomOutputFormatter()
465+
new CustomOutputFormatter(),
466+
new StringOutputFormatter()
467467
});
468468
},
469-
"When calling FullHttpBadRequestAction action in MvcController expected bad request result output formatters to contain formatter of HttpNotAcceptableOutputFormatter type, but none was found.");
469+
"When calling FullHttpBadRequestAction action in MvcController expected bad request result output formatters to contain formatter of StringOutputFormatter type, but none was found.");
470470
}
471471

472472
[Fact]
@@ -482,7 +482,6 @@ public void ContainingOutputFormattersShouldThrowExceptionWithIncorrectCount()
482482
.BadRequest()
483483
.ContainingOutputFormatters(new List<IOutputFormatter>
484484
{
485-
TestObjectFactory.GetOutputFormatter(),
486485
new CustomOutputFormatter()
487486
});
488487
},
@@ -520,7 +519,7 @@ public void AndAlsoShouldWorkCorrectly()
520519
.BadRequest()
521520
.WithStatusCode(201)
522521
.AndAlso()
523-
.ContainingOutputFormatters(TestObjectFactory.GetOutputFormatter());
522+
.ContainingOutputFormatters(TestObjectFactory.GetOutputFormatter(), new CustomOutputFormatter());
524523
}
525524

526525
[Fact]

test/MyTested.AspNetCore.Mvc.Test/Setups/Routes/RouteController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public IActionResult Index()
1111
return this.View();
1212
}
1313

14-
[HttpGet("[action]/{id}")]
14+
[HttpGet("[action]")]
1515
public IActionResult Action(int id)
1616
{
1717
return this.View();

0 commit comments

Comments
 (0)