コード例 #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()));
    }
コード例 #2
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);
    }
コード例 #3
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);
    }
コード例 #4
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);
    }
コード例 #5
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);
    }
コード例 #6
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()));
    }
コード例 #7
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);
    }