public void BeforeThrowsAfterThrowsShouldResultInBeforeException() { MethodInfo methodInfo = typeof(MultipleAttributeSpy).GetMethod("PassedTest"); StubTestCommand stub = new StubTestCommand(); BeforeAfterCommand command = new BeforeAfterCommand(stub, methodInfo); BeforeAfterSpyAttribute.Reset(); BeforeAfterSpyAttribute.beforeTestThrowCount = 2; BeforeAfterSpyAttribute.afterTestThrowCount = 1; Assert.Throws <Exception>(() => command.Execute(new MultipleAttributeSpy())); }
public void MethodUnderTestProvidedToBeforeAfter() { MethodInfo methodInfo = typeof(InstrumentedTestClass).GetMethod("PassedTest"); StubTestCommand stub = new StubTestCommand(); BeforeAfterCommand command = new BeforeAfterCommand(stub, methodInfo); InstrumentedTestClass.Reset(); command.Execute(new InstrumentedTestClass()); Assert.Same(methodInfo, BeforeAfterSpyAttribute.beforeMethod); Assert.Same(methodInfo, BeforeAfterSpyAttribute.afterMethod); }
public void TestThrowsAfterThrowsShouldResultInTestException() { MethodInfo methodInfo = typeof(MultipleAttributeSpy).GetMethod("PassedTest"); StubTestCommand stub = new StubTestCommand { ThrowsOnExecute = true }; BeforeAfterCommand command = new BeforeAfterCommand(stub, methodInfo); BeforeAfterSpyAttribute.Reset(); BeforeAfterSpyAttribute.afterTestThrowCount = 1; Assert.Throws <Exception>(() => command.Execute(new InstrumentedTestClass())); }
public void MultipleBeforeAfterTestAttributesAllCalled() { MethodInfo methodInfo = typeof(BeforeAfterDoubleSpy).GetMethod("PassedTest"); StubTestCommand stub = new StubTestCommand(); BeforeAfterCommand command = new BeforeAfterCommand(stub, methodInfo); BeforeAfterDoubleSpy.Reset(); command.Execute(new BeforeAfterDoubleSpy()); Assert.Equal(2, BeforeAfterSpyAttribute.beforeTestCount); Assert.Equal(1, stub.ExecuteCount); Assert.Equal(2, BeforeAfterSpyAttribute.afterTestCount); }
public void VerifyBeforeAfterTestAttributeCalledOnce() { MethodInfo method = typeof(SimpleTestFixtureSpy).GetMethod("PassedTest"); BeforeAfterCommand command = new BeforeAfterCommand(new FactCommand(Reflector.Wrap(method)), method); SimpleTestFixtureSpy.Reset(); ITestResult result = command.Execute(new SimpleTestFixtureSpy()); Assert.Equal(1, BeforeAfterSpyAttribute.beforeTestCount); Assert.Equal(1, BeforeAfterSpyAttribute.afterTestCount); Assert.Equal("ctor beforetest test aftertest ", SimpleTestFixtureSpy.callOrder); Assert.IsType <PassedResult>(result); }
public void MultipleBeforeTestsSecondThrows() { MethodInfo methodInfo = typeof(MultipleAttributeSpy).GetMethod("PassedTest"); StubTestCommand stub = new StubTestCommand(); BeforeAfterCommand command = new BeforeAfterCommand(stub, methodInfo); BeforeAfterSpyAttribute.Reset(); BeforeAfterSpyAttribute.beforeTestThrowCount = 2; Assert.Throws <Exception>(() => command.Execute(new MultipleAttributeSpy())); Assert.Equal(2, BeforeAfterSpyAttribute.beforeTestCount); Assert.Equal(0, stub.ExecuteCount); Assert.Equal(1, BeforeAfterSpyAttribute.afterTestCount); }
public void AfterTestThrows() { MethodInfo methodInfo = typeof(InstrumentedTestClass).GetMethod("PassedTest"); StubTestCommand stub = new StubTestCommand(); BeforeAfterCommand command = new BeforeAfterCommand(stub, methodInfo); InstrumentedTestClass.Reset(); BeforeAfterSpyAttribute.afterTestThrowCount = 1; Assert.Throws <AfterTestException>(() => command.Execute(new InstrumentedTestClass())); Assert.Equal(1, BeforeAfterSpyAttribute.beforeTestCount); Assert.Equal(1, stub.ExecuteCount); Assert.Equal(1, BeforeAfterSpyAttribute.afterTestCount); }