예제 #1
0
    public void TestMethodReturnPassedResult()
    {
        MethodInfo method = typeof(TestMethodCommandClass).GetMethod("TestMethod");
        TestCommand command = new FactCommand(Reflector.Wrap(method));

        MethodResult result = command.Execute(new TestMethodCommandClass());

        Assert.IsType<PassedResult>(result);
    }
예제 #2
0
    public void ExecuteRunsTest()
    {
        MethodInfo method = typeof(TestMethodCommandClass).GetMethod("TestMethod");
        TestCommand command = new FactCommand(Reflector.Wrap(method));
        TestMethodCommandClass.testCounter = 0;

        command.Execute(new TestMethodCommandClass());

        Assert.Equal(1, TestMethodCommandClass.testCounter);
    }
예제 #3
0
        public void ConstructorThrowsTargetInvocationExceptionIsUnwrappedAndRethrown()
        {
            MethodInfo method = typeof(SpyWithConstructorThrow).GetMethod("PassedTest");
            IMethodInfo wrappedMethod = Reflector.Wrap(method);
            FactCommand factCommand = new FactCommand(wrappedMethod);
            LifetimeCommand command = new LifetimeCommand(factCommand, wrappedMethod);
            SpyWithConstructorThrow.Reset();

            Exception ex = Record.Exception(() => command.Execute(null));

            Assert.IsType<InvalidOperationException>(ex);
        }
예제 #4
0
        public void DisposeThrowsTestCalled()
        {
            MethodInfo method = typeof(SpyWithDisposeThrow).GetMethod("PassedTest");
            IMethodInfo wrappedMethod = Reflector.Wrap(method);
            TestCommand testCommand = new FactCommand(wrappedMethod);
            LifetimeCommand command = new LifetimeCommand(testCommand, wrappedMethod);
            SpyWithDisposeThrow.Reset();

            Record.Exception(() => command.Execute(new SpyWithDisposeThrow()));

            Assert.Equal(1, SpyWithDisposeThrow.ctorCalled);
            Assert.Equal(1, SpyWithDisposeThrow.testCalled);
            Assert.Equal(1, SpyWithDisposeThrow.disposeCalled);
        }
예제 #5
0
    public void TurnsParameterCountMismatchExceptionIntoInvalidOperationException()
    {
        Mock<IMethodInfo> method = new Mock<IMethodInfo>();
        method.SetupGet(m => m.Name)
              .Returns("StubbyName");
        method.SetupGet(m => m.TypeName)
              .Returns("StubbyType");
        method.Setup(m => m.Invoke(It.IsAny<object>(), It.IsAny<object[]>()))
              .Throws<ParamterCountMismatchException>();
        TestCommand command = new FactCommand(method.Object);

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

        Assert.IsType<InvalidOperationException>(ex);
        Assert.Equal("Fact method StubbyType.StubbyName cannot have parameters", ex.Message);
    }