Exemplo n.º 1
0
 public SkeletonFabricator(FabSupport context) : base(context)
 {
     Fixture.AddConvention(cfg =>
     {
         cfg.IfPropertyNameIs("Name").Use(f => f.Name.FullName());
     });
 }
Exemplo n.º 2
0
        public static IServiceCollection AddFabrication(
            this IServiceCollection services,
            Action <ConventionExpression> conventions = null)
        {
            services.AddSingleton <Faker>();

            services.AddSingleton <FabricatedSession, FabricatedSession>();

            services.AddSingleton(sp =>
            {
                var fixture = new Fixture();
                var faker   = sp.GetService <Faker>();
                var session = sp.GetService <FabricatedSession>();

                fixture.AddDefaultMiruConvention(faker);

                if (conventions != null)
                {
                    fixture.AddConvention(faker, conventions);
                }

                // TODO: better name for this builder
                fixture.Customizations.Add(new FabricationSpecimenBuilder(fixture, session));

                return(fixture);
            });

            services.AddSingleton <FabSupport>();

            services.AddSingleton <Fabricator>();

            return(services);
        }
Exemplo n.º 3
0
        public MongFabricator(FabSupport context) : base(context)
        {
            Fixture.AddConvention(cfg =>
            {
                cfg.IfPropertyNameIs("Amount").Use(f => decimal.Round(f.Random.Decimal(5, 100), 2));

                cfg.IfPropertyNameIs("TransactionId").Use(() => Guid.NewGuid().ToString());
                cfg.IfPropertyNameIs("PaymentId").Use(() => Guid.NewGuid().ToString());

                cfg.IfPropertyNameIs("BlockedAt").Use(() => null);
            });
        }
Exemplo n.º 4
0
        public PlaygroundFabricator(FabSupport context) : base(context)
        {
            Fixture.AddConvention(cfg =>
            {
                cfg.IfPropertyNameIs("Name").Use(f => f.Name.FullName());
            });

            WithDefault <TableList.Product>(x =>
            {
                x.ProductName     = Faker.Commerce.ProductName();
                x.ProductPrice    = Faker.Random.Decimal(0.5m, 99.99m);
                x.ProductLastSale = Faker.Date.Past(1);
            });
        }
Exemplo n.º 5
0
        public SelfImprovFabricator(FabSupport context) : base(context)
        {
            Fixture.AddConvention(_ =>
            {
                _.IfPropertyNameIs("Name").Use(f => f.Name.FullName());

                _.IfPropertyImplements <IUser>().Ignore();

                // TODO: Support IfPropertyIs<IInactivable>(m => m.IsInactive)
                _.IfPropertyNameIs(nameof(IInactivable.IsInactive)).Use(false);

                _.IfPropertyNameStarts("Password").Use("123456");
                _.IfPropertyNameIs("HashedPassword").Use(() => Hash.Create("123456"));
            });
        }
        public static IServiceCollection AddFabrication <TFabricator>(
            this IServiceCollection services,
            Action <ConventionExpression> conventions = null)
            where TFabricator : Fabricator
        {
            services.Scan(scan => scan
                          .FromAssemblies(typeof(TFabricator).Assembly)
                          .AddClasses(classes => classes.AssignableTo(typeof(ICustomFabricator <>)))
                          .AsImplementedInterfaces()
                          .As <ICustomFabricator>()
                          .WithSingletonLifetime());

            services.AddSingleton <Faker>();

            services.AddSingleton <FabricatedSession, FabricatedSession>();

            services.AddSingleton(sp =>
            {
                var fixture = new Fixture();
                var faker   = sp.GetService <Faker>();
                var session = sp.GetService <FabricatedSession>();

                fixture.AddDefaultMiruConvention(faker);

                if (conventions != null)
                {
                    fixture.AddConvention(faker, conventions);
                }

                // TODO: better name for this builder
                fixture.Customizations.Add(new FabricationSpecimenBuilder(fixture, session));

                return(fixture);
            });

            services.AddSingleton <FabSupport>();

            services.AddSingleton <TFabricator>();

            services.AddSingleton <Fabricator>(sp => sp.GetRequiredService <TFabricator>());

            return(services);
        }
Exemplo n.º 7
0
        public static Fixture AddDefaultMiruConvention(this Fixture fixture, Faker faker)
        {
            fixture.OmitRecursion();

            fixture.AddConvention(faker, _ =>
            {
                _.AddEntityFramework();

                // Ignore types
                _.IfPropertyImplementsEnumerableOf <IEntity>().Ignore();

                _.IfPropertyImplements(typeof(Enumeration <,>)).Ignore();
                _.IfPropertyImplements(typeof(Enumeration <>)).Ignore();
                _.IfPropertyImplements <IEnumerable <ILookupable> >().Ignore();

                _.AddAutoFaker();

                // Potential additions to AutoFaker

                _.IfPropertyNameIs("Name").Use(f => f.Name.FirstName());

                // Userfy
                _.IfPropertyNameStarts("Password").Use("123456");
                _.IfPropertyNameIs(HashedPassword).Use(() => Hash.Create("123456"));

                _.IfPropertyNameIs(nameof(IRecoverable.ResetPasswordToken)).Ignore();
                _.IfPropertyNameIs(nameof(IRecoverable.ResetPasswordSentAt)).Ignore();

                _.IfPropertyNameIs(nameof(IConfirmable.ConfirmationToken)).Use(() => null);
                _.IfPropertyNameIs(nameof(IConfirmable.ConfirmationSentAt)).Use(() => null);
                _.IfPropertyNameIs(nameof(IConfirmable.ConfirmedAt)).Use(() => 5.Minutes().Ago());

                _.IfPropertyNameIs(nameof(ICanBeAdmin.IsAdmin)).Use(() => false);

                // CreditCard
                _.IfPropertyNameIs("CreditCard").Use(f => f.Finance.CreditCardNumber());

                // Dates
                // _.IfPropertyTypeIs<DateTimeOffset>().Use(f => f.Date.FutureOffset().Time);
            });

            return(fixture);
        }
Exemplo n.º 8
0
        public SupportreonFabricator(FabSupport context) : base(context)
        {
            Fixture.AddConvention(conv =>
            {
                conv.IfPropertyNameIs(nameof(Project.Description))
                .Use(f => f.Lorem.Paragraphs(1));

                conv.IfPropertyIs <Project>(p => p.EndDate)
                .Use(f => f.Date.Future());

                conv.IfPropertyNameIs(nameof(Project.MinimumDonation))
                .Use(f => f.Finance.Amount(min: Donation.Minimum, max: 7));

                conv.IfPropertyNameIs(nameof(Donation.Amount))
                .Use(f => f.Finance.Amount(min: 7, max: 50));

                conv.IfPropertyNameIs(nameof(Donation.CreditCard))
                .Use(f => f.Random.String2(10, "1234567890"));

                conv.IfPropertyNameIs(nameof(Project.CreatedAt))
                .Use(f => DateTime.Now);
            });
        }
Exemplo n.º 9
0
 public static Fixture AddConvention(this Fixture fixture, Action <ConventionExpression> convention)
 {
     return(fixture.AddConvention(new Faker(), convention));
 }
Exemplo n.º 10
0
        public AutoFakerConventionTest()
        {
            _fixture = new Fixture();

            _fixture.AddConvention(_ => _.AddAutoFaker());
        }