public void IfCreateParametersThrowsExceptionThenReturnsNotRunnableTestMethodWithExceptionInfoAsSkipReason() { // Arrange // DummyFixture is set up to throw DummyException when invoked by AutoDataAttribute var autoDataAttributeStub = new AutoDataAttributeStub(() => new ThrowingStubFixture()); var fixtureType = this.GetType(); var methodWrapper = new MethodWrapper(fixtureType, fixtureType.GetMethod("DummyTestMethod")); var testSuite = new TestSuite(fixtureType); // Act var testMethod = autoDataAttributeStub.BuildFrom(methodWrapper, testSuite).First(); // Assert Assert.That(testMethod.RunState == RunState.NotRunnable); Assert.That(testMethod.Properties.Get(PropertyNames.SkipReason), Is.EqualTo(ExceptionHelper.BuildMessage(new ThrowingStubFixture.DummyException()))); }
public void GetDataOrdersCustomizationAttributes(string methodName) { // Arrange var method = new MethodWrapper(typeof(TypeWithCustomizationAttributes), methodName); var customizationLog = new List <ICustomization>(); var fixture = new DelegatingFixture(); fixture.OnCustomize = c => { customizationLog.Add(c); return(fixture); }; var sut = new AutoDataAttributeStub(() => fixture); // Assert sut.BuildFrom(method, new TestSuite(this.GetType())).Single(); // Assert Assert.False(customizationLog[0] is FreezeOnMatchCustomization); Assert.True(customizationLog[1] is FreezeOnMatchCustomization); }
public void BuildFromDontActivateFixtureIfArgsValuesAreNotUsedByTestBuilder() { // Arrange bool wasActivated = false; var sut = new AutoDataAttributeStub(() => { wasActivated = true; return(null); }); sut.TestMethodBuilder = new TestMethodBuilderWithoutParametersUsage(); var methodWrapper = new MethodWrapper(this.GetType(), nameof(this.DummyTestMethod)); var testSuite = new TestSuite(this.GetType()); // Assert var dummy = sut.BuildFrom(methodWrapper, testSuite).ToArray(); // Assert Assert.IsFalse(wasActivated); }
public void ShouldRecognizeAttributesImplementingIParameterCustomizationSource() { // Arrange var method = new MethodWrapper( typeof(TypeWithIParameterCustomizationSourceUsage), nameof(TypeWithIParameterCustomizationSourceUsage.DecoratedMethod)); var customizationLog = new List <ICustomization>(); var fixture = new DelegatingFixture(); fixture.OnCustomize = c => { customizationLog.Add(c); return(fixture); }; var sut = new AutoDataAttributeStub(() => fixture); // Assert sut.BuildFrom(method, new TestSuite(this.GetType())).ToArray(); // Assert Assert.True(customizationLog[0] is TypeWithIParameterCustomizationSourceUsage.Customization); }