public void CanBeExtendedToTakeAnIFixture()
        {
#pragma warning disable 612
            var stub = new AutoDataAttributeStub(new ThrowingStubFixture());
#pragma warning restore 612

            Assert.That(stub, Is.AssignableTo <AutoDataAttribute>());
        }
Beispiel #2
0
        public void FixtureFactoryIsNotInvokedImmediately()
        {
            // Arrange
            bool            wasInvoked     = false;
            Func <IFixture> fixtureFactory = () =>
            {
                wasInvoked = true;
                return(null);
            };

            // Act
            var sut = new AutoDataAttributeStub(fixtureFactory);

            // Assert
            Assert.False(wasInvoked);
        }
        public void FixtureFactoryIsNotInvokedImmediately()
        {
            // Fixture setup
            bool            wasInvoked     = false;
            Func <IFixture> fixtureFactory = () =>
            {
                wasInvoked = true;
                return(null);
            };

            // Exercise system
            var sut = new AutoDataAttributeStub(fixtureFactory);

            // Verify outcome
            Assert.False(wasInvoked);
            // Teardown
        }
        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);
        }
Beispiel #6
0
        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);
        }