Update usage of TestSink

This commit is contained in:
John Luo 2018-04-12 18:19:09 -07:00
parent e6be423c33
commit c35030267c
7 changed files with 28 additions and 30 deletions

View File

@ -45,8 +45,8 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
// Assert // Assert
Assert.Empty(sink.Scopes); Assert.Empty(sink.Scopes);
Assert.Single(sink.Writes); var write = Assert.Single(sink.Writes);
Assert.Equal(expectedMessage, sink.Writes[0].State?.ToString()); Assert.Equal(expectedMessage, write.State?.ToString());
} }
private MvcRouteHandler CreateMvcRouteHandler( private MvcRouteHandler CreateMvcRouteHandler(

View File

@ -301,8 +301,8 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
// Assert // Assert
Assert.Empty(sink.Scopes); Assert.Empty(sink.Scopes);
Assert.Single(sink.Writes); var write = Assert.Single(sink.Writes);
Assert.Equal(expectedMessage, sink.Writes[0].State?.ToString()); Assert.Equal(expectedMessage, write.State?.ToString());
} }
[Fact] [Fact]
@ -770,7 +770,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
{ {
new DefaultActionConstraintProvider(), new DefaultActionConstraintProvider(),
}; };
var actionSelector = new ActionSelector( var actionSelector = new ActionSelector(
actionDescriptorCollectionProvider, actionDescriptorCollectionProvider,
GetActionConstraintCache(actionConstraintProviders), GetActionConstraintCache(actionConstraintProviders),

View File

@ -91,8 +91,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
logger.AuthorizationFiltersExecutionPlan(filters); logger.AuthorizationFiltersExecutionPlan(filters);
// Assert // Assert
Assert.Single(testSink.Writes); var write = Assert.Single(testSink.Writes);
var write = testSink.Writes[0];
Assert.Equal( Assert.Equal(
"Execution plan of authorization filters (in the following order): " + "Execution plan of authorization filters (in the following order): " +
$"{authFilter.GetType()}, {asyncAuthFilter.GetType()}, {orderedAuthFilter.GetType()} (Order: -100)", $"{authFilter.GetType()}, {asyncAuthFilter.GetType()}, {orderedAuthFilter.GetType()} (Order: -100)",
@ -138,8 +137,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
logger.ResourceFiltersExecutionPlan(filters); logger.ResourceFiltersExecutionPlan(filters);
// Assert // Assert
Assert.Single(testSink.Writes); var write = Assert.Single(testSink.Writes);
var write = testSink.Writes[0];
Assert.Equal( Assert.Equal(
"Execution plan of resource filters (in the following order): " + "Execution plan of resource filters (in the following order): " +
$"{resourceFilter.GetType()}, {asyncResourceFilter.GetType()}, {orderedResourceFilter.GetType()} (Order: -100)", $"{resourceFilter.GetType()}, {asyncResourceFilter.GetType()}, {orderedResourceFilter.GetType()} (Order: -100)",
@ -185,8 +183,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
logger.ActionFiltersExecutionPlan(filters); logger.ActionFiltersExecutionPlan(filters);
// Assert // Assert
Assert.Single(testSink.Writes); var write = Assert.Single(testSink.Writes);
var write = testSink.Writes[0];
Assert.Equal( Assert.Equal(
"Execution plan of action filters (in the following order): " + "Execution plan of action filters (in the following order): " +
$"{actionFilter.GetType()}, {asyncActionFilter.GetType()}, {orderedActionFilter.GetType()} (Order: -100)", $"{actionFilter.GetType()}, {asyncActionFilter.GetType()}, {orderedActionFilter.GetType()} (Order: -100)",
@ -232,8 +229,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
logger.ExceptionFiltersExecutionPlan(filters); logger.ExceptionFiltersExecutionPlan(filters);
// Assert // Assert
Assert.Single(testSink.Writes); var write = Assert.Single(testSink.Writes);
var write = testSink.Writes[0];
Assert.Equal( Assert.Equal(
"Execution plan of exception filters (in the following order): " + "Execution plan of exception filters (in the following order): " +
$"{exceptionFilter.GetType()}, {asyncExceptionFilter.GetType()}, {orderedExceptionFilter.GetType()} (Order: -100)", $"{exceptionFilter.GetType()}, {asyncExceptionFilter.GetType()}, {orderedExceptionFilter.GetType()} (Order: -100)",
@ -279,8 +275,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
logger.ResultFiltersExecutionPlan(filters); logger.ResultFiltersExecutionPlan(filters);
// Assert // Assert
Assert.Single(testSink.Writes); var write = Assert.Single(testSink.Writes);
var write = testSink.Writes[0];
Assert.Equal( Assert.Equal(
"Execution plan of result filters (in the following order): " + "Execution plan of result filters (in the following order): " +
$"{resultFilter.GetType()}, {asyncResultFilter.GetType()}, {orderedResultFilter.GetType()} (Order: -100)", $"{resultFilter.GetType()}, {asyncResultFilter.GetType()}, {orderedResultFilter.GetType()} (Order: -100)",

View File

@ -647,10 +647,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
// Act // Act
await binder.BindModelAsync(bindingContext); await binder.BindModelAsync(bindingContext);
var writeList = sink.Writes.ToList();
// Assert // Assert
Assert.Equal($"Attempting to bind model of type '{typeof(Person)}' using the name 'someName' in request data ...", sink.Writes[0].State.ToString()); Assert.Equal($"Attempting to bind model of type '{typeof(Person)}' using the name 'someName' in request data ...", writeList[0].State.ToString());
Assert.Equal($"Rejected input formatter '{typeof(TestInputFormatter)}' for content type 'application/json'.", sink.Writes[1].State.ToString()); Assert.Equal($"Rejected input formatter '{typeof(TestInputFormatter)}' for content type 'application/json'.", writeList[1].State.ToString());
Assert.Equal($"Selected input formatter '{typeof(TestInputFormatter)}' for content type 'application/json'.", sink.Writes[2].State.ToString()); Assert.Equal($"Selected input formatter '{typeof(TestInputFormatter)}' for content type 'application/json'.", writeList[2].State.ToString());
} }
[Fact] [Fact]

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Globalization; using System.Globalization;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
@ -193,7 +194,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
// Assert // Assert
Assert.Equal(ModelBindingResult.Failed(), bindingContext.Result); Assert.Equal(ModelBindingResult.Failed(), bindingContext.Result);
Assert.Empty(bindingContext.ModelState); Assert.Empty(bindingContext.ModelState);
Assert.Equal(2, sink.Writes.Count); Assert.Equal(2, sink.Writes.Count());
} }
[Theory] [Theory]
@ -283,7 +284,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
Assert.True(bindingContext.Result.IsModelSet); Assert.True(bindingContext.Result.IsModelSet);
Assert.Equal(42, bindingContext.Result.Model); Assert.Equal(42, bindingContext.Result.Model);
Assert.True(bindingContext.ModelState.ContainsKey("theModelName")); Assert.True(bindingContext.ModelState.ContainsKey("theModelName"));
Assert.Equal(2, sink.Writes.Count); Assert.Equal(2, sink.Writes.Count());
} }
public static TheoryData<Type> BiggerNumericTypes public static TheoryData<Type> BiggerNumericTypes

View File

@ -410,7 +410,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
Assert.Equal(expectedKey, modelState.Key); Assert.Equal(expectedKey, modelState.Key);
var error = Assert.Single(modelState.Value.Errors); var error = Assert.Single(modelState.Value.Errors);
Assert.Equal(attribute.FormatErrorMessage(expectedFieldName), error.ErrorMessage); Assert.Equal(attribute.FormatErrorMessage(expectedFieldName), error.ErrorMessage);
Assert.Equal(4, sink.Writes.Count); Assert.Equal(4, sink.Writes.Count());
} }
[Fact] [Fact]

View File

@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.TagHelpers
[Fact] [Fact]
public void Init_InvokesComponentsInitInCorrectOrder() public void Init_InvokesComponentsInitInCorrectOrder()
{ {
// Arrange // Arrange
var tagHelperContext = new TagHelperContext( var tagHelperContext = new TagHelperContext(
"head", "head",
allAttributes: new TagHelperAttributeList( allAttributes: new TagHelperAttributeList(
@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.TagHelpers
[Fact] [Fact]
public async void ProcessAsync_InvokesComponentsProcessAsyncInCorrectOrder() public async void ProcessAsync_InvokesComponentsProcessAsyncInCorrectOrder()
{ {
// Arrange // Arrange
var tagHelperContext = new TagHelperContext( var tagHelperContext = new TagHelperContext(
"head", "head",
allAttributes: new TagHelperAttributeList( allAttributes: new TagHelperAttributeList(
@ -128,7 +128,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.TagHelpers
[Fact] [Fact]
public void Init_InvokesTagHelperComponentInit() public void Init_InvokesTagHelperComponentInit()
{ {
// Arrange // Arrange
var tagHelperContext = new TagHelperContext( var tagHelperContext = new TagHelperContext(
"head", "head",
allAttributes: new TagHelperAttributeList( allAttributes: new TagHelperAttributeList(
@ -183,7 +183,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.TagHelpers
// Act // Act
await testTagHelperComponentTagHelper.ProcessAsync(tagHelperContext, output); await testTagHelperComponentTagHelper.ProcessAsync(tagHelperContext, output);
// Assert // Assert
Assert.Equal("Processed1", output.PostContent.GetContent()); Assert.Equal("Processed1", output.PostContent.GetContent());
} }
@ -216,7 +216,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.TagHelpers
// Act // Act
await testTagHelperComponentTagHelper.ProcessAsync(tagHelperContext, output); await testTagHelperComponentTagHelper.ProcessAsync(tagHelperContext, output);
// Assert // Assert
Assert.Equal("Processed0Processed1Processed2", output.PostContent.GetContent()); Assert.Equal("Processed0Processed1Processed2", output.PostContent.GetContent());
} }
@ -250,7 +250,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.TagHelpers
testTagHelperComponentTagHelper.Init(tagHelperContext); testTagHelperComponentTagHelper.Init(tagHelperContext);
// Assert // Assert
Assert.Equal($"Tag helper component '{typeof(TestTagHelperComponent)}' initialized.", sink.Writes[0].State.ToString(), StringComparer.Ordinal); Assert.Equal($"Tag helper component '{typeof(TestTagHelperComponent)}' initialized.", sink.Writes.First().State.ToString(), StringComparer.Ordinal);
} }
[Fact] [Fact]
@ -282,14 +282,14 @@ namespace Microsoft.AspNetCore.Mvc.Razor.TagHelpers
// Act // Act
await testTagHelperComponentTagHelper.ProcessAsync(tagHelperContext, output); await testTagHelperComponentTagHelper.ProcessAsync(tagHelperContext, output);
// Assert // Assert
Assert.Equal($"Tag helper component '{typeof(TestTagHelperComponent)}' processed.", sink.Writes[0].State.ToString(), StringComparer.Ordinal); Assert.Equal($"Tag helper component '{typeof(TestTagHelperComponent)}' processed.", sink.Writes.First().State.ToString(), StringComparer.Ordinal);
} }
[Fact] [Fact]
public void Init_GetsTagHelperComponentPropertyActivator_FromRequestServices() public void Init_GetsTagHelperComponentPropertyActivator_FromRequestServices()
{ {
// Arrange // Arrange
var tagHelperContext = new TagHelperContext( var tagHelperContext = new TagHelperContext(
"head", "head",
allAttributes: new TagHelperAttributeList( allAttributes: new TagHelperAttributeList(