public static void Overrides() { var testMethod = Mocks.TestMethod("MockType", "Mock_Method"); var arguments = new object[] { 42, 21.12, "Hello world!" }; var traits = new Dictionary <string, List <string> > { { "FOO", new List <string> { "BAR" } } }; var testCase = new TestableTestMethodTestCase( testMethod, arguments, TestMethodDisplay.Method, TestMethodDisplayOptions.ReplaceUnderscoreWithSpace, "Skip me!", traits, "test-case-custom-id" ); Assert.Equal($"Mock Method(???: 42, ???: {21.12:G17}, ???: \"Hello world!\")", testCase.TestCaseDisplayName); Assert.Equal("Skip me!", testCase.SkipReason); Assert.Same(arguments, testCase.TestMethodArguments); Assert.Collection( testCase.Traits, kvp => { Assert.Equal("FOO", kvp.Key); Assert.Equal("BAR", Assert.Single(kvp.Value)); } ); Assert.Equal("test-case-custom-id", testCase.UniqueID); }
public static void OverrideDefaultMethodDisplay(TestMethodDisplay methodDisplay, string expectedDisplayName) { var testMethod = Mocks.TestMethod(typeof(DisplayName), "OverrideDefaultMethodDisplay"); var testCase = new TestableTestMethodTestCase(testMethod, defaultMethodDisplay: methodDisplay); Assert.Equal(expectedDisplayName, testCase.DisplayName); }
public static void NotEnoughTestArguments() { var param = Mocks.ParameterInfo("p1"); var testMethod = Mocks.TestMethod(parameters: new[] { param }); var testCase = new TestableTestMethodTestCase(testMethod, new object[0]); Assert.Equal("MockType.MockMethod(p1: ???)", testCase.DisplayName); }
public static void CanRoundTrip_PublicClass_PublicTestMethod() { var testCase = TestableTestMethodTestCase.Create <Serialization>("CanRoundTrip_PublicClass_PublicTestMethod"); var serialized = XunitSerializationInfo.Serialize(testCase); var deserialized = XunitSerializationInfo.Deserialize(typeof(TestableTestMethodTestCase), serialized); Assert.NotNull(deserialized); }
public static void TooManyTestArguments() { var param = Mocks.ParameterInfo("p1"); var testMethod = Mocks.TestMethod(parameters: new[] { param }); var arguments = new object[] { 42, 21.12M }; var testCase = new TestableTestMethodTestCase(testMethod, arguments); Assert.Equal(String.Format("MockType.MockMethod(p1: 42, ???: {0})", 21.12), testCase.DisplayName); }
public static void UniqueID_Arguments() { var value42 = TestableTestMethodTestCase.Create <ClassUnderTest>("TestMethod", new object[] { 42 }).UniqueID; var valueHelloWorld = TestableTestMethodTestCase.Create <ClassUnderTest>("TestMethod", new object[] { "Hello, world!" }).UniqueID; var valueNull = TestableTestMethodTestCase.Create <ClassUnderTest>("TestMethod", new object[] { (string)null }).UniqueID; Assert.NotEmpty(value42); Assert.NotEqual(value42, valueHelloWorld); Assert.NotEqual(value42, valueNull); }
public static void DefaultBehavior() { var testMethod = Mocks.TestMethod("MockType", "MockMethod"); var testCase = new TestableTestMethodTestCase(testMethod); Assert.Equal("MockType.MockMethod", testCase.DisplayName); Assert.Null(testCase.SkipReason); Assert.Empty(testCase.Traits); }
public static void TooManyTestArguments() { var param = Mocks.ParameterInfo("p1"); var testMethod = Mocks.TestMethod(parameters: new[] { param }); var arguments = new object[] { 42, 21.12M }; var testCase = new TestableTestMethodTestCase(testMethod, arguments); Assert.Equal($"{testMethod.TestClass.Class.Name}.{testMethod.Method.Name}(p1: 42, ???: {21.12})", testCase.TestCaseDisplayName); }
public static void CanRoundTrip_PublicClass_PublicTestMethod() { var serializer = new BinaryFormatter(); var testCase = TestableTestMethodTestCase.Create <Serialization>("CanRoundTrip_PublicClass_PublicTestMethod"); var memoryStream = new MemoryStream(); serializer.Serialize(memoryStream, testCase); memoryStream.Position = 0; serializer.Deserialize(memoryStream); // Should not throw }
public static void CanRoundTrip_PublicClass_PrivateTestMethod() { var serializer = new BinaryFormatter(); var testCase = TestableTestMethodTestCase.Create <Serialization>("CanRoundTrip_PublicClass_PrivateTestMethod"); var memoryStream = new MemoryStream(); serializer.Serialize(memoryStream, testCase); memoryStream.Position = 0; Assert.DoesNotThrow(() => serializer.Deserialize(memoryStream)); }
public static void CorrectNumberOfTestArguments() { var param1 = Mocks.ParameterInfo("p1"); var param2 = Mocks.ParameterInfo("p2"); var param3 = Mocks.ParameterInfo("p3"); var testMethod = Mocks.TestMethod(parameters: new[] { param1, param2, param3 }); var arguments = new object[] { 42, "Hello, world!", 'A' }; var testCase = new TestableTestMethodTestCase(testMethod, arguments); Assert.Equal("MockType.MockMethod(p1: 42, p2: \"Hello, world!\", p3: 'A')", testCase.DisplayName); }
public static void DisposesArguments() { var disposable1 = Substitute.For <IDisposable>(); var disposable2 = Substitute.For <IDisposable>(); var testMethod = Mocks.TestMethod(); var testCase = new TestableTestMethodTestCase(testMethod, new[] { disposable1, disposable2 }); testCase.Dispose(); disposable1.Received(1).Dispose(); disposable2.Received(1).Dispose(); }
public static async ValueTask DisposesArguments() { var disposable = new SerializableDisposable(); var asyncDisposable = new SerializableAsyncDisposable(); var testMethod = Mocks.TestMethod(); var testCase = new TestableTestMethodTestCase(testMethod, new object[] { disposable, asyncDisposable }); await testCase.DisposeAsync(); Assert.True(disposable.DisposeCalled); Assert.True(asyncDisposable.DisposeAsyncCalled); }
public static void DefaultBehavior() { var testMethod = Mocks.TestMethod("MockType", "MockMethod"); var testCase = new TestableTestMethodTestCase(testMethod); Assert.Equal("MockType.MockMethod", testCase.DisplayName); Assert.Null(testCase.InitializationException); Assert.Same(testMethod.Method, testCase.Method); Assert.Null(testCase.SkipReason); Assert.Null(testCase.SourceInformation); Assert.Same(testMethod, testCase.TestMethod); Assert.Null(testCase.TestMethodArguments); Assert.Empty(testCase.Traits); Assert.Equal("4428bc4e444a8f5294832dc06425f20fc994bdc44788f03219b7237f892bffe0", testCase.UniqueID); }
public static void UniqueID_NoArguments() { var value = TestableTestMethodTestCase.Create <ClassUnderTest>("TestMethod").UniqueID; Assert.NotEmpty(value); }