public void CreatesNewInstanceWhenPassedNull() { StubCommand innerCommand = new StubCommand(); MethodInfo method = typeof(StubCommand).GetMethod("Execute"); LifetimeCommand command = new LifetimeCommand(innerCommand, Reflector.Wrap(method)); command.Execute(null); Assert.NotNull(innerCommand.TestClass); }
public void DoesNotCreateNewInstanceWhenPassedExistingInstance() { StubCommand innerCommand = new StubCommand(); MethodInfo method = typeof(StubCommand).GetMethod("Execute"); LifetimeCommand command = new LifetimeCommand(innerCommand, Reflector.Wrap(method)); object instance = new object(); command.Execute(instance); Assert.Same(instance, innerCommand.TestClass); }
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); }