コード例 #1
0
        public void CustomizeWithoutSpecimenValueAddsCustomizationToFixture()
        {
            var fixture            = new Fixture();
            var fixtureMock        = new Mock <IFixture>();
            var customizationsMock = new Mock <IList <ISpecimenBuilder> >();
            var declaringType      = typeof(ParameterCustomizationTests);
            var parameterName      = fixture.Create <string>();
            var sut = new SutAlias(declaringType, parameterName);

            fixtureMock.SetupGet(f => f.Customizations).Returns(customizationsMock.Object);

            sut.Customize(fixtureMock.Object);

            customizationsMock.Verify(
                c => c.Add(It.Is <ParameterSpecimenBuilder>(p =>
                                                            p.DeclaringType == declaringType &&
                                                            p.ParameterName == parameterName &&
                                                            p.SpecimenValue == null)),
                Times.Once());
        }
コード例 #2
0
        /// <summary>
        /// Gets a customization that applies a known value to the specified parameter.
        /// </summary>
        /// <param name="parameter">The parameter that the known value will be applied to.</param>
        /// <returns>The customization that will apply a known value to a parameter.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="parameter"/> is
        /// <see langword="null"/>.</exception>
        public override ICustomization GetCustomization(ParameterInfo parameter)
        {
            ParameterValidation.IsNotNull(parameter, nameof(parameter));

            ICustomization customization;

            if (this.SpecimenValue == null)
            {
                customization = new ParameterCustomization(
                    parameter.ParameterType,
                    this.ParameterName);
            }
            else
            {
                customization = new ParameterCustomization(
                    parameter.ParameterType,
                    this.ParameterName,
                    this.SpecimenValue);
            }

            return(customization);
        }