public void NotEnoughData() { TheoryCommand command = new TheoryCommand(Reflector.Wrap(typeof(ParameterSpy).GetMethod("Method")), new object[] { 2 }); Assert.Throws<InvalidOperationException>(() => command.Execute(new ParameterSpy())); }
public void DisplayNameWithTooManyValues() { MethodInfo methodInfo = typeof(DummyWithAttributes).GetMethod("TheoryMethod"); TheoryCommand command = new TheoryCommand(Reflector.Wrap(methodInfo), new object[] { 42, 24.5, "Hello!" }); Assert.Equal("My display name(x: 42, y: 24.5, ???: \"Hello!\")", command.DisplayName); }
public void UsesDisplayName() { MethodInfo methodInfo = typeof(DummyWithAttributes).GetMethod("TheoryMethod"); TheoryCommand command = new TheoryCommand(Reflector.Wrap(methodInfo), new object[] { 42, 24.5 }); Assert.Equal("My display name(x: 42, y: 24.5)", command.DisplayName); }
public void TestMethodReturnPassedResult() { MethodInfo methodInfo = typeof(TestMethodCommandClass).GetMethod("TestMethod"); TheoryCommand command = new TheoryCommand(Reflector.Wrap(methodInfo), null); MethodResult result = command.Execute(new TestMethodCommandClass()); Assert.IsType<PassedResult>(result); }
public void ExecuteStubTestFixtureVerifyBeforeAfterTestCalledOnce() { MethodInfo methodInfo = typeof(DisposableSpy).GetMethod("PassedTest"); TheoryCommand command = new TheoryCommand(Reflector.Wrap(methodInfo), null); DisposableSpy.ctorCalled = 0; DisposableSpy.disposeCalled = 0; ITestResult result = command.Execute(new DisposableSpy()); Assert.IsType<PassedResult>(result); }
public void ExecuteCreatesClassAndRunsTest() { MethodInfo methodInfo = typeof(InstrumentedSpy).GetMethod("PassedTest"); TheoryCommand command = new TheoryCommand(Reflector.Wrap(methodInfo), null); InstrumentedSpy.ctorCounter = 0; InstrumentedSpy.passedTestCounter = 0; command.Execute(new InstrumentedSpy()); Assert.Equal(1, InstrumentedSpy.ctorCounter); Assert.Equal(1, InstrumentedSpy.passedTestCounter); }
public void PassesParametersToTest() { MethodInfo methodInfo = typeof(SpyWithDataPassed).GetMethod("Test"); TheoryCommand command = new TheoryCommand(Reflector.Wrap(methodInfo), new object[] { 42, 24.5, "foo" }); SpyWithDataPassed.X = 0; SpyWithDataPassed.Y = 0.0; SpyWithDataPassed.Z = null; command.Execute(new SpyWithDataPassed()); Assert.Equal(42, SpyWithDataPassed.X); Assert.Equal(24.5, SpyWithDataPassed.Y); Assert.Equal("foo", SpyWithDataPassed.Z); }
public void ThrowsExceptionReturnFailedResult() { MethodInfo methodInfo = typeof(TestMethodCommandClass).GetMethod("ThrowsException"); TheoryCommand command = new TheoryCommand(Reflector.Wrap(methodInfo), null); Assert.Throws<InvalidOperationException>(() => command.Execute(new TestMethodCommandClass())); }
public void SettingTheoryTimeoutSetsTimeout() { TheoryCommand command = new TheoryCommand(Reflector.Wrap(typeof(DummyWithAttributes).GetMethod("TimeoutMethod")), null); Assert.Equal(153, command.Timeout); }
public void TruncatesVeryLongStrings() { StringBuilder sb = new StringBuilder(500); for (int idx = 0; idx < 50; idx++) sb.Append("----=----|"); TheoryCommand command = new TheoryCommand(Reflector.Wrap(typeof(ParameterSpy).GetMethod("Method")), new object[] { 2, sb.ToString() }); MethodResult result = command.Execute(new ParameterSpy()); Assert.IsType<PassedResult>(result); Assert.Equal(@"TheoryCommandTests+ParameterSpy.Method(2, ""----=----|----=----|----=----|----=----|----=----|""...)", result.DisplayName); }
public PrefixedTreesTheoryCommand(TheoryCommand command, IMethodInfo method, string testCaseDisplayName) : base(method, string.Format("{0} {1}", command.DisplayName, testCaseDisplayName), command.Timeout) { this.command = command; }
public void StringDataWithEmbeddedNullCreatesValidXml() { string expectedDisplayName = @"TheoryCommandTests+DummyWithAttributes.StringMethod(s: ""\0"")"; string expectedXml = @"<start name=""TheoryCommandTests+DummyWithAttributes.StringMethod(s: "\0")"" type=""TheoryCommandTests+DummyWithAttributes"" method=""StringMethod"" />"; TheoryCommand command = new TheoryCommand(Reflector.Wrap(typeof(DummyWithAttributes).GetMethod("StringMethod")), new object[] { "\0" }); Assert.Equal(expectedDisplayName, command.DisplayName); Assert.Equal(expectedXml, command.ToStartXml().OuterXml); }
public void StringDataWithEmbeddedNullCreatesValidXml() // CodePlex issue #9755 { string expectedXml = @"<start name=""Xunit1.Extensions.TheoryCommandTests+DummyWithAttributes.StringMethod(s: "\x0\xFFFF")"" type=""Xunit1.Extensions.TheoryCommandTests+DummyWithAttributes"" method=""StringMethod"" />"; TheoryCommand command = new TheoryCommand(Reflector.Wrap(typeof(DummyWithAttributes).GetMethod("StringMethod")), new object[] { "\0\xffff" }); Assert.Equal(expectedXml, command.ToStartXml().OuterXml); }