Example #1
0
    public void NotEnoughData()
    {
        TheoryCommand command = new TheoryCommand(Reflector.Wrap(typeof(ParameterSpy).GetMethod("Method")),
                                                  new object[] { 2 });

        Assert.Throws<InvalidOperationException>(() => command.Execute(new ParameterSpy()));
    }
Example #2
0
    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);
    }
Example #3
0
        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);
        }
Example #4
0
    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);
    }
Example #5
0
    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);
    }
Example #6
0
    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);
    }
Example #7
0
    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);
    }
Example #8
0
    public void ThrowsExceptionReturnFailedResult()
    {
        MethodInfo methodInfo = typeof(TestMethodCommandClass).GetMethod("ThrowsException");
        TheoryCommand command = new TheoryCommand(Reflector.Wrap(methodInfo), null);

        Assert.Throws<InvalidOperationException>(() => command.Execute(new TestMethodCommandClass()));
    }
Example #9
0
    public void SettingTheoryTimeoutSetsTimeout()
    {
        TheoryCommand command = new TheoryCommand(Reflector.Wrap(typeof(DummyWithAttributes).GetMethod("TimeoutMethod")), null);

        Assert.Equal(153, command.Timeout);
    }
Example #10
0
    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);
    }
Example #11
0
		public PrefixedTreesTheoryCommand(TheoryCommand command, IMethodInfo method, string testCaseDisplayName)
			: base(method, string.Format("{0} {1}", command.DisplayName, testCaseDisplayName), command.Timeout)
		{
			this.command = command;
		}
Example #12
0
    public void StringDataWithEmbeddedNullCreatesValidXml()
    {
        string expectedDisplayName = @"TheoryCommandTests+DummyWithAttributes.StringMethod(s: ""\0"")";
        string expectedXml = @"<start name=""TheoryCommandTests+DummyWithAttributes.StringMethod(s: &quot;\0&quot;)"" 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);
    }
Example #13
0
        public void StringDataWithEmbeddedNullCreatesValidXml()  // CodePlex issue #9755
        {
            string expectedXml = @"<start name=""Xunit1.Extensions.TheoryCommandTests+DummyWithAttributes.StringMethod(s: &quot;\x0\xFFFF&quot;)"" 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);
        }