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); }
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); }
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); }
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); }
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); }