예제 #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()));
        }
            public override MethodResult Execute(object testClass)
            {
                var result = theory.Execute(testClass);

                InjectDataAttribute.Release(testClass.GetType());
                return(result);
            }
예제 #3
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()));
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #8
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(@"Xunit1.Extensions.TheoryCommandTests+ParameterSpy.Method(x: 2, y: ""----=----|----=----|----=----|----=----|----=----|""...)", result.DisplayName);
        }
예제 #9
0
        public void ExceptionThrownWhenInvokingTheoryCommandProperlyReported()
        {
            var methodInfo = typeof(TheoryCommandTests.TestMethodCommandClass).GetMethod("ThrowsException");
            var command    = new TheoryCommand(Reflector.Wrap(methodInfo), null);

            Exception exception = Record.Exception(() => command.Execute(new TheoryCommandTests.TestMethodCommandClass()));

            // If you get a test failure here, then there's another missing instance of "throw;" where there
            // is a call to RethrowWithNoStackTraceLoss. Specifically, for this test, it's in TheoryCommand.Execute
            // Again, it should look like:
            //
            // catch (TargetInvocationException ex)
            // {
            //     ExceptionUtility.RethrowWithNoStackTraceLoss(ex.InnerException);
            //     throw;  // <---- New line
            // }
            if (exception == null || exception.GetType() != typeof(TargetInvocationException))
            {
                throw new ExceptionNotBeingRethrownException("TheoryCommand.Execute");
            }
        }
예제 #10
0
 public override MethodResult Execute(object testClass)
 {
     return(command.Execute(testClass));
 }