Пример #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
        }
Пример #2
0
        public void ShouldRecognizeAttributesImplementingIParameterCustomizationSource()
        {
            // Fixture setup
            var method = typeof(TypeWithIParameterCustomizationSourceUsage)
                         .GetMethod(nameof(TypeWithIParameterCustomizationSourceUsage.DecoratedMethod));

            var parameters     = method.GetParameters();
            var parameterTypes = parameters.Select(p => p.ParameterType).ToArray();

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

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

            // Exercise system
            sut.GetData(method, parameterTypes);
            // Verify outcome
            Assert.True(customizationLog[0] is TypeWithIParameterCustomizationSourceUsage.Customization);
            // Teardown
        }
Пример #3
0
        public void GetDataOrdersCustomizationAttributes(string methodName)
        {
            // Fixture setup
            var method = typeof(TypeWithCustomizationAttributes).GetMethod(methodName, new[] { typeof(ConcreteType) });

            var parameters     = method.GetParameters();
            var parameterTypes = (from pi in parameters
                                  select pi.ParameterType).ToArray();

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

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

            // Exercise system
            sut.GetData(method, parameterTypes);
            // Verify outcome
            Assert.False(customizationLog[0] is FreezeOnMatchCustomization);
            Assert.True(customizationLog[1] is FreezeOnMatchCustomization);
            // Teardown
        }
Пример #4
0
        public void GetDataReturnsCorrectResult()
        {
            // Arrange
            var method         = typeof(TypeWithOverloadedMembers).GetMethod("DoSomething", new[] { typeof(object) });
            var parameters     = method.GetParameters();
            var parameterTypes = (from pi in parameters
                                  select pi.ParameterType).ToArray();

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

            var sut = new DerivedAutoDataAttribute(() => composer);
            // Act
            var result = sut.GetData(method, parameterTypes);

            // Assert
            Assert.True(new[] { expectedResult }.SequenceEqual(result.Single()));
        }
        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);
        }