public void IfCreateParametersThrowsExceptionThenReturnsNotRunnableTestMethodWithExceptionInfoAsSkipReason() { // Arrange // DummyFixture is set up to throw DummyException when invoked by AutoDataAttribute var inlineAutoDataAttributeStub = new InlineAutoDataAttributeStub(() => new ThrowingStubFixture()); var fixtureType = this.GetType(); var methodWrapper = new MethodWrapper(fixtureType, fixtureType.GetMethod(nameof(this.DummyTestMethod))); var testSuite = new TestSuite(fixtureType); // Act var testMethod = inlineAutoDataAttributeStub.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 InlineAutoDataAttributeStub(() => fixture); // Act sut.BuildFrom(method, new TestSuite(this.GetType())).Single(); // Assert Assert.False(customizationLog[0] is FreezeOnMatchCustomization); Assert.True(customizationLog[1] is FreezeOnMatchCustomization); }
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 InlineAutoDataAttributeStub(() => fixture, new[] { 42 }); // Act sut.BuildFrom(method, new TestSuite(this.GetType())).ToArray(); // Assert Assert.True(customizationLog[0] is TypeWithIParameterCustomizationSourceUsage.Customization); }