From 3a710c3d64557a97bae248446987d357711fffc4 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Thu, 17 Aug 2017 10:45:03 -0700 Subject: [PATCH] Upgrade to xunit 2.3.0-beta4 --- Mvc.sln | 1 + build/dependencies.props | 5 +-- test/Directory.Build.props | 2 ++ test/Directory.Build.targets | 1 + .../ModelBinding/ModelStateDictionaryTest.cs | 34 +++++++++---------- .../Authorization/AuthorizeFilterTest.cs | 2 +- .../BadRequestObjectResultTests.cs | 2 +- .../ControllerBaseTest.cs | 2 +- .../FileResultTest.cs | 2 +- .../Formatters/FormatFilterTest.cs | 10 +++--- .../Formatters/FormatterCollectionTest.cs | 4 +-- .../Formatters/MediaTypeTest.cs | 4 +-- .../Formatters/TextInputFormatterTest.cs | 2 +- ...ControllerActionDescriptorProviderTests.cs | 2 +- .../Internal/ControllerActionInvokerTest.cs | 6 ++-- .../ControllerBinderDelegateProviderTest.cs | 2 +- .../Internal/DefaultObjectValidatorTests.cs | 3 +- .../Binders/ComplexTypeModelBinderTest.cs | 2 +- .../DefaultModelMetadataProviderTest.cs | 2 +- .../ModelBinding/ModelBindingHelperTest.cs | 28 +++++++-------- .../ProducesAttributeTests.cs | 4 +-- .../SerializableErrorTests.cs | 2 +- .../CorsApplicationModelProviderTest.cs | 2 +- .../Internal/EnumerableWrapperProviderTest.cs | 2 +- .../Internal/SerializableErrorWrapperTests.cs | 2 +- ...ataContractSerializerInputFormatterTest.cs | 24 ++++++------- ...taContractSerializerOutputFormatterTest.cs | 6 ++-- .../XmlSerializerInputFormatterTest.cs | 20 +++++------ .../BasicTests.cs | 4 +-- .../WebApiCompatShimBasicTest.cs | 4 +-- .../ActionParametersIntegrationTest.cs | 12 +++---- ...ellationTokenModelBinderIntegrationTest.cs | 12 +++++-- .../GenericModelBinderIntegrationTest.cs | 4 +-- .../ModelBindingTestHelper.cs | 20 ++++++++--- .../ServicesModelBinderIntegrationTest.cs | 4 +-- .../SimpleTypeModelBinderIntegrationTest.cs | 10 +++--- .../TryUpdateModelIntegrationTest.cs | 28 +++++++-------- .../HtmlLocalizerTest.cs | 2 +- .../ViewLocalizerTest.cs | 2 +- .../RazorViewEngineTest.cs | 2 +- .../JsonPatchExtensionsTest.cs | 2 +- .../HtmlAttributePropertyHelperTest.cs | 6 ++-- .../DefaultViewComponentHelperTest.cs | 14 ++++---- .../ViewFeatures/ModelExplorerTest.cs | 2 +- .../ApiControllerActionDiscoveryTest.cs | 4 +-- test/MvcTests.ruleset | 9 +++++ 46 files changed, 172 insertions(+), 147 deletions(-) create mode 100644 test/MvcTests.ruleset diff --git a/Mvc.sln b/Mvc.sln index 92a04cd37c..f6a565c1a7 100644 --- a/Mvc.sln +++ b/Mvc.sln @@ -13,6 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{3BA657BF-2 ProjectSection(SolutionItems) = preProject test\Directory.Build.props = test\Directory.Build.props test\Directory.Build.targets = test\Directory.Build.targets + test\MvcTests.ruleset = test\MvcTests.ruleset EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc", "src\Microsoft.AspNetCore.Mvc\Microsoft.AspNetCore.Mvc.csproj", "{079EFA1F-0B0A-4853-B27B-5780D111CD85}" diff --git a/build/dependencies.props b/build/dependencies.props index 13696ffdb4..9db4a00489 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -14,8 +14,9 @@ 2.0.0-* 2.3.1 2.0.0-* - 15.3.0-* + 15.3.0 5.2.2 - 2.3.0-beta2-* + 2.3.0-beta4-build3742 + 0.6.1 diff --git a/test/Directory.Build.props b/test/Directory.Build.props index 3d7bd86234..ec72533796 100644 --- a/test/Directory.Build.props +++ b/test/Directory.Build.props @@ -3,5 +3,7 @@ false + xUnit1026:$(WarningsNotAsErrors) + $(MSBuildThisFileDirectory)MvcTests.ruleset diff --git a/test/Directory.Build.targets b/test/Directory.Build.targets index f6198dfe39..5c49d2f8a3 100644 --- a/test/Directory.Build.targets +++ b/test/Directory.Build.targets @@ -9,6 +9,7 @@ + diff --git a/test/Microsoft.AspNetCore.Mvc.Abstractions.Test/ModelBinding/ModelStateDictionaryTest.cs b/test/Microsoft.AspNetCore.Mvc.Abstractions.Test/ModelBinding/ModelStateDictionaryTest.cs index dd69d69f1c..90abb75dd2 100644 --- a/test/Microsoft.AspNetCore.Mvc.Abstractions.Test/ModelBinding/ModelStateDictionaryTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Abstractions.Test/ModelBinding/ModelStateDictionaryTest.cs @@ -1037,13 +1037,13 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding dictionary.ClearValidationState("Property4"); // Assert - Assert.Equal(0, dictionary["Property1"].Errors.Count); + Assert.Empty(dictionary["Property1"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["Property1"].ValidationState); - Assert.Equal(0, dictionary["Property2"].Errors.Count); + Assert.Empty(dictionary["Property2"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["Property2"].ValidationState); - Assert.Equal(1, dictionary["Property3"].Errors.Count); + Assert.Single(dictionary["Property3"].Errors); Assert.Equal(ModelValidationState.Invalid, dictionary["Property3"].ValidationState); - Assert.Equal(0, dictionary["Property4"].Errors.Count); + Assert.Empty(dictionary["Property4"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["Property4"].ValidationState); } @@ -1064,19 +1064,19 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding dictionary.ClearValidationState("Product"); // Assert - Assert.Equal(0, dictionary["Product"].Errors.Count); + Assert.Empty(dictionary["Product"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product"].ValidationState); - Assert.Equal(0, dictionary["Product.Detail1"].Errors.Count); + Assert.Empty(dictionary["Product.Detail1"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail1"].ValidationState); - Assert.Equal(0, dictionary["Product.Detail2[0]"].Errors.Count); + Assert.Empty(dictionary["Product.Detail2[0]"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail2[0]"].ValidationState); - Assert.Equal(0, dictionary["Product.Detail2[1]"].Errors.Count); + Assert.Empty(dictionary["Product.Detail2[1]"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail2[1]"].ValidationState); - Assert.Equal(0, dictionary["Product.Detail2[2]"].Errors.Count); + Assert.Empty(dictionary["Product.Detail2[2]"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail2[2]"].ValidationState); - Assert.Equal(0, dictionary["Product.Detail3"].Errors.Count); + Assert.Empty(dictionary["Product.Detail3"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail3"].ValidationState); - Assert.Equal(1, dictionary["ProductName"].Errors.Count); + Assert.Single(dictionary["ProductName"].Errors); Assert.Equal(ModelValidationState.Invalid, dictionary["ProductName"].ValidationState); } @@ -1095,9 +1095,9 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding // Assert Assert.Equal(ModelValidationState.Valid, dictionary["Product"].ValidationState); - Assert.Equal(0, dictionary["Product.Detail1"].Errors.Count); + Assert.Empty(dictionary["Product.Detail1"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail1"].ValidationState); - Assert.Equal(0, dictionary["Product.Detail1.Name"].Errors.Count); + Assert.Empty(dictionary["Product.Detail1.Name"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail1.Name"].ValidationState); Assert.Equal(ModelValidationState.Skipped, dictionary["Product.Detail1Name"].ValidationState); } @@ -1118,13 +1118,13 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding dictionary.ClearValidationState(modelKey); // Assert - Assert.Equal(0, dictionary["Property1"].Errors.Count); + Assert.Empty(dictionary["Property1"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["Property1"].ValidationState); - Assert.Equal(0, dictionary["Property2"].Errors.Count); + Assert.Empty(dictionary["Property2"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["Property2"].ValidationState); - Assert.Equal(0, dictionary["Property3"].Errors.Count); + Assert.Empty(dictionary["Property3"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["Property3"].ValidationState); - Assert.Equal(0, dictionary["Property4"].Errors.Count); + Assert.Empty(dictionary["Property4"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["Property4"].ValidationState); } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/Authorization/AuthorizeFilterTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/Authorization/AuthorizeFilterTest.cs index f1979a60ea..3429bad91e 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/Authorization/AuthorizeFilterTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/Authorization/AuthorizeFilterTest.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Mvc.Authorization public void InvalidUser() { var authorizationContext = GetAuthorizationContext(); - Assert.True(authorizationContext.HttpContext.User.Identities.Any(i => i.IsAuthenticated)); + Assert.Contains(authorizationContext.HttpContext.User.Identities, i => i.IsAuthenticated); } [Fact] diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/BadRequestObjectResultTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/BadRequestObjectResultTests.cs index 153cfc27d0..453575e5bf 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/BadRequestObjectResultTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/BadRequestObjectResultTests.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Mvc // Assert Assert.Equal(StatusCodes.Status400BadRequest, badRequestObjecResult.StatusCode); var errors = Assert.IsType(badRequestObjecResult.Value); - Assert.Equal(0, errors.Count); + Assert.Empty(errors); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ControllerBaseTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ControllerBaseTest.cs index 11a35576cf..b2b9e5c339 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ControllerBaseTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ControllerBaseTest.cs @@ -1987,7 +1987,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test Assert.IsType(result); Assert.Equal(StatusCodes.Status400BadRequest, result.StatusCode); var errors = Assert.IsType(result.Value); - Assert.Equal(0, errors.Count); + Assert.Empty(errors); } [Theory] diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/FileResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/FileResultTest.cs index 55c86fd3cc..a16d207956 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/FileResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/FileResultTest.cs @@ -153,7 +153,7 @@ namespace Microsoft.AspNetCore.Mvc await result.ExecuteResultAsync(actionContext); // Assert - Assert.Equal(1, loggerSink.Writes.Count); + Assert.Single(loggerSink.Writes); } public static TheoryData ContentDispositionData diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/FormatFilterTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/FormatFilterTest.cs index ee1268d2fd..be2a8d01a3 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/FormatFilterTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/FormatFilterTest.cs @@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters // Assert var objectResult = Assert.IsType(resultExecutingContext.Result); - Assert.Equal(1, objectResult.ContentTypes.Count); + Assert.Single(objectResult.ContentTypes); MediaTypeAssert.Equal(mediaType, objectResult.ContentTypes[0]); } @@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters // Assert var objectResult = Assert.IsType(resultExecutingContext.Result); - Assert.Equal(1, objectResult.ContentTypes.Count); + Assert.Single(objectResult.ContentTypes); MediaTypeAssert.Equal(mediaType, objectResult.ContentTypes[0]); } @@ -132,7 +132,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters // Assert var objectResult = Assert.IsType(resultExecutingContext.Result); - Assert.Equal(1, objectResult.ContentTypes.Count); + Assert.Single(objectResult.ContentTypes); MediaTypeAssert.Equal(mediaType, objectResult.ContentTypes[0]); } @@ -336,7 +336,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters // Assert var result = Assert.IsType(resultExecutingContext.Result); - Assert.Equal(1, result.ContentTypes.Count); + Assert.Single(result.ContentTypes); MediaTypeAssert.Equal(mediaType, result.ContentTypes[0]); } @@ -371,7 +371,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters // Assert var result = Assert.IsType(resultExecutingContext.Result); - Assert.Equal(0, result.ContentTypes.Count); + Assert.Empty(result.ContentTypes); } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/FormatterCollectionTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/FormatterCollectionTest.cs index 79922d1d62..81b532a3ad 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/FormatterCollectionTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/FormatterCollectionTest.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters // Assert var formatter = Assert.Single(collection); - Assert.IsType(typeof(AnotherTestOutputFormatter), formatter); + Assert.IsType(formatter); } [Fact] @@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters // Assert var formatter = Assert.Single(collection); - Assert.IsType(typeof(AnotherTestOutputFormatter), formatter); + Assert.IsType(formatter); } private class TestOutputFormatter : TextOutputFormatter diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/MediaTypeTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/MediaTypeTest.cs index 1b6524085c..28591cf017 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/MediaTypeTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/MediaTypeTest.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters Assert.Equal(new StringSegment("json"), result.SubType); } - public static IEnumerable MediaTypesWithSuffixes + public static IEnumerable MediaTypesWithSuffixes { get { @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters } [Theory] - [MemberData(nameof (MediaTypesWithSuffixes))] + [MemberData(nameof(MediaTypesWithSuffixes))] public void Constructor_CanParseSuffixedMediaTypes( string mediaType, string expectedSubTypeWithoutSuffix, diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/TextInputFormatterTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/TextInputFormatterTest.cs index d3e0b4bd0f..5191a25c33 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/TextInputFormatterTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/TextInputFormatterTest.cs @@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters // Assert Assert.True(result.HasError); Assert.True(context.ModelState.ContainsKey("something")); - Assert.Equal(1, context.ModelState["something"].Errors.Count); + Assert.Single(context.ModelState["something"].Errors); var error = context.ModelState["something"].Errors[0]; Assert.IsType(error.Exception); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerActionDescriptorProviderTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerActionDescriptorProviderTests.cs index 139b9e4fe8..bc317f4983 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerActionDescriptorProviderTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerActionDescriptorProviderTests.cs @@ -1337,7 +1337,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var actions = provider.GetDescriptors().Where(a => a.ActionName == actionName); // Assert - Assert.Equal(1, actions.Count()); + Assert.Single(actions); var action = Assert.Single(actions, a => a.AttributeRouteInfo.Template == "A2"); Assert.Equal(2, action.ActionConstraints.Count); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerActionInvokerTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerActionInvokerTest.cs index fdc3002df2..b2a007797a 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerActionInvokerTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerActionInvokerTest.cs @@ -1103,7 +1103,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal await invoker.InvokeAsync(); // Assert - Assert.IsType(typeof(EmptyResult), result); + Assert.IsType(result); } [Fact] @@ -1131,8 +1131,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal await invoker.InvokeAsync(); // Assert - Assert.IsType(typeof(ObjectResult), result); - Assert.IsType(typeof(int), ((ObjectResult)result).Value); + Assert.IsType(result); + Assert.IsType(((ObjectResult)result).Value); Assert.Equal(1, ((ObjectResult)result).Value); } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerBinderDelegateProviderTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerBinderDelegateProviderTest.cs index e28222d178..cc34fcfeb5 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerBinderDelegateProviderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerBinderDelegateProviderTest.cs @@ -139,7 +139,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal await binderDelegate(controllerContext, controller, arguments); // Assert - Assert.Equal(1, arguments.Count); + Assert.Single(arguments); Assert.Equal(value, arguments["foo"]); } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/DefaultObjectValidatorTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/DefaultObjectValidatorTests.cs index d1aae93d21..e6caec6464 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/DefaultObjectValidatorTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/DefaultObjectValidatorTests.cs @@ -1076,8 +1076,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var model = new ThrowingProperty(); // Act & Assert - Assert.Throws( - typeof(InvalidTimeZoneException), + Assert.Throws( () => { validator.Validate(actionContext, validationState, string.Empty, model); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ComplexTypeModelBinderTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ComplexTypeModelBinderTest.cs index 4b8e1a7cae..43300f7dbf 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ComplexTypeModelBinderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ComplexTypeModelBinderTest.cs @@ -1024,7 +1024,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders // Assert Assert.False(bindingContext.ModelState.IsValid); - Assert.Equal(1, bindingContext.ModelState["foo.NameNoAttribute"].Errors.Count); + Assert.Single(bindingContext.ModelState["foo.NameNoAttribute"].Errors); Assert.Equal("This is a different exception." + Environment.NewLine + "Parameter name: value", bindingContext.ModelState["foo.NameNoAttribute"].Errors[0].Exception.Message); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Metadata/DefaultModelMetadataProviderTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Metadata/DefaultModelMetadataProviderTest.cs index 286b589487..7c0215b4f6 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Metadata/DefaultModelMetadataProviderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Metadata/DefaultModelMetadataProviderTest.cs @@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata var metadata = provider.GetMetadataForProperties(typeof(ModelTypeWithIndexer)).ToArray(); // Assert - Assert.Equal(1, metadata.Length); + Assert.Single(metadata); Assert.Single(metadata, m => m.PropertyName == "Property1"); } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/ModelBindingHelperTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/ModelBindingHelperTest.cs index d2354d1390..39b30f421a 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/ModelBindingHelperTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/ModelBindingHelperTest.cs @@ -652,14 +652,14 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding ModelBindingHelper.ClearValidationStateForModel(modelMetadata, dictionary, modelKey); // Assert - Assert.Equal(0, dictionary["Name"].Errors.Count); + Assert.Empty(dictionary["Name"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["Name"].ValidationState); - Assert.Equal(0, dictionary["Id"].Errors.Count); + Assert.Empty(dictionary["Id"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["Id"].ValidationState); - Assert.Equal(0, dictionary["Category"].Errors.Count); + Assert.Empty(dictionary["Category"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["Category"].ValidationState); - Assert.Equal(1, dictionary["Unrelated"].Errors.Count); + Assert.Single(dictionary["Unrelated"].Errors); Assert.Equal(ModelValidationState.Invalid, dictionary["Unrelated"].ValidationState); } @@ -681,10 +681,10 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding ModelBindingHelper.ClearValidationStateForModel(modelMetadata, dictionary, modelKey); // Assert - Assert.Equal(0, dictionary[string.Empty].Errors.Count); + Assert.Empty(dictionary[string.Empty].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary[string.Empty].ValidationState); - Assert.Equal(1, dictionary["Unrelated"].Errors.Count); + Assert.Single(dictionary["Unrelated"].Errors); Assert.Equal(ModelValidationState.Invalid, dictionary["Unrelated"].ValidationState); } @@ -712,20 +712,20 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding ModelBindingHelper.ClearValidationStateForModel(modelMetadata, dictionary, modelKey); // Assert - Assert.Equal(0, dictionary["[0].Name"].Errors.Count); + Assert.Empty(dictionary["[0].Name"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["[0].Name"].ValidationState); - Assert.Equal(0, dictionary["[0].Id"].Errors.Count); + Assert.Empty(dictionary["[0].Id"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["[0].Id"].ValidationState); - Assert.Equal(0, dictionary["[0].Category"].Errors.Count); + Assert.Empty(dictionary["[0].Category"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["[0].Category"].ValidationState); - Assert.Equal(0, dictionary["[1].Name"].Errors.Count); + Assert.Empty(dictionary["[1].Name"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["[1].Name"].ValidationState); - Assert.Equal(0, dictionary["[1].Id"].Errors.Count); + Assert.Empty(dictionary["[1].Id"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["[1].Id"].ValidationState); - Assert.Equal(0, dictionary["[1].Category"].Errors.Count); + Assert.Empty(dictionary["[1].Category"].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary["[1].Category"].ValidationState); - Assert.Equal(1, dictionary["Unrelated"].Errors.Count); + Assert.Single(dictionary["Unrelated"].Errors); Assert.Equal(ModelValidationState.Invalid, dictionary["Unrelated"].ValidationState); } @@ -761,7 +761,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding { if (entry.StartsWith(prefix)) { - Assert.Equal(0, dictionary[entry].Errors.Count); + Assert.Empty(dictionary[entry].Errors); Assert.Equal(ModelValidationState.Unvalidated, dictionary[entry].ValidationState); } } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ProducesAttributeTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ProducesAttributeTests.cs index 3488442798..49084a2c91 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ProducesAttributeTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ProducesAttributeTests.cs @@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Mvc.Test // Assert var objectResult = Assert.IsType(resultExecutingContext.Result); - Assert.Equal(1, objectResult.ContentTypes.Count); + Assert.Single(objectResult.ContentTypes); } [Fact] @@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Mvc.Test // Assert var objectResult = Assert.IsType(resultExecutingContext.Result); - Assert.Equal(0, objectResult.ContentTypes.Count); + Assert.Empty(objectResult.ContentTypes); } [Theory] diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/SerializableErrorTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/SerializableErrorTests.cs index 8f8e272304..24a397b882 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/SerializableErrorTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/SerializableErrorTests.cs @@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.Mvc var serializableError = new SerializableError(modelState); // Assert - Assert.Equal(0, serializableError.Count); + Assert.Empty(serializableError); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Cors.Test/Internal/CorsApplicationModelProviderTest.cs b/test/Microsoft.AspNetCore.Mvc.Cors.Test/Internal/CorsApplicationModelProviderTest.cs index 3ecea8b091..1b7ce68776 100644 --- a/test/Microsoft.AspNetCore.Mvc.Cors.Test/Internal/CorsApplicationModelProviderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Cors.Test/Internal/CorsApplicationModelProviderTest.cs @@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.Mvc.Cors.Internal // Assert var controller = Assert.Single(context.Result.Controllers); var action = Assert.Single(controller.Actions); - Assert.True(action.Filters.Any(f => f is DisableCorsAuthorizationFilter)); + Assert.Contains(action.Filters, f => f is DisableCorsAuthorizationFilter); var selector = Assert.Single(action.Selectors); var constraint = Assert.Single(selector.ActionConstraints, c => c is HttpMethodActionConstraint); Assert.IsType(constraint); diff --git a/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/Internal/EnumerableWrapperProviderTest.cs b/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/Internal/EnumerableWrapperProviderTest.cs index 0b594890c6..59ac66a273 100644 --- a/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/Internal/EnumerableWrapperProviderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/Internal/EnumerableWrapperProviderTest.cs @@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml.Internal Assert.NotNull(wrapped); var delegatingEnumerable = wrapped as DelegatingEnumerable; Assert.NotNull(delegatingEnumerable); - Assert.Equal(0, delegatingEnumerable.Count()); + Assert.Empty(delegatingEnumerable); } [Fact] diff --git a/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/Internal/SerializableErrorWrapperTests.cs b/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/Internal/SerializableErrorWrapperTests.cs index faaa011c58..2a6cfaf47d 100644 --- a/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/Internal/SerializableErrorWrapperTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/Internal/SerializableErrorWrapperTests.cs @@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml.Internal // Assert Assert.NotNull(wrapper.SerializableError); Assert.Same(serializableError, wrapper.SerializableError); - Assert.Equal(1, wrapper.SerializableError.Count); + Assert.Single(wrapper.SerializableError); Assert.True(wrapper.SerializableError.ContainsKey("key1")); Assert.Equal("key1-error", wrapper.SerializableError["key1"]); } diff --git a/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/XmlDataContractSerializerInputFormatterTest.cs b/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/XmlDataContractSerializerInputFormatterTest.cs index 7e88c163cb..4cc8f27279 100644 --- a/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/XmlDataContractSerializerInputFormatterTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/XmlDataContractSerializerInputFormatterTest.cs @@ -117,12 +117,10 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml var formatter = new XmlDataContractSerializerInputFormatter(); // Assert - Assert.True(formatter.SupportedMediaTypes - .Select(content => content.ToString()) - .Contains("application/xml")); - Assert.True(formatter.SupportedMediaTypes - .Select(content => content.ToString()) - .Contains("text/xml")); + Assert.Contains("application/xml", formatter.SupportedMediaTypes + .Select(content => content.ToString())); + Assert.Contains("text/xml", formatter.SupportedMediaTypes + .Select(content => content.ToString())); } [Fact] @@ -132,8 +130,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml var formatter = new XmlDataContractSerializerInputFormatter(); // Assert - Assert.True(formatter.SupportedEncodings.Any(i => i.WebName == "utf-8")); - Assert.True(formatter.SupportedEncodings.Any(i => i.WebName == "utf-16")); + Assert.Contains(formatter.SupportedEncodings, i => i.WebName == "utf-8"); + Assert.Contains(formatter.SupportedEncodings, i => i.WebName == "utf-16"); } [Fact] @@ -309,7 +307,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml var context = GetInputFormatterContext(contentBytes, typeof(TestLevelTwo)); // Act & Assert - await Assert.ThrowsAsync(typeof(SerializationException), async () => await formatter.ReadAsync(context)); + await Assert.ThrowsAsync(async () => await formatter.ReadAsync(context)); } [Fact] @@ -326,7 +324,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml var context = GetInputFormatterContext(contentBytes, typeof(TestLevelTwo)); // Act & Assert - await Assert.ThrowsAsync(typeof(SerializationException), async () => await formatter.ReadAsync(context)); + await Assert.ThrowsAsync(async () => await formatter.ReadAsync(context)); } [Fact] @@ -336,7 +334,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml var formatter = new XmlDataContractSerializerInputFormatter(); // Act & Assert - Assert.Throws(typeof(ArgumentException), () => formatter.MaxDepth = 0); + Assert.Throws(() => formatter.MaxDepth = 0); } [Fact] @@ -498,7 +496,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml var context = GetInputFormatterContext(contentBytes, typeof(DummyClass)); // Act & Assert - await Assert.ThrowsAsync(typeof(SerializationException), async () => await formatter.ReadAsync(context)); + await Assert.ThrowsAsync(async () => await formatter.ReadAsync(context)); } [Fact] @@ -555,7 +553,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml var context = GetInputFormatterContext(contentBytes, typeof(DummyClass)); // Act & Assert - await Assert.ThrowsAsync(typeof(SerializationException), async () => await formatter.ReadAsync(context)); + await Assert.ThrowsAsync(async () => await formatter.ReadAsync(context)); } [Fact] diff --git a/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/XmlDataContractSerializerOutputFormatterTest.cs b/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/XmlDataContractSerializerOutputFormatterTest.cs index e5b06fdfed..1fb1d6f6de 100644 --- a/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/XmlDataContractSerializerOutputFormatterTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/XmlDataContractSerializerOutputFormatterTest.cs @@ -471,8 +471,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml var outputFormatterContext = GetOutputFormatterContext(sampleInput, typeof(DummyClass)); // Act & Assert - await Assert.ThrowsAsync(typeof(SerializationException), - async () => await formatter.WriteAsync(outputFormatterContext)); + await Assert.ThrowsAsync(async () => await formatter.WriteAsync(outputFormatterContext)); } [ConditionalFact] @@ -489,8 +488,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml var outputFormatterContext = GetOutputFormatterContext(parent, parent.GetType()); // Act & Assert - await Assert.ThrowsAsync(typeof(SerializationException), - async () => await formatter.WriteAsync(outputFormatterContext)); + await Assert.ThrowsAsync(async () => await formatter.WriteAsync(outputFormatterContext)); } [ConditionalFact] diff --git a/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/XmlSerializerInputFormatterTest.cs b/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/XmlSerializerInputFormatterTest.cs index 4604443f16..1cc85cfa7c 100644 --- a/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/XmlSerializerInputFormatterTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/XmlSerializerInputFormatterTest.cs @@ -215,12 +215,10 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml var formatter = new XmlSerializerInputFormatter(); // Assert - Assert.True(formatter.SupportedMediaTypes - .Select(content => content.ToString()) - .Contains("application/xml")); - Assert.True(formatter.SupportedMediaTypes - .Select(content => content.ToString()) - .Contains("text/xml")); + Assert.Contains("application/xml", formatter.SupportedMediaTypes + .Select(content => content.ToString())); + Assert.Contains("text/xml", formatter.SupportedMediaTypes + .Select(content => content.ToString())); } [Fact] @@ -230,8 +228,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml var formatter = new XmlSerializerInputFormatter(); // Assert - Assert.True(formatter.SupportedEncodings.Any(i => i.WebName == "utf-8")); - Assert.True(formatter.SupportedEncodings.Any(i => i.WebName == "utf-16")); + Assert.Contains(formatter.SupportedEncodings, i => i.WebName == "utf-8"); + Assert.Contains(formatter.SupportedEncodings, i => i.WebName == "utf-16"); } [Fact] @@ -342,7 +340,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml var context = GetInputFormatterContext(contentBytes, typeof(TestLevelTwo)); // Act & Assert - await Assert.ThrowsAsync(typeof(InvalidOperationException), () => formatter.ReadAsync(context)); + await Assert.ThrowsAsync(() => formatter.ReadAsync(context)); } [ConditionalFact] @@ -363,7 +361,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml var context = GetInputFormatterContext(contentBytes, typeof(TestLevelTwo)); // Act & Assert - await Assert.ThrowsAsync(typeof(InvalidOperationException), () => formatter.ReadAsync(context)); + await Assert.ThrowsAsync(() => formatter.ReadAsync(context)); } [Fact] @@ -373,7 +371,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml var formatter = new XmlSerializerInputFormatter(); // Act & Assert - Assert.Throws(typeof(ArgumentException), () => formatter.MaxDepth = 0); + Assert.Throws(() => formatter.MaxDepth = 0); } [Fact] diff --git a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/BasicTests.cs b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/BasicTests.cs index b6bd2c39a7..4362397fc8 100644 --- a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/BasicTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/BasicTests.cs @@ -208,7 +208,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests Assert.Equal(0, response.Content.Headers.ContentLength); var responseBytes = await response.Content.ReadAsByteArrayAsync(); - Assert.Equal(0, responseBytes.Length); + Assert.Empty(responseBytes); } [Fact] @@ -224,7 +224,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests Assert.Equal(0, response.Content.Headers.ContentLength); var responseBytes = await response.Content.ReadAsByteArrayAsync(); - Assert.Equal(0, responseBytes.Length); + Assert.Empty(responseBytes); } [Theory] diff --git a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/WebApiCompatShimBasicTest.cs b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/WebApiCompatShimBasicTest.cs index e18aa4c966..9834346b79 100644 --- a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/WebApiCompatShimBasicTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/WebApiCompatShimBasicTest.cs @@ -145,7 +145,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests // Assert var json = JsonConvert.DeserializeObject>(response); - Assert.Equal(1, json.Count); + Assert.Single(json); Assert.Equal("The field ID must be between 0 and 100.", json["prefix.ID"]); } @@ -167,7 +167,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests // Assert var json = JsonConvert.DeserializeObject>(response); - Assert.Equal(1, json.Count); + Assert.Single(json); Assert.Equal("The field ID must be between 0 and 100.", json["ID"]); } diff --git a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/ActionParametersIntegrationTest.cs b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/ActionParametersIntegrationTest.cs index e318353c21..ebbac1867d 100644 --- a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/ActionParametersIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/ActionParametersIntegrationTest.cs @@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Model Assert.NotNull(modelBindingResult.Model); var boundModel = Assert.IsType(modelBindingResult.Model); - Assert.Equal(1, boundModel.Address.Count); + Assert.Single(boundModel.Address); Assert.Equal("SomeStreet", boundModel.Address[0].Street); // ModelState @@ -153,7 +153,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests Assert.NotNull(modelBindingResult.Model); var boundModel = Assert.IsType(modelBindingResult.Model); Assert.NotNull(boundModel.Address); - Assert.Equal(1, boundModel.Address.Count()); + Assert.Single(boundModel.Address); Assert.Equal("SomeStreet", boundModel.Address[0].Street); // ModelState @@ -201,7 +201,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests Assert.NotNull(boundModel.Address); // Arrays should not be updated. - Assert.Equal(0, boundModel.Address.Count()); + Assert.Empty(boundModel.Address); // ModelState Assert.True(modelState.IsValid); @@ -239,7 +239,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Model Assert.NotNull(modelBindingResult.Model); var boundModel = Assert.IsType(modelBindingResult.Model); - Assert.Equal(1, boundModel.Address.Count); + Assert.Single(boundModel.Address); Assert.Equal("SomeStreet", boundModel.Address[0].Street); // ModelState @@ -330,7 +330,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Model Assert.NotNull(modelBindingResult.Model); var boundModel = Assert.IsType(modelBindingResult.Model); - Assert.Equal(1, boundModel.Address.Count()); + Assert.Single(boundModel.Address); Assert.Equal("SomeStreet", boundModel.Address[0].Street); // ModelState @@ -377,7 +377,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests var boundModel = Assert.IsType(modelBindingResult.Model); // Arrays should not be updated. - Assert.Equal(0, boundModel.Address.Count()); + Assert.Empty(boundModel.Address); // ModelState Assert.True(modelState.IsValid); diff --git a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/CancellationTokenModelBinderIntegrationTest.cs b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/CancellationTokenModelBinderIntegrationTest.cs index d5080ea6c8..26552ccfce 100644 --- a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/CancellationTokenModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/CancellationTokenModelBinderIntegrationTest.cs @@ -50,7 +50,9 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Model var boundPerson = Assert.IsType(modelBindingResult.Model); Assert.NotNull(boundPerson); - Assert.NotSame(default(CancellationToken), boundPerson.Token); + Assert.False(boundPerson.Token.IsCancellationRequested); + testContext.HttpContext.Abort(); + Assert.True(boundPerson.Token.IsCancellationRequested); // ModelState Assert.True(modelState.IsValid); @@ -84,7 +86,9 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Model var boundPerson = Assert.IsType(modelBindingResult.Model); Assert.NotNull(boundPerson); - Assert.NotSame(default(CancellationToken), boundPerson.Token); + Assert.False(boundPerson.Token.IsCancellationRequested); + testContext.HttpContext.Abort(); + Assert.True(boundPerson.Token.IsCancellationRequested); // ModelState Assert.True(modelState.IsValid); @@ -120,7 +124,9 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Model var token = Assert.IsType(modelBindingResult.Model); - Assert.NotSame(default(CancellationToken), token); + Assert.False(token.IsCancellationRequested); + testContext.HttpContext.Abort(); + Assert.True(token.IsCancellationRequested); // ModelState Assert.True(modelState.IsValid); diff --git a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/GenericModelBinderIntegrationTest.cs b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/GenericModelBinderIntegrationTest.cs index d85638e325..bf10111e82 100644 --- a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/GenericModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/GenericModelBinderIntegrationTest.cs @@ -216,7 +216,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); - Assert.Equal(1, model.Length); + Assert.Single(model); Assert.NotNull(model[0]); Assert.Equal(0, modelState.Count); @@ -250,7 +250,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); - Assert.Equal(1, model.Length); + Assert.Single(model); Assert.Null(model[0]); Assert.Equal(0, modelState.Count); diff --git a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/ModelBindingTestHelper.cs b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/ModelBindingTestHelper.cs index 8d340a29a6..7ccd40514b 100644 --- a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/ModelBindingTestHelper.cs +++ b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/ModelBindingTestHelper.cs @@ -3,8 +3,10 @@ using System; using System.Collections.Generic; +using System.Threading; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Internal; @@ -100,11 +102,9 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests Action updateOptions = null) { var httpContext = new DefaultHttpContext(); + httpContext.Features.Set(new CancellableRequestLifetimeFeature()); - if (updateRequest != null) - { - updateRequest(httpContext.Request); - } + updateRequest?.Invoke(httpContext.Request); httpContext.RequestServices = GetServices(updateOptions); return httpContext; @@ -128,5 +128,17 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests return serviceCollection.BuildServiceProvider(); } + + private class CancellableRequestLifetimeFeature : IHttpRequestLifetimeFeature + { + private readonly CancellationTokenSource _cts = new CancellationTokenSource(); + + public CancellationToken RequestAborted { get => _cts.Token; set => throw new NotImplementedException(); } + + public void Abort() + { + _cts.Cancel(); + } + } } } diff --git a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/ServicesModelBinderIntegrationTest.cs b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/ServicesModelBinderIntegrationTest.cs index 8e41bac727..8d3f83f68f 100644 --- a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/ServicesModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/ServicesModelBinderIntegrationTest.cs @@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Model var formatterArray = Assert.IsType(modelBindingResult.Model); - Assert.Equal(1, formatterArray.Length); + Assert.Single(formatterArray); // ModelState Assert.True(modelState.IsValid); @@ -152,7 +152,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Model var actionResultArray = Assert.IsType(modelBindingResult.Model); - Assert.Equal(0, actionResultArray.Length); + Assert.Empty(actionResultArray); // ModelState Assert.True(modelState.IsValid); diff --git a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/SimpleTypeModelBinderIntegrationTest.cs b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/SimpleTypeModelBinderIntegrationTest.cs index 906450a3fa..daddf74bda 100644 --- a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/SimpleTypeModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/SimpleTypeModelBinderIntegrationTest.cs @@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // ModelState Assert.True(modelState.IsValid); - Assert.Equal(1, modelState.Keys.Count()); + Assert.Single(modelState.Keys); var key = Assert.Single(modelState.Keys, k => k == "CustomParameter.Address.Zip"); Assert.Equal("1", modelState[key].AttemptedValue); Assert.Equal("1", modelState[key].RawValue); @@ -101,7 +101,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // ModelState Assert.True(modelState.IsValid); - Assert.Equal(1, modelState.Keys.Count()); + Assert.Single(modelState.Keys); var key = Assert.Single(modelState.Keys, k => k == "Address.Zip"); Assert.Equal("1", modelState[key].AttemptedValue); Assert.Equal("1", modelState[key].RawValue); @@ -144,7 +144,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // ModelState Assert.True(modelState.IsValid); - Assert.Equal(1, modelState.Keys.Count()); + Assert.Single(modelState.Keys); var key = Assert.Single(modelState.Keys); Assert.Equal("Parameter1", key); Assert.Equal("someValue", modelState[key].AttemptedValue); @@ -188,7 +188,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // ModelState Assert.True(modelState.IsValid); - Assert.Equal(1, modelState.Keys.Count()); + Assert.Single(modelState.Keys); var key = Assert.Single(modelState.Keys); Assert.Equal("Parameter1", key); Assert.Equal("32,000.99", modelState[key].AttemptedValue); @@ -232,7 +232,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // ModelState Assert.True(modelState.IsValid); - Assert.Equal(1, modelState.Keys.Count()); + Assert.Single(modelState.Keys); var key = Assert.Single(modelState.Keys); Assert.Equal("Parameter1", key); Assert.Equal("someValue,otherValue", modelState[key].AttemptedValue); diff --git a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/TryUpdateModelIntegrationTest.cs b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/TryUpdateModelIntegrationTest.cs index 47b8ac9945..200d95914d 100644 --- a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/TryUpdateModelIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/TryUpdateModelIntegrationTest.cs @@ -234,7 +234,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Model Assert.NotNull(model.Address); - Assert.Equal(1, model.Address.Count); + Assert.Single(model.Address); Assert.Equal("SomeStreet", model.Address[0].Street); Assert.Null(model.Address[0].City); @@ -275,7 +275,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Model Assert.NotNull(model.Address); Assert.Same(collection, model.Address); - Assert.Equal(1, model.Address.Count); + Assert.Single(model.Address); Assert.Equal("SomeStreet", model.Address[0].Street); Assert.Null(model.Address[0].City); @@ -336,7 +336,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Model (collection is cleared and new members created from scratch). Assert.NotNull(model.Address); - Assert.Equal(1, model.Address.Count); + Assert.Single(model.Address); Assert.Equal("SomeStreet", model.Address[0].Street); Assert.Null(model.Address[0].City); @@ -440,7 +440,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Model Assert.NotNull(model.Address); - Assert.Equal(1, model.Address.Length); + Assert.Single(model.Address); Assert.Equal("SomeStreet", model.Address[0].Street); Assert.Null(model.Address[0].City); @@ -488,7 +488,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Model Assert.NotNull(model.Address); Assert.NotSame(collection, model.Address); - Assert.Equal(1, model.Address.Length); + Assert.Single(model.Address); Assert.Equal("SomeStreet", model.Address[0].Street); Assert.Null(model.Address[0].City); @@ -531,7 +531,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests Assert.NotNull(model.Address); // Arrays should not be updated. - Assert.Equal(0, model.Address.Length); + Assert.Empty(model.Address); // ModelState Assert.True(modelState.IsValid); @@ -572,7 +572,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests Assert.NotNull(model.Address); // Arrays should not be updated. - Assert.Equal(1, model.Address.Count()); + Assert.Single(model.Address); Assert.Collection( model.Address, (a) => @@ -619,7 +619,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests Assert.NotNull(model.Address); // Arrays should not be updated. - Assert.Equal(1, model.Address.Count()); + Assert.Single(model.Address); Assert.Collection( model.Address, (a) => @@ -829,7 +829,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Model Assert.NotNull(model.Address); - Assert.Equal(1, model.Address.Count); + Assert.Single(model.Address); Assert.Equal("SomeStreet", model.Address[0].Street); Assert.Null(model.Address[0].City); @@ -870,7 +870,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Model Assert.NotNull(model.Address); Assert.Same(collection, model.Address); - Assert.Equal(1, model.Address.Count); + Assert.Single(model.Address); Assert.Equal("SomeStreet", model.Address[0].Street); Assert.Null(model.Address[0].City); @@ -921,7 +921,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Model (collection is cleared and new members created from scratch). Assert.NotNull(model.Address); - Assert.Equal(1, model.Address.Count); + Assert.Single(model.Address); Assert.Equal("SomeStreet", model.Address[0].Street); Assert.Null(model.Address[0].City); @@ -957,7 +957,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Model Assert.NotNull(model.Address); - Assert.Equal(1, model.Address.Length); + Assert.Single(model.Address); Assert.Equal("SomeStreet", model.Address[0].Street); Assert.Null(model.Address[0].City); @@ -1005,7 +1005,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Model Assert.NotNull(model.Address); Assert.NotSame(collection, model.Address); - Assert.Equal(1, model.Address.Length); + Assert.Single(model.Address); Assert.Equal("SomeStreet", model.Address[0].Street); Assert.Null(model.Address[0].City); @@ -1043,7 +1043,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests Assert.NotNull(model.Address); // Arrays should not be updated. - Assert.Equal(0, model.Address.Length); + Assert.Empty(model.Address); // ModelState Assert.True(modelState.IsValid); diff --git a/test/Microsoft.AspNetCore.Mvc.Localization.Test/HtmlLocalizerTest.cs b/test/Microsoft.AspNetCore.Mvc.Localization.Test/HtmlLocalizerTest.cs index b78a0b3ed5..d7cf25b528 100644 --- a/test/Microsoft.AspNetCore.Mvc.Localization.Test/HtmlLocalizerTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Localization.Test/HtmlLocalizerTest.cs @@ -230,7 +230,7 @@ namespace Microsoft.AspNetCore.Mvc.Localization.Test var allLocalizedStrings = htmlLocalizer.GetAllStrings(includeParentCultures: false).ToList(); //Assert - Assert.Equal(1, allLocalizedStrings.Count); + Assert.Single(allLocalizedStrings); Assert.Equal("World", allLocalizedStrings.First().Value); } diff --git a/test/Microsoft.AspNetCore.Mvc.Localization.Test/ViewLocalizerTest.cs b/test/Microsoft.AspNetCore.Mvc.Localization.Test/ViewLocalizerTest.cs index 0e40de4a06..ae1afa5ce2 100644 --- a/test/Microsoft.AspNetCore.Mvc.Localization.Test/ViewLocalizerTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Localization.Test/ViewLocalizerTest.cs @@ -136,7 +136,7 @@ namespace Microsoft.AspNetCore.Mvc.Localization.Test var allLocalizedStrings = viewLocalizer.GetAllStrings(includeParentCultures: false).ToList(); // Assert - Assert.Equal(1, allLocalizedStrings.Count); + Assert.Single(allLocalizedStrings); Assert.Equal("World", allLocalizedStrings.First().Value); } diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Test/RazorViewEngineTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Test/RazorViewEngineTest.cs index b19fb8002c..df48377833 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Test/RazorViewEngineTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Test/RazorViewEngineTest.cs @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Test {"page", "/Accounts/Index"}, }; - public static IEnumerable AbsoluteViewPathData + public static IEnumerable AbsoluteViewPathData { get { diff --git a/test/Microsoft.AspNetCore.Mvc.Test/JsonPatchExtensionsTest.cs b/test/Microsoft.AspNetCore.Mvc.Test/JsonPatchExtensionsTest.cs index eb173f505f..b19ca4149e 100644 --- a/test/Microsoft.AspNetCore.Mvc.Test/JsonPatchExtensionsTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Test/JsonPatchExtensionsTest.cs @@ -87,7 +87,7 @@ namespace Microsoft.AspNetCore.Mvc // Assert Assert.Equal(1, modelState.ErrorCount); Assert.Equal(nameof(Customer), modelState.First().Key); - Assert.Equal(1, modelState.First().Value.Errors.Count); + Assert.Single(modelState.First().Value.Errors); Assert.Equal(error, modelState.First().Value.Errors.First().ErrorMessage); } diff --git a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/HtmlAttributePropertyHelperTest.cs b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/HtmlAttributePropertyHelperTest.cs index 12bfae0bbc..00c7672240 100644 --- a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/HtmlAttributePropertyHelperTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/HtmlAttributePropertyHelperTest.cs @@ -81,7 +81,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal var helpers2 = HtmlAttributePropertyHelper.GetProperties(anonymous.GetType()); // Assert - Assert.Equal(1, helpers1.Length); + Assert.Single(helpers1); Assert.Same(helpers1, helpers2); Assert.Same(helpers1[0], helpers2[0]); } @@ -97,8 +97,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal var helpers2 = PropertyHelper.GetProperties(anonymous.GetType()); // Assert - Assert.Equal(1, helpers1.Length); - Assert.Equal(1, helpers2.Length); + Assert.Single(helpers1); + Assert.Single(helpers2); Assert.NotEqual(helpers1, helpers2); Assert.NotEqual(helpers1[0], helpers2[0]); diff --git a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewComponents/DefaultViewComponentHelperTest.cs b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewComponents/DefaultViewComponentHelperTest.cs index ae4503c7a9..1bebf6ebac 100644 --- a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewComponents/DefaultViewComponentHelperTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewComponents/DefaultViewComponentHelperTest.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents // Assert Assert.Equal(0, argumentDictionary.Count); - Assert.IsType(typeof(Dictionary),argumentDictionary); + Assert.IsType>(argumentDictionary); } [Fact] @@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents item => { Assert.Equal("a", item.Key); - Assert.IsType(typeof(int), item.Value); + Assert.IsType(item.Value); Assert.Equal(0, item.Value); }); } @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents item => { Assert.Equal("a", item.Key); - Assert.IsType(typeof(int), item.Value); + Assert.IsType(item.Value); Assert.Equal(0, item.Value); }); } @@ -85,13 +85,13 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents item1 => { Assert.Equal("a", item1.Key); - Assert.IsType(typeof(int), item1.Value); + Assert.IsType(item1.Value); Assert.Equal(0, item1.Value); }, item2 => { Assert.Equal("b", item2.Key); - Assert.IsType(typeof(string), item2.Value); + Assert.IsType(item2.Value); Assert.Equal("foo", item2.Value); }); } @@ -112,7 +112,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents item => { Assert.Equal("o", item.Key); - Assert.IsType(typeof(object), item.Value); + Assert.IsType(item.Value); Assert.Same(expectedValue, item.Value); }); } @@ -136,7 +136,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents item => { Assert.Equal("a", item.Key); - Assert.IsType(typeof(int), item.Value); + Assert.IsType(item.Value); Assert.Equal(10, item.Value); }); } diff --git a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewFeatures/ModelExplorerTest.cs b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewFeatures/ModelExplorerTest.cs index 66bf38009d..366f8b37b5 100644 --- a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewFeatures/ModelExplorerTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ViewFeatures/ModelExplorerTest.cs @@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures var properties = modelExplorer.Properties.ToArray(); // Assert - Assert.Equal(1, properties.Length); + Assert.Single(properties); var baseProperty = Assert.Single(properties, p => p.Metadata.PropertyName == "Base1"); Assert.Equal(typeof(int), baseProperty.Metadata.ModelType); diff --git a/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/ApiControllerActionDiscoveryTest.cs b/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/ApiControllerActionDiscoveryTest.cs index c3f2b4a866..315a4568bc 100644 --- a/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/ApiControllerActionDiscoveryTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/ApiControllerActionDiscoveryTest.cs @@ -281,7 +281,7 @@ namespace System.Web.Http var parameter = Assert.Single(action.Parameters); Assert.Equal((new FromUriAttribute()).BindingSource, parameter.BindingInfo.BindingSource); var optionalParameters = (HashSet)action.Properties["OptionalParameters"]; - Assert.False(optionalParameters.Contains(parameter.Name)); + Assert.DoesNotContain(parameter.Name, optionalParameters); } } @@ -366,7 +366,7 @@ namespace System.Web.Http var parameter = Assert.Single(action.Parameters); Assert.Equal((new FromUriAttribute()).BindingSource, parameter.BindingInfo.BindingSource); var optionalParameters = (HashSet)action.Properties["OptionalParameters"]; - Assert.True(optionalParameters.Contains(parameter.Name)); + Assert.Contains(parameter.Name, optionalParameters); } } diff --git a/test/MvcTests.ruleset b/test/MvcTests.ruleset new file mode 100644 index 0000000000..23f2deac4a --- /dev/null +++ b/test/MvcTests.ruleset @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file