public static IPostprocessComposer <T> With <T, TProperty, TValue>(
     this IPostprocessComposer <T> composer,
     Expression <Func <T, TProperty> > propertyPicker,
     TValue value)
 {
     return(composer.With(propertyPicker, Convert <TValue, TProperty>(value)));
 }
Esempio n. 2
0
        public static IPostprocessComposer <Dream> WithImage(this IPostprocessComposer <Dream> postProcessComposer, int imageSize = 256)
        {
            var fixture  = new Fixture();
            var newImage = fixture.ImageBuilder(imageSize).Create();

            return(postProcessComposer.With(d => d.DreamImage, newImage));
        }
Esempio n. 3
0
 public static IPostprocessComposer <Build> WithBuildConfigSummary(
     this IPostprocessComposer <Build> composer, BuildConfig buildConfig)
 {
     return(composer
            .With(x => x.BuildConfig, (BuildConfigSummary)buildConfig)
            .With(x => x.BuildTypeId, buildConfig.Id));
 }
 public static IPostprocessComposer <T> Json <T, TProperty, TValue>(
     this IPostprocessComposer <T> composer,
     Expression <Func <T, TProperty> > propertyPicker,
     TValue value)
 {
     return(composer.With(propertyPicker, Serialize(value)));
 }
Esempio n. 5
0
        public static T Freeze <T>(this IPostprocessComposer <T> composer, Fixture fixture)

        {
            var obj = ((ISpecimenBuilder)composer).Create <T>();

            fixture.Inject(obj);
            return(obj);
        }
        /// <summary>
        /// Registers that a writable property should be assigned to the result of calling
        /// the specified factory function as part of specimen post-processing.
        /// </summary>
        /// <typeparam name="TModel">The type of the model.</typeparam>
        /// <typeparam name="TProperty">The type of the property.</typeparam>
        /// <param name="composer">The composer.</param>
        /// <param name="property">The property.</param>
        /// <param name="factory">The factory.</param>
        /// <returns></returns>
        public static IPostprocessComposer <TModel> With <TModel, TProperty>(this IPostprocessComposer <TModel> composer,
                                                                             Expression <Func <TModel, TProperty> > property,
                                                                             Func <TProperty> factory)
        {
            var info = property.GetProperty();

            return(composer.Without(property).Do(x => info.SetValue(x, factory())));
        }
Esempio n. 7
0
 public static IPostprocessComposer <Project> WithBuildConfigSummary(
     this IPostprocessComposer <Project> composer, BuildConfig buildConfig)
 {
     return(composer.With(x => x.BuildConfigs, new List <BuildConfigSummary>()
     {
         (BuildConfigSummary)buildConfig
     }));
 }
        public CsvDbUpdateClassifierArticleTests()
        {
            _fixture = new Fixture().Customize(new AutoConfiguredMoqCustomization()).Customize(new MultipleCustomization());
            _postProcessFieldComposer = _fixture.Build <Field>().FromFactory(CsvDbUpdateTestHelpers.GenerateField(_fixture)).OmitAutoProperties();
            _fixture.Customize <Field>(composer => _postProcessFieldComposer);

            QPContext.CurrentDbConnectionString = _fixture.Create <string>();
            LogProvider.LogFactory = new NullLogFactory();
        }
        /// <summary>
        /// Returns a new <see cref="BehaviorPostprocessComposer{T}"/> that decorates the new
        /// composer, but otherwise preserves other state information of the instance (such as the
        /// <see cref="Behaviors"/>.
        /// </summary>
        /// <param name="newComposer">The new composer to decorate.</param>
        /// <returns>
        /// A new <see cref="BehaviorPostprocessComposer{T}"/> that decorates
        /// <paramref name="newComposer"/>.
        /// </returns>
        public BehaviorPostprocessComposer <T> With(IPostprocessComposer <T> newComposer)
        {
            if (newComposer == null)
            {
                throw new ArgumentNullException("newComposer");
            }

            return(new BehaviorPostprocessComposer <T>(newComposer, this.Behaviors));
        }
Esempio n. 10
0
 private IPostprocessComposer <Ticket> AddTagCustomisation(
     IFixture _,
     IPostprocessComposer <Ticket> ticket, string reason)
 =>
 ticket
 .Without(y => y.Tags)
 .Do(y => y.Tags = new List <string> {
     $"pending_middleware_{reason.ToLower()}"
 });
Esempio n. 11
0
        public static IPostprocessComposer <OutputGroupModel> WithItems(
            this IPostprocessComposer <OutputGroupModel> composer, IDictionary <string, int> itemsDefinitions,
            IFixture fixture)
        {
            var items = itemsDefinitions?.Select(def => fixture.Build <OutputItemModel>()
                                                 .WithId(def.Key)
                                                 .WithCount(def.Value)
                                                 .Create());

            return(items != null?composer.With(m => m.Items, items) : composer);
        }
Esempio n. 12
0
        private static Estacion MakeEstacion(Coord?coord = null)
        {
            IPostprocessComposer <Estacion> builder = fixture.Build <Estacion>();

            if (coord != null)
            {
                builder = builder.With(e => e.Coord, coord.Value);
            }

            return(builder.Create());
        }
        public CsvDbUpdateRelationArticleTests()
        {
            _fixture = new Fixture().Customize(new AutoMoqCustomization()
            {
                ConfigureMembers = true
            });
            _postProcessFieldComposer = _fixture.Build <Field>().FromFactory(CsvDbUpdateTestHelpers.GenerateField(_fixture)).OmitAutoProperties();
            _fixture.Customize <Field>(composer => _postProcessFieldComposer);

            QPContext.CurrentDbConnectionString = _fixture.Create <string>();
        }
Esempio n. 14
0
 public static IPostprocessComposer <T> WithoutBaseProperties <T>(this IPostprocessComposer <T> builder) where T : BaseModel <int>
 {
     return(builder
            .Without(x => x.Id)
            .Without(x => x.CreatedBy)
            .Without(x => x.CreatedOn)
            .Without(x => x.UpdatedOn)
            .Without(x => x.UpdatedBy)
            .Without(x => x.DeletedOn)
            .Without(x => x.DeletedBy));
 }
Esempio n. 15
0
 public static IPostprocessComposer <DependencyDefinition> WithPathRules(
     this IPostprocessComposer <DependencyDefinition> composer, string pathRules)
 {
     return(composer.With(x => x.Properties, new Properties()
     {
         Count = "1", Property = new PropertyList {
             new Property {
                 Name = "pathRules", Value = pathRules
             }
         }
     }));
 }
        public void InitializedWithArrayConstructorHasCorrectComposer()
        {
            // Fixture setup
            var expectedComposer = new DelegatingComposer <object>();
            var sut = new BehaviorPostprocessComposer <object>(expectedComposer);
            // Exercise system
            IPostprocessComposer <object> result = sut.Composer;

            // Verify outcome
            Assert.Equal(expectedComposer, result);
            // Teardown
        }
Esempio n. 17
0
        public IEventGeneratingScenarioGivenStateBuilder Given <TEvent>(string identifier, Func <IPostprocessComposer <TEvent>, IPostprocessComposer <TEvent> > customize = null)
        {
            IPostprocessComposer <TEvent> composer = _fixture.Build <TEvent>();

            if (customize != null)
            {
                composer = customize(composer);
            }

            var @event = composer.Create();

            return(new AutoAutoFixtureTestBuilder(Given(identifier, @event), _fixture));
        }
    public static IEnumerable <T> CreateMany <T>(this IPostprocessComposer <T> composer, int numberOfObjects)
    {
        if (numberOfObjects < 0)
        {
            throw new ArgumentException("The number of objects is negative!");
        }
        IList <T> collection = new List <T>();

        for (int i = 0; i < numberOfObjects; i++)
        {
            collection.Add(composer.Create <T>());
        }
        return(collection);
    }
        /// <summary>
        /// Initializes a new instance of the <see cref="BehaviorPostprocessComposer&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="composer">The composer to decorate.</param>
        /// <param name="behaviors">
        /// The behaviors which will be applied when <see cref="Compose"/> is invoked.
        /// </param>
        public BehaviorPostprocessComposer(IPostprocessComposer <T> composer, params ISpecimenBuilderTransformation[] behaviors)
        {
            if (composer == null)
            {
                throw new ArgumentNullException("composer");
            }
            if (behaviors == null)
            {
                throw new ArgumentNullException("behaviors");
            }

            this.composer  = composer;
            this.behaviors = behaviors;
        }
        /// <summary>
        /// Registers that a writable string property and normalized equivalent should be assigned to the result of calling
        /// the specified factory function as part of specimen post-processing.
        /// </summary>
        /// <typeparam name="TModel">The type of the model.</typeparam>
        /// <param name="composer">The composer.</param>
        /// <param name="property">The property.</param>
        /// <param name="normalizedProperty">The normalized property.</param>
        /// <param name="factory">The factory.</param>
        /// <returns></returns>
        public static IPostprocessComposer <TModel> WithNormalized <TModel>(this IPostprocessComposer <TModel> composer,
                                                                            Expression <Func <TModel, string> > property,
                                                                            Expression <Func <TModel, string> > normalizedProperty,
                                                                            Func <Faker, string> factory)
        {
            var faker          = new Faker();
            var info           = property.GetProperty();
            var normalizedInfo = normalizedProperty.GetProperty();

            return(composer.Without(property).Without(normalizedProperty).Do(x =>
            {
                var value = factory(faker);
                info.SetValue(x, value);
                normalizedInfo.SetValue(x, value.Normalize().ToUpper());
            }));
        }
Esempio n. 21
0
            // When escalating tickets agents use a macro that adds a tagged
            // comment to the ticket.  The extra tag and comment occur in the
            // same audit event as the "pending" tag.
            private static IPostprocessComposer <Ticket> EscalateCommentCustomisation(
                IFixture fixture,
                IPostprocessComposer <Ticket> ticket)
            =>
            ticket
            .Without(y => y.Id)
            .Do(ticket =>
            {
                ticket.Id = fixture.Create <long>();

                var comment = fixture.Create <AuditedComment>();
                comment.Escalate();

                var zendesk = fixture.Create <FakeZendeskApi>();
                zendesk.AddComments(ticket, new[] { comment });
            });
Esempio n. 22
0
        public static IPostprocessComposer <AppUserEntity> Build()
        {
            Fixture fixture = new Fixture();

            IPostprocessComposer <AppUserEntity> composer = fixture
                                                            .Build <AppUserEntity>()
                                                            .With(x => x.Claims, new List <UserClaimEntity>())
                                                            .With(x => x.Logins, new List <UserLoginEntity>())
                                                            .With(x => x.Tokens, new List <UserTokenEntity>())
                                                            .With(x => x.UserRoles, new List <UserRoleEntity>())
                                                            .With(x => x.Sessions, new List <SessionEntity>())
                                                            .With(x => x.Groups, new List <GroupUserEntity>())
                                                            .With(x => x.UserImage, new UserImageEntity())
                                                            .With(x => x.Attributes, new List <UserAttributeEntity>());

            return(composer);
        }
        public static IPostprocessComposer <QuestionnaireResponse> WithAllYesAnswers(
            this IPostprocessComposer <QuestionnaireResponse> composer)
        {
            var value = "Yes";

            return(composer
                   .With(x => x.WheelchairFriendlyAnswer, value)
                   .With(x => x.BuggyFriendlyAnswer, value)
                   .With(x => x.HasToiletsAnswer, value)
                   .With(x => x.DogsAllowedAnswer, value)
                   .With(x => x.CafeAnswer, value)
                   .With(x => x.PostRunCoffeeAnswer, value)
                   .With(x => x.DrinkingFountainsAnswer, value)
                   .With(x => x.ChangingRoomsAnswer, value)
                   .With(x => x.LockersAvailableAnswer, value)
                   .With(x => x.ShowersAvailableAnswer, value)
                   .With(x => x.BagDropAnswer, value)
                   .With(x => x.BabyChangingFacilitiesAnswer, value)
                   .With(x => x.VisuallyImpairedFriendlyAnswer, value));
        }
Esempio n. 24
0
 public static T Create <T>(this IPostprocessComposer <T> composer)
 {
     return(Create <T>((ISpecimenBuilder)composer));
 }
Esempio n. 25
0
 public static IEnumerable <T> CreateMany <T>(this IPostprocessComposer <T> composer, int count)
 {
     return(((ISpecimenBuilder)composer).CreateMany <T>(count));
 }
Esempio n. 26
0
 public static T CreateAnonymous <T>(this IPostprocessComposer <T> composer)
 {
     return(Create <T>(composer));
 }
Esempio n. 27
0
 public IPostprocessComposer <T> WithAutoProperties() => _builder = _builder.WithAutoProperties();
Esempio n. 28
0
 public IPostprocessComposer <T> Without <TProperty>(Expression <Func <T, TProperty> > propertyPicker) => _builder = _builder.Without(propertyPicker);
Esempio n. 29
0
 public static IPostprocessComposer <Dream> WithNewCategory(this IPostprocessComposer <Dream> postProcessComposer)
 {
     return(postProcessComposer.WithCategory(new Fixture().DreamCategoryBuilder().Create()));
 }
Esempio n. 30
0
 public static IPostprocessComposer <Dream> WithCategory(this IPostprocessComposer <Dream> postProcessComposer, DreamCategory category)
 {
     return(postProcessComposer.With(d => d.DreamCategory, category));
 }