Beispiel #1
0
        public void GetArgumentsReturnsCorrectResult()
        {
            // Fixture setup
            var method     = typeof(TypeWithOverloadedMembers).GetMethod("DoSomething", new[] { typeof(object) });
            var parameters = method.GetParameters();

            var expectedResult = new object();
            var builder        = new DelegatingSpecimenBuilder
            {
                OnCreate = (r, c) =>
                {
                    Assert.AreEqual(parameters.Single(), r);
                    Assert.NotNull(c);
                    return(expectedResult);
                }
            };
            var composer = new DelegatingFixture {
                OnCreate = builder.OnCreate
            };

            var sut = new DerivedAutoDataAttribute(() => composer);
            // Exercise system
            var result = sut.GetData(method);

            // Verify outcome
            Assert.True(new[] { expectedResult }.SequenceEqual(result.Single()));
            // Teardown
        }
        public void InitializedWithComposerHasCorrectComposer()
        {
            // Arrange
            var expectedComposer = new DelegatingFixture();

#pragma warning disable 612
            var sut = new DerivedAutoDataAttribute(expectedComposer);
#pragma warning restore 612
            // Act
#pragma warning disable 618
            var result = sut.Fixture;
#pragma warning restore 618
            // Assert
            Assert.AreEqual(expectedComposer, result);
        }
Beispiel #3
0
        public void InitializedWithComposerHasCorrectComposer()
        {
            // Fixture setup
            var expectedComposer = new DelegatingFixture();

#pragma warning disable 612
            var sut = new DerivedAutoDataAttribute(expectedComposer);
#pragma warning restore 612
            // Exercise system
#pragma warning disable 618
            var result = sut.Fixture;
#pragma warning restore 618
            // Verify outcome
            Assert.AreEqual(expectedComposer, result);
            // Teardown
        }
        public void GetDataOrdersCustomizationAttributes(string methodName)
        {
            // Arrange
            var method           = typeof(TypeWithCustomizationAttributes).GetMethod(methodName, new[] { typeof(ConcreteType) });
            var customizationLog = new List <ICustomization>();
            var fixture          = new DelegatingFixture();

            fixture.OnCustomize = c =>
            {
                customizationLog.Add(c);
                return(fixture);
            };
            var sut = new DerivedAutoDataAttribute(() => fixture);

            // Act
            sut.GetData(method);
            // Assert
            Assert.False(customizationLog[0] is FreezeOnMatchCustomization);
            Assert.True(customizationLog[1] is FreezeOnMatchCustomization);
        }
        public void ShouldRecognizeAttributesImplementingIParameterCustomizationSource()
        {
            // Arrange
            var method = typeof(TypeWithIParameterCustomizationSourceUsage)
                         .GetMethod(nameof(TypeWithIParameterCustomizationSourceUsage.DecoratedMethod));

            var customizationLog = new List <ICustomization>();
            var fixture          = new DelegatingFixture();

            fixture.OnCustomize = c =>
            {
                customizationLog.Add(c);
                return(fixture);
            };
            var sut = new DerivedAutoDataAttribute(() => fixture);

            // Act
            sut.GetData(method);
            // Assert
            Assert.True(customizationLog[0] is TypeWithIParameterCustomizationSourceUsage.Customization);
        }