From af7d61113bfe46776e6d6a7c558f49d5c19ed9ba Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 25 Mar 2014 15:10:31 -0700 Subject: [PATCH] Updating test projects to use Microsoft.AspNet.Testing --- WebFx.sln | 7 - .../project.json | 1 + .../Binders/ModelBindingContextTest.cs | 1 + .../Binders/MutableObjectModelBinderTest.cs | 1 + .../AssociatedMetadataProviderTest.cs | 13 +- .../AssociatedValidatorProviderTest.cs | 13 -- .../DataAnnotationsModelValidatorTest.cs | 14 +- .../Validation/ErrorModelValidatorTest.cs | 1 + .../InvalidModelValidatorProviderTest.cs | 1 + .../Validation/ModelValidationNodeTest.cs | 2 +- ...dableStringCollectionValueProviderTests.cs | 24 --- .../project.json | 1 + .../project.json | 2 +- .../project.json | 2 +- .../project.json | 2 +- test/TestCommon/CultureReplacer.cs | 72 -------- test/TestCommon/ExceptionAssert.cs | 170 ------------------ test/TestCommon/ReplaceCulture.cs | 56 ------ test/TestCommon/project.json | 17 -- 19 files changed, 12 insertions(+), 388 deletions(-) delete mode 100644 test/TestCommon/CultureReplacer.cs delete mode 100644 test/TestCommon/ExceptionAssert.cs delete mode 100644 test/TestCommon/ReplaceCulture.cs delete mode 100644 test/TestCommon/project.json diff --git a/WebFx.sln b/WebFx.sln index 11c8b287bb..16a2fb71ac 100644 --- a/WebFx.sln +++ b/WebFx.sln @@ -51,8 +51,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.k10", "src\Common\Co EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Mvc.Razor.Test.net45", "test\Microsoft.AspNet.Mvc.Razor.Test\Microsoft.AspNet.Mvc.Razor.Test.net45.csproj", "{3EB2CFF9-6E67-4C03-9AC4-2DD169024938}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestCommon.net45", "test\TestCommon\TestCommon.net45.csproj", "{75A07B53-C5EE-4995-A55B-27562C23BCCD}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Mvc.Rendering.Test.net45", "test\Microsoft.AspNet.Mvc.Rendering.Test\Microsoft.AspNet.Mvc.Rendering.Test.net45.csproj", "{68FC3791-A9E4-4EDE-93A5-C7AC7DC0ED6E}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "k10", "k10", "{A4E25DA1-9BC1-4534-BDAA-4AEB7C089B0F}" @@ -141,10 +139,6 @@ Global {3EB2CFF9-6E67-4C03-9AC4-2DD169024938}.Debug|Any CPU.Build.0 = Debug|Any CPU {3EB2CFF9-6E67-4C03-9AC4-2DD169024938}.Release|Any CPU.ActiveCfg = Release|Any CPU {3EB2CFF9-6E67-4C03-9AC4-2DD169024938}.Release|Any CPU.Build.0 = Release|Any CPU - {75A07B53-C5EE-4995-A55B-27562C23BCCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {75A07B53-C5EE-4995-A55B-27562C23BCCD}.Debug|Any CPU.Build.0 = Debug|Any CPU - {75A07B53-C5EE-4995-A55B-27562C23BCCD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {75A07B53-C5EE-4995-A55B-27562C23BCCD}.Release|Any CPU.Build.0 = Release|Any CPU {68FC3791-A9E4-4EDE-93A5-C7AC7DC0ED6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {68FC3791-A9E4-4EDE-93A5-C7AC7DC0ED6E}.Debug|Any CPU.Build.0 = Debug|Any CPU {68FC3791-A9E4-4EDE-93A5-C7AC7DC0ED6E}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -187,7 +181,6 @@ Global {998C5A2E-D043-465F-BE19-076D27444289} = {49EBEEDD-E117-4B91-B4BA-56FB80AF4F3C} {3EB2CFF9-6E67-4C03-9AC4-2DD169024938} = {49EBEEDD-E117-4B91-B4BA-56FB80AF4F3C} {68FC3791-A9E4-4EDE-93A5-C7AC7DC0ED6E} = {49EBEEDD-E117-4B91-B4BA-56FB80AF4F3C} - {75A07B53-C5EE-4995-A55B-27562C23BCCD} = {49EBEEDD-E117-4B91-B4BA-56FB80AF4F3C} {5A219830-3C19-475D-901F-E580BA87DFF8} = {A4E25DA1-9BC1-4534-BDAA-4AEB7C089B0F} EndGlobalSection EndGlobal diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/project.json b/test/Microsoft.AspNet.Mvc.Core.Test/project.json index 51cfc7e1eb..1dffea98f2 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/project.json +++ b/test/Microsoft.AspNet.Mvc.Core.Test/project.json @@ -3,6 +3,7 @@ "dependencies": { "Microsoft.AspNet.Mvc.Core" : "", "Microsoft.AspNet.Mvc" : "", + "Microsoft.AspNet.Testing": "0.1-alpha-*", "Moq": "4.2.1312.1622", "Xunit.KRunner": "0.1-alpha-*", "xunit.abstractions": "2.0.0-aspnet-*", diff --git a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Binders/ModelBindingContextTest.cs b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Binders/ModelBindingContextTest.cs index 4dc4a3522f..04725ca495 100644 --- a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Binders/ModelBindingContextTest.cs +++ b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Binders/ModelBindingContextTest.cs @@ -1,4 +1,5 @@ using System; +using Microsoft.AspNet.Testing; using Xunit; namespace Microsoft.AspNet.Mvc.ModelBinding.Test diff --git a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Binders/MutableObjectModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Binders/MutableObjectModelBinderTest.cs index aded08fe6f..c25ffcc35e 100644 --- a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Binders/MutableObjectModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Binders/MutableObjectModelBinderTest.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; +using Microsoft.AspNet.Testing; using Moq; using Xunit; diff --git a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Metadata/AssociatedMetadataProviderTest.cs b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Metadata/AssociatedMetadataProviderTest.cs index 8acad63255..bffcf113c2 100644 --- a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Metadata/AssociatedMetadataProviderTest.cs +++ b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Metadata/AssociatedMetadataProviderTest.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Linq; +using Microsoft.AspNet.Testing; using Xunit; namespace Microsoft.AspNet.Mvc.ModelBinding.Test.Binders @@ -72,18 +73,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test.Binders // GetMetadataForProperty - //[Fact] - //public void GetMetadataForPropertyNullContainerTypeThrows() - //{ - // // Arrange - // TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); - - // // Act & Assert - // ExceptionAssert.ThrowsArgumentNull( - // () => provider.GetMetadataForProperty(modelAccessor: null, containerType: null, propertyName: "propertyName"), - // "containerType"); - //} - [Fact] public void GetMetadataForPropertyNullOrEmptyPropertyNameThrows() { diff --git a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/AssociatedValidatorProviderTest.cs b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/AssociatedValidatorProviderTest.cs index 8182bf36c1..b8f0caefd4 100644 --- a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/AssociatedValidatorProviderTest.cs +++ b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/AssociatedValidatorProviderTest.cs @@ -12,19 +12,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding { private readonly DataAnnotationsModelMetadataProvider _metadataProvider = new DataAnnotationsModelMetadataProvider(); - [Fact] - public void GetValidatorsThrowsIfMetadataIsNull() - { - // Arrange - var metadata = _metadataProvider.GetMetadataForType(null, typeof(object)); - var provider = new Mock { CallBase = true }; - - // Act & Assert - ExceptionAssert.ThrowsArgumentNull( - () => provider.Object.GetValidators(metadata: null), - "metadata"); - } - [Fact] public void GetValidatorsForPropertyWithLocalAttributes() { diff --git a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/DataAnnotationsModelValidatorTest.cs b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/DataAnnotationsModelValidatorTest.cs index b4f7c08813..35e827a835 100644 --- a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/DataAnnotationsModelValidatorTest.cs +++ b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/DataAnnotationsModelValidatorTest.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using Microsoft.AspNet.Testing; #if NET45 using Moq; using Moq.Protected; @@ -13,19 +14,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding { private static DataAnnotationsModelMetadataProvider _metadataProvider = new DataAnnotationsModelMetadataProvider(); - [Fact] - public void ConstructorGuards() - { - // Arrange - var metadata = _metadataProvider.GetMetadataForType(null, typeof(object)); - var attribute = new RequiredAttribute(); - - // Act & Assert - ExceptionAssert.ThrowsArgumentNull( - () => new DataAnnotationsModelValidator(null), - "attribute"); - } - [Fact] public void ValuesSet() { diff --git a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/ErrorModelValidatorTest.cs b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/ErrorModelValidatorTest.cs index 03d657e474..7c8232ef11 100644 --- a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/ErrorModelValidatorTest.cs +++ b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/ErrorModelValidatorTest.cs @@ -1,4 +1,5 @@ using System; +using Microsoft.AspNet.Testing; using Xunit; namespace Microsoft.AspNet.Mvc.ModelBinding diff --git a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/InvalidModelValidatorProviderTest.cs b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/InvalidModelValidatorProviderTest.cs index c46c8710ee..dd4aa68c53 100644 --- a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/InvalidModelValidatorProviderTest.cs +++ b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/InvalidModelValidatorProviderTest.cs @@ -2,6 +2,7 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Runtime.Serialization; +using Microsoft.AspNet.Testing; using Xunit; namespace Microsoft.AspNet.Mvc.ModelBinding diff --git a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/ModelValidationNodeTest.cs b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/ModelValidationNodeTest.cs index 3215da0ead..fdf944dc37 100644 --- a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/ModelValidationNodeTest.cs +++ b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/ModelValidationNodeTest.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; -using Microsoft.AspNet.Mvc.ModelBinding.Test; +using Microsoft.AspNet.Testing; using Xunit; namespace Microsoft.AspNet.Mvc.ModelBinding diff --git a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/ValueProviders/ReadableStringCollectionValueProviderTests.cs b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/ValueProviders/ReadableStringCollectionValueProviderTests.cs index 49bb65827e..6a3cc102e9 100644 --- a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/ValueProviders/ReadableStringCollectionValueProviderTests.cs +++ b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/ValueProviders/ReadableStringCollectionValueProviderTests.cs @@ -19,18 +19,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test }); - [Fact] - public void ContainsPrefix_GuardClauses() - { - // Arrange - var valueProvider = new ReadableStringCollectionValueProvider(_backingStore, null); - - // Act & assert - ExceptionAssert.ThrowsArgumentNull( - () => valueProvider.ContainsPrefix(null), - "prefix"); - } - [Fact] public void ContainsPrefix_WithEmptyCollection_ReturnsFalseForEmptyPrefix() { @@ -126,18 +114,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test Assert.Equal("bar.baz", kvp.Value); } - [Fact] - public void GetValue_GuardClauses() - { - // Arrange - var valueProvider = new ReadableStringCollectionValueProvider(_backingStore, null); - - // Act & assert - ExceptionAssert.ThrowsArgumentNull( - () => valueProvider.GetValue(null), - "key"); - } - [Fact] public void GetValue_SingleValue() { diff --git a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/project.json b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/project.json index 5509daf522..9d13d708c0 100644 --- a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/project.json +++ b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/project.json @@ -3,6 +3,7 @@ "dependencies": { "Microsoft.AspNet.Abstractions": "0.1-alpha-*", "Microsoft.AspNet.PipelineCore": "0.1-alpha-*", + "Microsoft.AspNet.Testing": "0.1-alpha-*", "Microsoft.ComponentModel.DataAnnotations" : "4.0.10.0", "Microsoft.AspNet.Mvc.ModelBinding" : "", "Newtonsoft.Json": "5.0.8", diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/project.json b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/project.json index 691135ee55..3ff2d0842f 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/project.json +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/project.json @@ -2,8 +2,8 @@ "version" : "0.1-alpha-*", "dependencies": { "Microsoft.AspNet.Razor" : "0.1-alpha-*", + "Microsoft.AspNet.Testing" : "0.1-alpha-*", "Microsoft.AspNet.Mvc.Razor.Host" : "", - "TestCommon" : "", "Xunit.KRunner": "0.1-alpha-*", "xunit.abstractions": "2.0.0-aspnet-*", "xunit.assert": "2.0.0-aspnet-*", diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/project.json b/test/Microsoft.AspNet.Mvc.Razor.Test/project.json index f968670141..80924a4882 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Test/project.json +++ b/test/Microsoft.AspNet.Mvc.Razor.Test/project.json @@ -5,7 +5,7 @@ "Microsoft.AspNet.Razor": "0.1-alpha-*", "Microsoft.AspNet.Mvc.Razor" : "", "Microsoft.AspNet.Mvc.Razor.Host" : "", - "TestCommon" : "", + "Microsoft.AspNet.Testing" : "0.1-alpha-*", "Xunit.KRunner": "0.1-alpha-*", "xunit.abstractions": "2.0.0-aspnet-*", "xunit.assert": "2.0.0-aspnet-*", diff --git a/test/Microsoft.AspNet.Mvc.Rendering.Test/project.json b/test/Microsoft.AspNet.Mvc.Rendering.Test/project.json index 5ba50da201..d2f461e3ae 100644 --- a/test/Microsoft.AspNet.Mvc.Rendering.Test/project.json +++ b/test/Microsoft.AspNet.Mvc.Rendering.Test/project.json @@ -5,7 +5,7 @@ "Microsoft.AspNet.PipelineCore": "0.1-alpha-*", "Microsoft.AspNet.Mvc.ModelBinding" : "", "Microsoft.AspNet.Mvc.Rendering" : "", - "TestCommon" : "", + "Microsoft.AspNet.Testing" : "0.1-alpha-*", "Xunit.KRunner": "0.1-alpha-*", "xunit.abstractions": "2.0.0-aspnet-*", "xunit.assert": "2.0.0-aspnet-*", diff --git a/test/TestCommon/CultureReplacer.cs b/test/TestCommon/CultureReplacer.cs deleted file mode 100644 index b9d259e64f..0000000000 --- a/test/TestCommon/CultureReplacer.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System; -using System.Globalization; -using System.Threading; -using Xunit; - -namespace Microsoft.AspNet.Mvc -{ - internal class CultureReplacer : IDisposable - { - private const string _defaultCultureName = "en-GB"; - private const string _defaultUICultureName = "en-US"; - private static readonly CultureInfo _defaultCulture = new CultureInfo(_defaultCultureName); - private readonly CultureInfo _originalCulture; - private readonly CultureInfo _originalUICulture; - private readonly long _threadId; - - // Culture => Formatting of dates/times/money/etc, defaults to en-GB because en-US is the same as InvariantCulture - // We want to be able to find issues where the InvariantCulture is used, but a specific culture should be. - // - // UICulture => Language - public CultureReplacer(string culture = _defaultCultureName, string uiCulture = _defaultUICultureName) - { - _originalCulture = CultureInfo.DefaultThreadCurrentCulture; - _originalUICulture = CultureInfo.DefaultThreadCurrentUICulture; - _threadId = Thread.CurrentThread.ManagedThreadId; - - CultureInfo.DefaultThreadCurrentCulture = new CultureInfo(culture); - CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(uiCulture); - } - - /// - /// The name of the culture that is used as the default value for Thread.CurrentCulture when CultureReplacer is used. - /// - public static string DefaultCultureName - { - get { return _defaultCultureName; } - } - - /// - /// The name of the culture that is used as the default value for Thread.UICurrentCulture when CultureReplacer is used. - /// - public static string DefaultUICultureName - { - get { return _defaultUICultureName; } - } - - /// - /// The culture that is used as the default value for Thread.CurrentCulture when CultureReplacer is used. - /// - public static CultureInfo DefaultCulture - { - get { return _defaultCulture; } - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private void Dispose(bool disposing) - { - if (disposing) - { - Assert.True(Thread.CurrentThread.ManagedThreadId == _threadId, - "The current thread is not the same as the thread invoking the constructor. This should never happen."); - CultureInfo.DefaultThreadCurrentCulture = _originalCulture; - CultureInfo.DefaultThreadCurrentUICulture = _originalUICulture; - } - } - } -} diff --git a/test/TestCommon/ExceptionAssert.cs b/test/TestCommon/ExceptionAssert.cs deleted file mode 100644 index afc5b65fd8..0000000000 --- a/test/TestCommon/ExceptionAssert.cs +++ /dev/null @@ -1,170 +0,0 @@ -using System; -using System.Reflection; -using Xunit; - -namespace Microsoft.AspNet.Mvc -{ - internal static class ExceptionAssert - { - /// - /// Verifies that an exception of the given type (or optionally a derived type) is thrown. - /// - /// The type of the exception expected to be thrown - /// A delegate to the code to be tested - /// The exception that was thrown, when successful - /// Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - public static TException Throws(Action testCode) - where TException : Exception - { - Type exceptionType = typeof(TException); - Exception exception = RecordException(testCode); - - TargetInvocationException tie = exception as TargetInvocationException; - if (tie != null) - { - exception = tie.InnerException; - } - - Assert.NotNull(exception); - return Assert.IsAssignableFrom(exception); - } - - /// - /// Verifies that an exception of the given type (or optionally a derived type) is thrown. - /// Also verifies that the exception message matches. - /// - /// The type of the exception expected to be thrown - /// A delegate to the code to be tested - /// The exception message to verify - /// The exception that was thrown, when successful - /// Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - public static TException Throws(Action testCode, string exceptionMessage) - where TException : Exception - { - var ex = Throws(testCode); - VerifyExceptionMessage(ex, exceptionMessage); - return ex; - } - - /// - /// Verifies that an exception of the given type (or optionally a derived type) is thrown. - /// Also verified that the exception message matches. - /// - /// The type of the exception expected to be thrown - /// A delegate to the code to be tested - /// The exception message to verify - /// The exception that was thrown, when successful - /// Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - public static TException Throws(Func testCode, string exceptionMessage) - where TException : Exception - { - return Throws(() => { testCode(); }, exceptionMessage); - } - - /// - /// Verifies that the code throws an (or optionally any exception which derives from it). - /// - /// A delegate to the code to be tested - /// The name of the parameter that should throw the exception - /// The exception message to verify - /// The exception that was thrown, when successful - /// Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - public static ArgumentException ThrowsArgument(Action testCode, string paramName, string exceptionMessage) - { - var ex = Throws(testCode); - - if (paramName != null) - { - Assert.Equal(paramName, ex.ParamName); - } - - VerifyExceptionMessage(ex, exceptionMessage, partialMatch: true); - - return ex; - } - - /// - /// Verifies that the code throws an ArgumentNullException (or optionally any exception which derives from it). - /// - /// A delegate to the code to be tested - /// The name of the parameter that should throw the exception - /// The exception that was thrown, when successful - /// Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - public static ArgumentNullException ThrowsArgumentNull(Action testCode, string paramName) - { - var ex = Throws(testCode); - - if (paramName != null) - { - Assert.Equal(paramName, ex.ParamName); - } - - return ex; - } - - /// - /// Verifies that the code throws an ArgumentNullException with the expected message that indicates that the value cannot - /// be null or empty. - /// - /// A delegate to the code to be tested - /// The name of the parameter that should throw the exception - /// The exception that was thrown, when successful - /// Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - public static ArgumentException ThrowsArgumentNullOrEmpty(Action testCode, string paramName) - { - return Throws(testCode, "Value cannot be null or empty.\r\nParameter name: " + paramName); - } - - // We've re-implemented all the xUnit.net Throws code so that we can get this - // updated implementation of RecordException which silently unwraps any instances - // of AggregateException. In addition to unwrapping exceptions, this method ensures - // that tests are executed in with a known set of Culture and UICulture. This prevents - // tests from failing when executed on a non-English machine. - private static Exception RecordException(Action testCode) - { - try - { - using (new CultureReplacer()) - { - testCode(); - } - return null; - } - catch (Exception exception) - { - return UnwrapException(exception); - } - } - - private static Exception UnwrapException(Exception exception) - { - AggregateException aggEx = exception as AggregateException; - if (aggEx != null) - { - return aggEx.GetBaseException(); - } - return exception; - } - - private static void VerifyException(Type exceptionType, Exception exception) - { - Assert.NotNull(exception); - Assert.IsAssignableFrom(exceptionType, exception); - } - - private static void VerifyExceptionMessage(Exception exception, string expectedMessage, bool partialMatch = false) - { - if (expectedMessage != null) - { - if (!partialMatch) - { - Assert.Equal(expectedMessage, exception.Message); - } - else - { - Assert.Contains(expectedMessage, exception.Message); - } - } - } - } -} diff --git a/test/TestCommon/ReplaceCulture.cs b/test/TestCommon/ReplaceCulture.cs deleted file mode 100644 index 9a9306a747..0000000000 --- a/test/TestCommon/ReplaceCulture.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Globalization; -using System.Reflection; -using Xunit.Sdk; - -namespace Microsoft.AspNet.Mvc -{ - /// - /// Replaces the current culture and UI culture for the test. - /// - [AttributeUsage(AttributeTargets.Method)] - internal class ReplaceCultureAttribute : BeforeAfterTestAttribute - { - private const string _defaultCultureName = "en-GB"; - private const string _defaultUICultureName = "en-US"; - private static readonly CultureInfo _defaultCulture = new CultureInfo(_defaultCultureName); - private CultureInfo _originalCulture; - private CultureInfo _originalUICulture; - - public ReplaceCultureAttribute() - { - Culture = _defaultCulture; - UICulture = _defaultCulture; - } - - /// - /// Sets for the test. Defaults to en-GB. - /// - /// - /// en-GB is used here as the default because en-US is equivalent to the InvariantCulture. We - /// want to be able to find bugs where we're accidentally relying on the Invariant instead of the - /// user's culture. - /// - public CultureInfo Culture { get; set; } - - /// - /// Sets for the test. Defaults to en-US. - /// - public CultureInfo UICulture { get; set; } - - public override void Before(MethodInfo methodUnderTest) - { - _originalCulture = CultureInfo.DefaultThreadCurrentCulture; - _originalUICulture = CultureInfo.DefaultThreadCurrentUICulture; - - CultureInfo.DefaultThreadCurrentCulture = Culture; - CultureInfo.DefaultThreadCurrentUICulture = UICulture; - } - - public override void After(MethodInfo methodUnderTest) - { - CultureInfo.DefaultThreadCurrentCulture = _originalCulture; - CultureInfo.DefaultThreadCurrentUICulture = _originalUICulture; - } - } -} diff --git a/test/TestCommon/project.json b/test/TestCommon/project.json deleted file mode 100644 index 2c6606c6ef..0000000000 --- a/test/TestCommon/project.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "shared": "*.cs", - "dependencies": { - "xunit.abstractions": "2.0.0-aspnet-*", - "xunit.assert": "2.0.0-aspnet-*", - "xunit.core": "2.0.0-aspnet-*", - "xunit.execution": "2.0.0-aspnet-*" - }, - "configurations": { - "net45": { - "dependencies": { - "Moq": "4.2.1312.1622", - "System.Reflection": "" - } - } - } -} \ No newline at end of file