コード例 #1
0
 public ComposableCustomizationOptions(IFixture fixture, ICustomization customization)
 {
     _customizations = new List <ICustomization> {
         customization
     };
     _fixture = fixture;
 }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WithCustomizationAttribute"/> class.
        /// </summary>
        /// <param name="customizationType">Type of the customization.</param>
        /// <exception cref="ArgumentNullException">customizationType</exception>
        /// <exception cref="ArgumentException">customizationType or customizationType</exception>
        public WithCustomizationAttribute(Type customizationType)
        {
            if (customizationType == null)
            {
                throw new ArgumentNullException("customizationType");
            }
            if (!typeof(ICustomization).IsAssignableFrom(customizationType))
            {
                throw new ArgumentException(string.Format(
                                                CultureInfo.CurrentCulture,
                                                "{0} is not compatible with ICustomization. Please supply a Type which implements ICustomization.",
                                                customizationType),
                                            "customizationType");
            }

            var ctor = customizationType.GetConstructor(Type.EmptyTypes);

            if (ctor == null)
            {
                throw new ArgumentException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              "{0} has no default constructor. Please supply a a Type that implements ICustomization and has a default constructor.",
                              customizationType),
                          "customizationType");
            }

            _customization = (ICustomization)ctor.Invoke(null);
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultDataAttribute"/> class with default customization
 /// and others to apply.
 /// </summary>
 /// <param name="defaultCustomization">The default <see cref="ICustomization"/> instance.</param>
 /// <param name="customizationTypes">Other <see cref="ICustomization"/> types to apply.</param>
 public DefaultDataAttribute(ICustomization defaultCustomization, params Type[] customizationTypes)
     : this(defaultCustomization)
 {
     this.Fixture.Customize(
         new CompositeCustomization(
             customizationTypes.Select(t =>
                                       (ICustomization)Activator.CreateInstance(t, null))));
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultDataAttribute"/> class with default customization
 /// and others to apply.
 /// </summary>
 /// <param name="defaultCustomization">The default <see cref="ICustomization"/> instance.</param>
 /// <param name="customizationTypes">Other <see cref="ICustomization"/> types to apply.</param>
 public DefaultDataAttribute(ICustomization defaultCustomization, params Type[] customizationTypes)
     : this(defaultCustomization)
 {
     this.Fixture.Customize(
         new CompositeCustomization(
             customizationTypes.Select(t =>
                 (ICustomization)Activator.CreateInstance(t, null))));
 }
コード例 #5
0
        public void Applies_customization_to_target(ICustomization <TestType> customization, TestType target)
        {
            var customizations = new[] { customization };

            CustomizationExtensions.ApplyTo(customizations, target);

            Mock.Get(customization).Verify(p => p.Customize(target), Times.Once());
        }
コード例 #6
0
ファイル: Fixture.cs プロジェクト: ErikSchierboom/AutoFixture
        /// <summary>
        /// Applies a customization.
        /// </summary>
        /// <param name="customization">The customization to apply.</param>
        /// <returns>
        /// The current instance.
        /// </returns>
        public IFixture Customize(ICustomization customization)
        {
            if (customization == null)
            {
                throw new ArgumentNullException(nameof(customization));
            }

            customization.Customize(this);
            return(this);
        }
コード例 #7
0
 public AutoDataAttribute(ICustomization customization)
     : this(() => new Fixture
 {
     Behaviors =
     {
         new OmitOnRecursionBehavior(),
     },
 }.Customize(customization))
 {
 }
コード例 #8
0
 private void CustomizeFixture(ParameterInfo parameter)
 {
     foreach (Attribute attribute in parameter.GetCustomAttributes())
     {
         switch (attribute)
         {
         case IParameterCustomizationSource source:
             IFixture       fixture       = _fixture.Value;
             ICustomization customization = source.GetCustomization(parameter);
             fixture.Customize(customization);
             break;
         }
     }
 }
        public void GivenMemberAutoMockData_WhenShareFixtureIsSetToTrue_ThenSameFixturePerDataRowIsUsed(int index, ICustomization customization, IFixture fixture)
        {
            // Arrange
            var expectedCostomizationsCount = 20;

            // Act
            var customizations = fixture.Customize(customization);

            // Assert
            fixture.Customizations.Should().HaveCount(expectedCostomizationsCount + index);
        }
コード例 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultDataAttribute"/> class with default customization.
 /// </summary>
 /// <param name="defaultCustomization">The default <see cref="ICustomization"/> instance.</param>
 public DefaultDataAttribute(ICustomization defaultCustomization)
     : base(new Fixture().Customize(defaultCustomization))
 { }
コード例 #11
0
 public IFixture BuildWith(ICustomization autoFixtureCustomization)
 {
     return(_autoFixtureCache.GetOrAdd(autoFixtureCustomization.GetType(),
                                       type => new Fixture().Customize(autoFixtureCustomization)));
 }
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultDataAttribute"/> class with default customization
 /// and others to apply.
 /// </summary>
 /// <param name="defaultCustomization">The default <see cref="ICustomization"/> instance.</param>
 /// <param name="customizationTypes">Other <see cref="ICustomization"/> types to apply.</param>
 public DefaultDataAttribute(ICustomization defaultCustomization, params Type[] customizationTypes)
 {
     _defaultCustomization = defaultCustomization;
     _customizationTypes   = customizationTypes;
 }
コード例 #13
0
 public void ClearCustomization()
 {
     _customization = null;
 }
コード例 #14
0
 protected AutoDataAttribute(IEnumerable <ISpecimenBuilderTransformation> transformations,
                             ICustomization customization)
     : this(new Fixtures(new EngineParts(transformations.Open()), customization))
 {
 }
コード例 #15
0
 public IFixture BuildWith(ICustomization autoFixtureCustomization)
 {
     return autoFixtureCache.GetOrAdd(autoFixtureCustomization.GetType(), type => new Fixture().Customize(autoFixtureCustomization));
 }
コード例 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultDataAttribute"/> class with default customization.
 /// </summary>
 /// <param name="defaultCustomization">The default <see cref="ICustomization"/> instance.</param>
 public DefaultDataAttribute(ICustomization defaultCustomization)
     : base(new Fixture().Customize(defaultCustomization))
 {
 }
コード例 #17
0
 protected CustomDataSourceAttribute(ICustomization customization) : base(() =>
                                                                          new Fixture().Customize(new CompositeCustomization(
                                                                                                      new AutoMoqCustomization(),
                                                                                                      customization)))
 {
 }
コード例 #18
0
ファイル: Fixtures.cs プロジェクト: pvandasler/Super.NET
 public Fixtures(DefaultRelays relays, ICustomization customization)
 {
     _relays        = relays;
     _customization = customization;
 }
コード例 #19
0
 public PageRendererDataAttribute(ICustomization customization, params object[] values)
     : base(new AutoDataAttribute(new Fixture().Customize(customization)), values)
 {
 }
コード例 #20
0
 public TemplateDataAttribute(ICustomization customization, params object[] values)
     : base(new AutoDataAttribute(new Fixture().Customize(customization)), values)
 {
 }
コード例 #21
0
        public static IComposableCustomizationOptions Compose(this IFixture fixture, ICustomization customization)
        {
            fixture = fixture ?? throw new ArgumentNullException(nameof(fixture));

            return(new ComposableCustomizationOptions(fixture, customization));
        }
コード例 #22
0
 protected void EnableCustomization(ICustomization customization)
 {
     customization.Customize(FixtureRepository);
 }
コード例 #23
0
ファイル: FixtureStub.cs プロジェクト: zvirja/AutoFixture
 IFixture IFixture.Customize(ICustomization customization) =>
 throw new NotSupportedException();
コード例 #24
0
 public IFixture Customize(ICustomization customization)
 {
     throw new NotImplementedException();
 }
コード例 #25
0
 /// <inheritdoc />
 public void AddCustomization(ICustomization customization)
 {
     _fixture.Customize(customization);
 }
        public void GivenMemberAutoMockData_WhenShareFixtureIsSetToFalse_ThenUniqueFixturePerDataRowIsCreated(ICustomization customization, IFixture fixture)
        {
            // Arrange
            var expectedCostomizationsCount = 20;

            // Act
            var customizations = fixture.Customize(customization);

            // Assert
            fixture.Customizations.Should().HaveCount(expectedCostomizationsCount);
        }
コード例 #27
0
 /// <summary>
 /// Customize Fixture behavior
 /// </summary>
 /// <param name="fixture"></param>
 /// <param name="customization"></param>
 public static void EnableCustomization(this IFixture fixture, ICustomization customization)
 {
     customization.Customize(fixture);
 }
 /// <summary>
 ///     Constructor
 /// </summary>
 public OmitAutoPropertiesTrueCompositeCustomization(ICustomization customization)
     : base(new OmitAutoPropertiesTrueCustomization(), customization)
 {
 }
コード例 #29
0
 protected ControllerDataSourceAttribute(ICustomization customization)
     : base(new CompositeCustomization(customization, new ControllerCustomization()))
 {
 }
コード例 #30
0
 protected AutoDataAttribute(ICustomization customization,
                             params ISpecimenBuilderTransformation[] transformations)
     : this(transformations, customization)
 {
 }
コード例 #31
0
 protected AccountDataSourceAttribute(ICustomization customization)
     : base(new CompositeCustomization(new AccountCustomization(), customization))
 {
 }
コード例 #32
0
 public IFixture Customize(ICustomization customization)
 {
     return(this.OnCustomize(customization));
 }
コード例 #33
0
 public void SetCustomization(ICustomization customization)
 {
     _customization = customization;
 }