Add CulturedFactAttribute to allow tests to run in multiple cultures.

This commit is contained in:
Brad Wilson 2014-04-17 21:29:16 -07:00
Родитель fcdac68370
Коммит d73e7f7f06
15 изменённых файлов: 195 добавлений и 60 удалений

Просмотреть файл

@ -112,7 +112,7 @@ namespace Xunit.Sdk
public ITypeInfo Class { get; private set; }
/// <inheritdoc/>
public string DisplayName { get; private set; }
public virtual string DisplayName { get; private set; }
/// <inheritdoc/>
public IMethodInfo Method { get; private set; }
@ -182,7 +182,7 @@ namespace Xunit.Sdk
/// <inheritdoc/>
[SecurityCritical]
public void GetObjectData(SerializationInfo info, StreamingContext context)
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("AssemblyName", Assembly.Name);
info.AddValue("TypeName", Class.Name);

Просмотреть файл

@ -0,0 +1,10 @@
using Xunit.Sdk;
namespace Xunit
{
[XunitTestCaseDiscoverer("TestUtility.CulturedFactAttributeDiscoverer", "test.utility")]
public sealed class CulturedFactAttribute : FactAttribute
{
public CulturedFactAttribute(params string[] cultures) { }
}
}

Просмотреть файл

@ -0,0 +1,21 @@
using System.Collections.Generic;
using System.Linq;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace TestUtility
{
public class CulturedFactAttributeDiscoverer : IXunitTestCaseDiscoverer
{
public IEnumerable<IXunitTestCase> Discover(ITestCollection testCollection, IAssemblyInfo assembly, ITypeInfo testClass, IMethodInfo testMethod, IAttributeInfo factAttribute)
{
var ctorArgs = factAttribute.GetConstructorArguments().ToArray();
var cultures = Reflector.ConvertArguments(ctorArgs, new[] { typeof(string[]) }).Cast<string[]>().Single();
if (cultures == null || cultures.Length == 0)
cultures = new[] { "en-US", "fr-FR" };
return cultures.Select(culture => new CulturedXunitTestCase(testCollection, assembly, testClass, testMethod, factAttribute, culture)).ToList();
}
}
}

Просмотреть файл

@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using System.Runtime.Serialization;
using System.Security;
using System.Threading;
using System.Threading.Tasks;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace TestUtility
{
public class CulturedXunitTestCase : XunitTestCase
{
private readonly string culture;
public CulturedXunitTestCase(ITestCollection testCollection, IAssemblyInfo assembly, ITypeInfo type, IMethodInfo method, IAttributeInfo factAttribute, string culture)
: base(testCollection, assembly, type, method, factAttribute)
{
this.culture = culture;
Traits.Add("Culture", culture);
}
protected CulturedXunitTestCase(SerializationInfo info, StreamingContext context)
: base(info, context)
{
culture = info.GetString("Culture");
Traits.Add("Culture", culture);
}
public override string DisplayName
{
get { return String.Format("{0} [{1}]", base.DisplayName, culture); }
}
[SecurityCritical]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("Culture", culture);
base.GetObjectData(info, context);
}
protected override async Task RunTestsOnMethodAsync(IMessageBus messageBus,
Type classUnderTest,
object[] constructorArguments,
MethodInfo methodUnderTest,
List<BeforeAfterTestAttribute> beforeAfterAttributes,
ExceptionAggregator aggregator,
CancellationTokenSource cancellationTokenSource)
{
var executionTime = 0M;
var originalCulture = Thread.CurrentThread.CurrentCulture;
var originalUICulture = Thread.CurrentThread.CurrentUICulture;
try
{
var cultureInfo = CultureInfo.GetCultureInfo(culture);
Thread.CurrentThread.CurrentCulture = cultureInfo;
Thread.CurrentThread.CurrentUICulture = cultureInfo;
executionTime =
await RunTestWithArgumentsAsync(messageBus,
classUnderTest,
constructorArguments,
methodUnderTest,
null,
DisplayName,
beforeAfterAttributes,
aggregator,
cancellationTokenSource);
}
catch (Exception ex)
{
if (!messageBus.QueueMessage(new Xunit.Sdk.TestStarting(this, DisplayName)))
cancellationTokenSource.Cancel();
else
{
if (!messageBus.QueueMessage(new Xunit.Sdk.TestFailed(this, DisplayName, executionTime, null, ex.Unwrap())))
cancellationTokenSource.Cancel();
}
if (!messageBus.QueueMessage(new Xunit.Sdk.TestFinished(this, DisplayName, executionTime, null)))
cancellationTokenSource.Cancel();
}
finally
{
Thread.CurrentThread.CurrentCulture = originalCulture;
Thread.CurrentThread.CurrentUICulture = originalUICulture;
}
}
}
}

Просмотреть файл

@ -111,10 +111,16 @@
<Compile Include="..\..\src\common\DictionaryExtensions.cs">
<Link>Common\DictionaryExtensions.cs</Link>
</Compile>
<Compile Include="..\..\src\common\ExceptionExtensions.cs">
<Link>Common\ExceptionExtensions.cs</Link>
</Compile>
<Compile Include="..\..\src\xunit.execution\Sdk\ExceptionUtility.cs">
<Link>Common\ExceptionUtility.cs</Link>
</Compile>
<Compile Include="Abstractions\TestCollection.cs" />
<Compile Include="CulturedFactAttribute.cs" />
<Compile Include="CulturedFactAttributeDiscoverer.cs" />
<Compile Include="CulturedXunitTestCase.cs" />
<Compile Include="NSubstituteExtensions.cs" />
<Compile Include="PreserveWorkingDirectoryAttribute.cs" />
<Compile Include="Abstractions\AssemblyWrapper.cs" />

Просмотреть файл

@ -169,12 +169,12 @@ public class EqualityAssertsTests
Assert.Equal(0.11111M, 0.11444M, 2);
}
[Fact]
[CulturedFact]
public void Failure()
{
var ex = Assert.Throws<EqualException>(() => Assert.Equal(0.11111M, 0.11444M, 3));
Assert.Equal(String.Format(CultureInfo.CurrentCulture, "{0} (rounded from {1})", 0.111M, 0.11111M), ex.Expected);
Assert.Equal(String.Format(CultureInfo.CurrentCulture, "{0} (rounded from {1})", 0.114M, 0.11444M), ex.Actual);
Assert.Equal(String.Format("{0} (rounded from {1})", 0.111M, 0.11111M), ex.Expected);
Assert.Equal(String.Format("{0} (rounded from {1})", 0.114M, 0.11444M), ex.Actual);
}
}
@ -186,12 +186,12 @@ public class EqualityAssertsTests
Assert.Equal(0.11111, 0.11444, 2);
}
[Fact]
[CulturedFact]
public void Failure()
{
var ex = Assert.Throws<EqualException>(() => Assert.Equal(0.11111, 0.11444, 3));
Assert.Equal(String.Format(CultureInfo.CurrentCulture, "{0} (rounded from {1})", 0.111M, 0.11111), ex.Expected);
Assert.Equal(String.Format(CultureInfo.CurrentCulture, "{0} (rounded from {1})", 0.114M, 0.11444), ex.Actual);
Assert.Equal(String.Format("{0} (rounded from {1})", 0.111M, 0.11111), ex.Expected);
Assert.Equal(String.Format("{0} (rounded from {1})", 0.114M, 0.11444), ex.Actual);
}
}

Просмотреть файл

@ -90,6 +90,10 @@
<Project>{09ef9917-4b00-4646-8c3f-96efacc8bf51}</Project>
<Name>xunit.execution</Name>
</ProjectReference>
<ProjectReference Include="..\test.utility\test.utility.csproj">
<Project>{4fec8604-e544-43c2-979c-f0815b5770e2}</Project>
<Name>test.utility</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

Просмотреть файл

@ -47,7 +47,7 @@ public class Xunit2TheoryAcceptanceTests
Assert.Collection(results.OrderBy(r => r.TestDisplayName),
result => Assert.Equal(@"Xunit2TheoryAcceptanceTests+TheoryTests+GenericWithSerializableData.GenericTest<Int32, Object>(value1: 42, value2: null)", result.TestDisplayName),
result => Assert.Equal(@"Xunit2TheoryAcceptanceTests+TheoryTests+GenericWithSerializableData.GenericTest<Int32[], List<String>>(value1: [1, 2, 3], value2: [""a"", ""b"", ""c""])", result.TestDisplayName),
result => Assert.Equal(@"Xunit2TheoryAcceptanceTests+TheoryTests+GenericWithSerializableData.GenericTest<String, Double>(value1: ""Hello, world!"", value2: " + 21.12.ToString(CultureInfo.CurrentCulture) + ")", result.TestDisplayName)
result => Assert.Equal(String.Format(@"Xunit2TheoryAcceptanceTests+TheoryTests+GenericWithSerializableData.GenericTest<String, Double>(value1: ""Hello, world!"", value2: {0})", 21.12), result.TestDisplayName)
);
}
@ -105,7 +105,7 @@ public class Xunit2TheoryAcceptanceTests
if (passing == null)
return false;
Assert.Equal("Xunit2TheoryAcceptanceTests+InlineDataTests+ClassUnderTest.TestViaInlineData(x: 42, y: " + 21.12.ToString(CultureInfo.CurrentCulture) + ", z: \"Hello, world!\")", passing.TestDisplayName);
Assert.Equal(String.Format("Xunit2TheoryAcceptanceTests+InlineDataTests+ClassUnderTest.TestViaInlineData(x: 42, y: {0}, z: \"Hello, world!\")", 21.12), passing.TestDisplayName);
return true;
});
Assert.Single(testMessages, msg =>
@ -219,7 +219,7 @@ public class Xunit2TheoryAcceptanceTests
if (passing == null)
return false;
Assert.Equal("Xunit2TheoryAcceptanceTests+FieldDataTests+ClassWithSelfFieldData.TestViaFieldData(x: 42, y: " + 21.12.ToString(CultureInfo.CurrentCulture) + ", z: \"Hello, world!\")", passing.TestDisplayName);
Assert.Equal(String.Format("Xunit2TheoryAcceptanceTests+FieldDataTests+ClassWithSelfFieldData.TestViaFieldData(x: 42, y: {0}, z: \"Hello, world!\")", 21.12), passing.TestDisplayName);
return true;
});
Assert.Single(testMessages, msg =>
@ -338,7 +338,7 @@ public class Xunit2TheoryAcceptanceTests
if (passing == null)
return false;
Assert.Equal("Xunit2TheoryAcceptanceTests+MethodDataTests+ClassWithSelfMethodData.TestViaMethodData(x: 42, y: " + 21.12.ToString(CultureInfo.CurrentCulture) + ", z: \"Hello, world!\")", passing.TestDisplayName);
Assert.Equal(String.Format("Xunit2TheoryAcceptanceTests+MethodDataTests+ClassWithSelfMethodData.TestViaMethodData(x: 42, y: {0}, z: \"Hello, world!\")", 21.12), passing.TestDisplayName);
return true;
});
Assert.Single(testMessages, msg =>
@ -460,7 +460,7 @@ public class Xunit2TheoryAcceptanceTests
if (passing == null)
return false;
Assert.Equal("Xunit2TheoryAcceptanceTests+MethodDataTests+ClassWithParameterizedMethodData.TestViaMethodData(x: 42, y: " + 21.12.ToString(CultureInfo.CurrentCulture) + ", z: \"Hello, world!\")", passing.TestDisplayName);
Assert.Equal(String.Format("Xunit2TheoryAcceptanceTests+MethodDataTests+ClassWithParameterizedMethodData.TestViaMethodData(x: 42, y: {0}, z: \"Hello, world!\")", 21.12), passing.TestDisplayName);
return true;
});
Assert.Single(testMessages, msg =>
@ -508,7 +508,7 @@ public class Xunit2TheoryAcceptanceTests
if (passing == null)
return false;
Assert.Equal("Xunit2TheoryAcceptanceTests+PropertyDataTests+ClassWithSelfPropertyData.TestViaPropertyData(x: 42, y: " + 21.12.ToString(CultureInfo.CurrentCulture) + ", z: \"Hello, world!\")", passing.TestDisplayName);
Assert.Equal(String.Format("Xunit2TheoryAcceptanceTests+PropertyDataTests+ClassWithSelfPropertyData.TestViaPropertyData(x: 42, y: {0}, z: \"Hello, world!\")", 21.12), passing.TestDisplayName);
return true;
});
Assert.Single(testMessages, msg =>
@ -625,7 +625,7 @@ public class Xunit2TheoryAcceptanceTests
{
var testMessages = Run<ITestFailed>(typeof(ClassUnderTest));
var equalFailure = Assert.Single(testMessages, msg => msg.TestDisplayName == "Xunit2TheoryAcceptanceTests+ErrorAggregation+ClassUnderTest.TestViaInlineData(x: 42, y: " + 21.12.ToString(CultureInfo.CurrentCulture) + ", z: ClassUnderTest { })");
var equalFailure = Assert.Single(testMessages, msg => msg.TestDisplayName == String.Format("Xunit2TheoryAcceptanceTests+ErrorAggregation+ClassUnderTest.TestViaInlineData(x: 42, y: {0}, z: ClassUnderTest {{ }})", 21.12));
Assert.Contains("Assert.Equal() Failure", equalFailure.Messages.Single());
var notNullFailure = Assert.Single(testMessages, msg => msg.TestDisplayName == "Xunit2TheoryAcceptanceTests+ErrorAggregation+ClassUnderTest.TestViaInlineData(x: 0, y: 0, z: null)");

Просмотреть файл

@ -101,7 +101,7 @@ public class XmlTestExecutionVisitorTests
Assert.Null(assemblyElement.Attribute("config-file"));
}
[Fact]
[CulturedFact]
public void AddsAssemblyFinishedInformationToXml()
{
var assemblyFinished = Substitute.For<ITestAssemblyFinished>();
@ -119,10 +119,10 @@ public class XmlTestExecutionVisitorTests
Assert.Equal("2064", assemblyElement.Attribute("passed").Value);
Assert.Equal("42", assemblyElement.Attribute("failed").Value);
Assert.Equal("6", assemblyElement.Attribute("skipped").Value);
Assert.Equal(123.457M.ToString(CultureInfo.CurrentCulture), assemblyElement.Attribute("time").Value);
Assert.Equal(123.457M.ToString(), assemblyElement.Attribute("time").Value);
}
[Fact]
[CulturedFact]
public void AddsTestCollectionElementsToXml()
{
var assemblyFinished = Substitute.For<ITestAssemblyFinished>();
@ -147,10 +147,10 @@ public class XmlTestExecutionVisitorTests
Assert.Equal("2064", collectionElement.Attribute("passed").Value);
Assert.Equal("42", collectionElement.Attribute("failed").Value);
Assert.Equal("6", collectionElement.Attribute("skipped").Value);
Assert.Equal(123.457M.ToString(CultureInfo.CurrentCulture), collectionElement.Attribute("time").Value);
Assert.Equal(123.457M.ToString(), collectionElement.Attribute("time").Value);
}
[Fact]
[CulturedFact]
public void AddsPassingTestElementToXml()
{
var assemblyFinished = Substitute.For<ITestAssemblyFinished>();
@ -172,7 +172,7 @@ public class XmlTestExecutionVisitorTests
Assert.Equal("XmlTestExecutionVisitorTests+Xml+ClassUnderTest", testElement.Attribute("type").Value);
Assert.Equal("TestMethod", testElement.Attribute("method").Value);
Assert.Equal("Pass", testElement.Attribute("result").Value);
Assert.Equal(123.457M.ToString(CultureInfo.CurrentCulture), testElement.Attribute("time").Value);
Assert.Equal(123.457M.ToString(), testElement.Attribute("time").Value);
Assert.Null(testElement.Attribute("source-file"));
Assert.Null(testElement.Attribute("source-line"));
Assert.Empty(testElement.Elements("traits"));
@ -180,7 +180,7 @@ public class XmlTestExecutionVisitorTests
Assert.Empty(testElement.Elements("reason"));
}
[Fact]
[CulturedFact]
public void AddsFailingTestElementToXml()
{
var assemblyFinished = Substitute.For<ITestAssemblyFinished>();
@ -204,7 +204,7 @@ public class XmlTestExecutionVisitorTests
Assert.Equal("XmlTestExecutionVisitorTests+Xml+ClassUnderTest", testElement.Attribute("type").Value);
Assert.Equal("TestMethod", testElement.Attribute("method").Value);
Assert.Equal("Fail", testElement.Attribute("result").Value);
Assert.Equal(123.457M.ToString(CultureInfo.CurrentCulture), testElement.Attribute("time").Value);
Assert.Equal(123.457M.ToString(), testElement.Attribute("time").Value);
var failureElement = Assert.Single(testElement.Elements("failure"));
Assert.Equal("Exception Type", failureElement.Attribute("exception-type").Value);
Assert.Equal("Exception Type : Exception Message", failureElement.Elements("message").Single().Value);
@ -235,7 +235,7 @@ public class XmlTestExecutionVisitorTests
Assert.Empty(failureElement.Elements("stack-trace").Single().Value);
}
[Fact]
[CulturedFact]
public void AddsSkippedTestElementToXml()
{
var assemblyFinished = Substitute.For<ITestAssemblyFinished>();
@ -257,7 +257,7 @@ public class XmlTestExecutionVisitorTests
Assert.Equal("XmlTestExecutionVisitorTests+Xml+ClassUnderTest", testElement.Attribute("type").Value);
Assert.Equal("TestMethod", testElement.Attribute("method").Value);
Assert.Equal("Skip", testElement.Attribute("result").Value);
Assert.Equal(0.0M.ToString("0.000", CultureInfo.CurrentCulture), testElement.Attribute("time").Value);
Assert.Equal(0.0M.ToString("0.000"), testElement.Attribute("time").Value);
var reasonElement = Assert.Single(testElement.Elements("reason"));
Assert.Equal("Skip Reason", reasonElement.Value);
Assert.Empty(testElement.Elements("failure"));

Просмотреть файл

@ -1,5 +1,4 @@
using System;
using System.Globalization;
using System.Linq;
using Xunit;
using Xunit.Sdk;
@ -8,37 +7,37 @@ public class ArgumentFormatterTests
{
public class SimpleValues
{
[Fact]
[CulturedFact]
public static void NullValue()
{
Assert.Equal("null", ArgumentFormatter.Format(null));
}
[Fact]
[CulturedFact]
public static void StringValue()
{
Assert.Equal("\"Hello, world!\"", ArgumentFormatter.Format("Hello, world!"));
}
[Fact]
[CulturedFact]
public static void StringValueTruncated()
{
Assert.Equal("\"----|----1----|----2----|----3----|----4----|----5\"...", ArgumentFormatter.Format("----|----1----|----2----|----3----|----4----|----5-"));
}
[Fact]
[CulturedFact]
public static void CharacterValue()
{
Assert.Equal("'a'", ArgumentFormatter.Format('a'));
}
[Fact]
[CulturedFact]
public static void DecimalValue()
{
Assert.Equal(123.45M.ToString(CultureInfo.CurrentCulture), ArgumentFormatter.Format(123.45M));
Assert.Equal(123.45M.ToString(), ArgumentFormatter.Format(123.45M));
}
[Fact]
[CulturedFact]
public static void DateTimeValue()
{
var now = DateTime.UtcNow;
@ -46,7 +45,7 @@ public class ArgumentFormatterTests
Assert.Equal<object>(now.ToString("o"), ArgumentFormatter.Format(now));
}
[Fact]
[CulturedFact]
public static void DateTimeOffsetValue()
{
var now = DateTimeOffset.UtcNow;
@ -54,7 +53,7 @@ public class ArgumentFormatterTests
Assert.Equal<object>(now.ToString("o"), ArgumentFormatter.Format(now));
}
[Fact]
[CulturedFact]
public static void TypeValue()
{
Assert.Equal("typeof(System.String)", ArgumentFormatter.Format(typeof(string)));
@ -63,21 +62,21 @@ public class ArgumentFormatterTests
public class Enumerables
{
[Fact]
[CulturedFact]
public static void EnumerableValue()
{
var expected = String.Format("[1, {0}, \"Hello, world!\"]", 2.3M.ToString(CultureInfo.CurrentCulture));
var expected = String.Format("[1, {0}, \"Hello, world!\"]", 2.3M);
Assert.Equal(expected, ArgumentFormatter.Format(new object[] { 1, 2.3M, "Hello, world!" }));
}
[Fact]
[CulturedFact]
public static void OnlyFirstFewValuesOfEnumerableAreRendered()
{
Assert.Equal("[0, 1, 2, 3, 4, ...]", ArgumentFormatter.Format(Enumerable.Range(0, Int32.MaxValue)));
}
[Fact]
[CulturedFact]
public static void EnumerablesAreRenderedWithMaximumDepthToPreventInfiniteRecursion()
{
object[] looping = new object[2];
@ -90,10 +89,10 @@ public class ArgumentFormatterTests
public class ComplexTypes
{
[Fact]
[CulturedFact]
public static void ReturnsValuesInAlphabeticalOrder()
{
var expected = String.Format("MyComplexType {{ MyPublicField = 42, MyPublicProperty = {0} }}", 21.12M.ToString(CultureInfo.CurrentCulture));
var expected = String.Format("MyComplexType {{ MyPublicField = 42, MyPublicProperty = {0} }}", 21.12M);
Assert.Equal(expected, ArgumentFormatter.Format(new MyComplexType()));
}
@ -116,10 +115,10 @@ public class ArgumentFormatterTests
}
}
[Fact]
[CulturedFact]
public static void ComplexTypeInsideComplexType()
{
var expected = String.Format("MyComplexTypeWrapper {{ c = 'A', s = \"Hello, world!\", t = MyComplexType {{ MyPublicField = 42, MyPublicProperty = {0} }} }}", 21.12M.ToString(CultureInfo.CurrentCulture));
var expected = String.Format("MyComplexTypeWrapper {{ c = 'A', s = \"Hello, world!\", t = MyComplexType {{ MyPublicField = 42, MyPublicProperty = {0} }} }}", 21.12M);
Assert.Equal(expected, ArgumentFormatter.Format(new MyComplexTypeWrapper()));
}
@ -131,13 +130,13 @@ public class ArgumentFormatterTests
public string s = "Hello, world!";
}
[Fact]
[CulturedFact]
public static void Empty()
{
Assert.Equal("Object { }", ArgumentFormatter.Format(new object()));
}
[Fact]
[CulturedFact]
public static void WithThrowingPropertyGetter()
{
Assert.Equal("ThrowingGetter { MyThrowingProperty = (throws NotImplementedException) }", ArgumentFormatter.Format(new ThrowingGetter()));
@ -148,10 +147,12 @@ public class ArgumentFormatterTests
public string MyThrowingProperty { get { throw new NotImplementedException(); } }
}
[Fact]
[CulturedFact]
public static void LimitsOutputToFirstFewValues()
{
Assert.Equal(@"Big { MyField1 = 42, MyField2 = ""Hello, world!"", MyProp1 = 21.12, MyProp2 = typeof(ArgumentFormatterTests+ComplexTypes+Big), MyProp3 = 2014-04-17T07:45:23.0000000+00:00, ... }", ArgumentFormatter.Format(new Big()));
var expected = String.Format(@"Big {{ MyField1 = 42, MyField2 = ""Hello, world!"", MyProp1 = {0}, MyProp2 = typeof(ArgumentFormatterTests+ComplexTypes+Big), MyProp3 = 2014-04-17T07:45:23.0000000+00:00, ... }}", 21.12);
Assert.Equal(expected, ArgumentFormatter.Format(new Big()));
}
public class Big
@ -177,7 +178,7 @@ public class ArgumentFormatterTests
}
}
[Fact]
[CulturedFact]
public static void TypesAreRenderedWithMaximumDepthToPreventInfiniteRecursion()
{
Assert.Equal("Looping { Me = Looping { Me = Looping { ... } } }", ArgumentFormatter.Format(new Looping()));

Просмотреть файл

@ -195,7 +195,7 @@ public class XunitTestCaseTests
Assert.Equal("MockType.MockMethod(p1: ???)", testCase.DisplayName);
}
[Fact]
[CulturedFact]
public void TooManyTestArguments()
{
var testCollection = new XunitTestCollection();
@ -208,7 +208,7 @@ public class XunitTestCaseTests
var testCase = new XunitTestCase(testCollection, assmInfo, type, method, fact, arguments);
Assert.Equal("MockType.MockMethod(p1: 42, ???: " + 21.12.ToString(CultureInfo.CurrentCulture) + ")", testCase.DisplayName);
Assert.Equal(String.Format("MockType.MockMethod(p1: 42, ???: {0})", 21.12), testCase.DisplayName);
}
}

Просмотреть файл

@ -25,7 +25,7 @@ public class XunitTheoryTestCaseTests
var resultMessages = bus.Messages.OfType<ITestResultMessage>();
Assert.Equal(2, resultMessages.Count());
var passed = (ITestPassed)Assert.Single(resultMessages, msg => msg is ITestPassed);
Assert.Equal("XunitTheoryTestCaseTests+RunAsync+ClassUnderTest.TestWithData(x: 42, y: " + 21.12.ToString(CultureInfo.CurrentCulture) + ", z: \"Hello\")", passed.TestDisplayName);
Assert.Equal(String.Format("XunitTheoryTestCaseTests+RunAsync+ClassUnderTest.TestWithData(x: 42, y: {0}, z: \"Hello\")", 21.12), passed.TestDisplayName);
var failed = (ITestFailed)Assert.Single(resultMessages, msg => msg is ITestFailed);
Assert.Equal("XunitTheoryTestCaseTests+RunAsync+ClassUnderTest.TestWithData(x: 0, y: 0, z: \"World!\")", failed.TestDisplayName);
}

Просмотреть файл

@ -153,7 +153,7 @@ public class Xunit2Tests
Assert.Contains("TestClass.TestMethod(x: ???)", testCaseNames);
Assert.Contains("TestClass.TestMethod(x: 42)", testCaseNames);
Assert.Contains("TestClass.TestMethod(x: 42, ???: " + 21.12.ToString(CultureInfo.CurrentCulture) + ")", testCaseNames);
Assert.Contains(String.Format("TestClass.TestMethod(x: 42, ???: {0})", 21.12), testCaseNames);
}
}
}

Просмотреть файл

@ -589,8 +589,8 @@ namespace Xunit1
public void AssertEqualWithDoubleWithPrecisionFailure()
{
var ex = Assert.Throws<EqualException>(() => Assert.Equal(0.11111, 0.11444, 3));
Assert.Equal(String.Format(CultureInfo.CurrentCulture, "{0} (rounded from {1})", 0.111, 0.11111), ex.Expected);
Assert.Equal(String.Format(CultureInfo.CurrentCulture, "{0} (rounded from {1})", 0.114, 0.11444), ex.Actual);
Assert.Equal(String.Format("{0} (rounded from {1})", 0.111, 0.11111), ex.Expected);
Assert.Equal(String.Format("{0} (rounded from {1})", 0.114, 0.11444), ex.Actual);
}
[Fact]
@ -603,8 +603,8 @@ namespace Xunit1
public void AssertEqualWithDecimalWithPrecisionFailure()
{
var ex = Assert.Throws<EqualException>(() => Assert.Equal(0.11111M, 0.11444M, 3));
Assert.Equal(String.Format(CultureInfo.CurrentCulture, "{0} (rounded from {1})", 0.111M, 0.11111M), ex.Expected);
Assert.Equal(String.Format(CultureInfo.CurrentCulture, "{0} (rounded from {1})", 0.114M, 0.11444M), ex.Actual);
Assert.Equal(String.Format("{0} (rounded from {1})", 0.111M, 0.11111M), ex.Expected);
Assert.Equal(String.Format("{0} (rounded from {1})", 0.114M, 0.11444M), ex.Actual);
}
}
}

Просмотреть файл

@ -70,10 +70,7 @@ namespace Xunit1
var actualValue = MakeEnumeration(1, 2.3, "Goodbye");
string expectedMessage =
"Message" + Environment.NewLine +
"Position: First difference is at position 1" + Environment.NewLine +
"Expected: <MakeEnumeration>d__2 { 1, 42, \"Hello\" }" + Environment.NewLine +
"Actual: <MakeEnumeration>d__2 { 1, " + 2.3.ToString(CultureInfo.CurrentCulture) + ", \"Goodbye\" }";
String.Format("Message{0}Position: First difference is at position 1{0}Expected: <MakeEnumeration>d__2 {{ 1, 42, \"Hello\" }}{0}Actual: <MakeEnumeration>d__2 {{ 1, {1}, \"Goodbye\" }}", Environment.NewLine, 2.3);
AssertActualExpectedException ex =
new AssertActualExpectedException(expectedValue, actualValue, "Message");