static DummyDataInitializer()
 {
     AutoFaker.Configure(builder =>
     {
         builder.WithConventions();
     });
 }
Ejemplo n.º 2
0
 public Vehicles()
 {
     AutoFaker.Configure(builder =>
     {
         builder
         .WithRecursiveDepth(4);
     });
 }
Ejemplo n.º 3
0
 public SearchServiceFixture()
 {
     _permitGenerator = new AutoFaker <Permit>();
     _permitGenerator.Configure(builder =>
     {
         builder.WithConventions();
         builder.WithBinder <MoqBinder>();
     });
 }
Ejemplo n.º 4
0
            public void Should_Configure_Default_Config()
            {
                AutoConfig config = null;

                AutoFaker.Configure(builder =>
                {
                    var instance = builder as AutoConfigBuilder;
                    config       = instance.Config;
                });

                config.Should().Be(AutoFaker.DefaultConfig);
            }
Ejemplo n.º 5
0
    static async Task Main(string[] args)
    {
        AutoFaker.Configure(builder =>
        {
            builder.WithConventions();
        });

        string runId      = DateTime.UtcNow.ToString("yyyy-MM-dd-HHmmss");
        string outputDir  = Path.Combine(AppContext.BaseDirectory, "../../../examples", runId);
        string outputFile = Path.Combine(outputDir, runId + ".txt");

        if (!Directory.Exists(outputDir))
        {
            Directory.CreateDirectory(outputDir);
        }

        using (var output = File.OpenWrite(outputFile))
            using (var writer = new StreamWriter(output))
            {
                for (int i = 0; i < 1000; i++)
                {
                    var stream = new MemoryStream();

                    try
                    {
                        var customers = new CustomerCollectionResponse
                        {
                            Customers = Enumerable.Range(0, 50).Select(i => CustomerDataGenerator.CreateCustomer()).ToList()
                        };

                        await JsonSerializer.SerializeAsync(stream, customers);

                        stream.Position = 0;

                        var deserialized = await JsonSerializer.DeserializeAsync <CustomerCollectionResponse>(stream, s_serializerOptions);

                        writer.WriteLine($"{i:0000}: Reading Json from stream - deserialized {deserialized.Customers.Count} customer records.");
                        Console.WriteLine($"{i:0000}: Reading Json from stream - deserialized {deserialized.Customers.Count} customer records.");
                    }
                    catch (Exception e)
                    {
                        writer.WriteLine($"{i:0000}: Error:{Environment.NewLine}{e}");
                        Console.WriteLine($"{i:0000}: Error:{Environment.NewLine}{e}");

                        using (var file = File.OpenWrite(Path.Combine(outputDir, $"{runId}-{i:0000}.json")))
                        {
                            await file.WriteAsync(stream.ToArray());
                        }
                    }
                }
            }
    }
Ejemplo n.º 6
0
        public void Generate_OverrideRulesAreAppliedGlobally()
        {
            //setup
            AutoFaker.Configure(builder =>
            {
                builder.WithOverride(new PostOverride());
            });
            var target = new AutoBogusGenerator();

            //invoke
            List <Post> posts = (List <Post>)target.Generate(new GeneratorContext
            {
                Description = new EntityDescription <Post>()
            });

            //assert
            AssertPostNotEmpty(posts);
        }
Ejemplo n.º 7
0
            public void Should_Not_Initialize_Properties_Twice()
            {
                // Arrange
                var random1 = new Randomizer(12345);
                var random2 = new Randomizer(12345);

                var faker = new Faker()
                {
                    Random = random1
                };

                var autoFaker = new AutoFaker <TestClassWithSingleProperty <int> >();

                autoFaker.Configure(
                    builder => builder.WithFakerHub(faker));

                // Act
                var instance = autoFaker.Generate(); // Should pull one int from random1

                var expectedValue = random2.Int();

                // Assert
                instance.Value.Should().Be(expectedValue);
            }
Ejemplo n.º 8
0
 public EntityFaker()
 {
     AutoFaker.Configure(b => b.WithSkip <T>(x => x.ETag).WithSkip <T>(x => x.PartitionKey).WithSkip <T>(x => x.RowKey).WithSkip <T>(x => x.Timestamp));
 }
Ejemplo n.º 9
0
        public async Task SeedData()
        {
            if (!_context.Roles.Any())
            {
                var role = new IdentityRole <Guid>();
                role.Name = "Admin";
                await _roleManager.CreateAsync(role);

                var basicRole = new IdentityRole <Guid>();
                basicRole.Name = "Basic";
                await _roleManager.CreateAsync(basicRole);

                await _context.SaveChangesAsync();
            }

            if (!_context.Users.Any())
            {
                var validUser = new ApplicationUser()
                {
                    Email     = "*****@*****.**",
                    UserName  = "******",
                    FirstName = "Marcus",
                    LastName  = "Testman",
                    DoB       = new DateTime(1986, 12, 15)
                };
                var validUserResult = await _userManager.CreateAsync(validUser, "Pa$$w0rd");

                if (validUserResult.Succeeded)
                {
                    await _userManager.AddToRoleAsync(validUser, "Admin");
                }

                var basicUser = new ApplicationUser()
                {
                    Email     = "*****@*****.**",
                    UserName  = "******",
                    FirstName = "Becky",
                    LastName  = "Testman",
                    DoB       = new DateTime(1984, 05, 09)
                };

                var basicUserResult = await _userManager.CreateAsync(basicUser, "Pa$$w0rd");

                if (basicUserResult.Succeeded)
                {
                    await _userManager.AddToRoleAsync(basicUser, "Basic");
                }

                _context.SaveChanges();
            }
            if (!_context.Portfolios.Any())
            {
                var jobs = new[] { "Cleaner", "Software Developer", "Journal Manager", "Head of Marketing", "Mechanic", "Shop Assistant", "Builder", "Electrician", "Accountant",
                                   "Nurse Practitioner", "Librarian", "Dog Trainer", "Delivery Driver", "Yoga Instructor", "Tech Support", "Cyber Security", "Biomedical Engineering", "Iron and Steel Worker",
                                   "Sheet Metal Worker", "Clinical Nurse Specialist", "Nurse Practitioner", "Account Management", "Quality Executive", "Risk Executive", "Accounting Specialist", "Accountant" };
                var maleTitles   = new[] { "Dr", "Mr", "Rev", "Sr", "Prof", "Lord" };
                var femaleTitles = new[] { "Mrs", "Miss", "Ms", "Lady", "Mx" };
                var townNames    = new[] { "Ossett", "Bradley Stoke", "Malton", "Swaffham", "Ramsey", "Saffron Walden", "Stockton-on-Tees", "Knares", "Horley",
                                           "Ampthill", "Boston", "Sleaford", "Wakefield", "Hingham", "Northwich", "Canterbury", "Wadebridge", "Fowey", "Reading", "Wymondham", "Warrington",
                                           "Northleach with Eastington", "Brentford", "Portsmouth", "Crediton", "Exeter", "Paignton", "Chester-le-Street", };
                var users  = _context.Users.ToArray();
                var titles = maleTitles.Concat(femaleTitles);

                Random rnd = new Random();

                AutoFaker.Configure(builder =>
                {
                    builder.WithLocale("en_GB");
                });

                var notes = new AutoFaker <Note>()
                            .RuleFor(x => x.Description, f => f.Lorem.Paragraph(rnd.Next(3, 5)))
                            .RuleFor(x => x.Title, f => f.Lorem.Sentence(rnd.Next(2, 5)));

                var personFaker = new AutoFaker <Tenant>()
                                  .RuleFor(x => x.Id, f => f.Random.Guid())
                                  .RuleFor(x => x.FirstName, f => f.Person.FirstName)
                                  .RuleFor(x => x.LastName, f => f.Person.LastName)
                                  .RuleFor(x => x.Profession, f => f.PickRandom(jobs))
                                  .RuleFor(x => x.ContactNumber, f => f.Phone.PhoneNumber())
                                  .RuleFor(x => x.EmailAddress, f => f.Person.Email)
                                  .RuleFor(x => x.Profile_Url, f => f.Person.Avatar)
                                  .RuleFor(x => x.TenancyStartDate, f => f.Date.PastOffset(1).DateTime)
                                  .RuleFor(x => x.TenancyEndDate, f => f.Date.PastOffset(1).DateTime.OrNull(f))
                                  .RuleFor(x => x.Title, f => f.PickRandom(titles))
                                  .RuleFor(x => x.CreatedDateTime, f => f.Date.Past())
                                  .RuleFor(x => x.Notes, notes.Generate(rnd.Next(1, 4)));

                var addresses = new AutoFaker <Address>()
                                .RuleFor(x => x.City, f => f.Address.City())
                                .RuleFor(x => x.Line1, f => f.Address.StreetAddress())
                                .RuleFor(x => x.Line2, f => f.Address.SecondaryAddress())
                                .RuleFor(x => x.PostCode, f => f.Address.ZipCode("??# #??"))
                                .RuleFor(x => x.Town, f => f.PickRandom(townNames));

                var properties = new AutoFaker <Property>()
                                 .RuleFor(x => x.AddressId, f => addresses.Generate().Id)
                                 .RuleFor(x => x.Description, f => f.Lorem.Paragraph(rnd.Next(3, 7)))
                                 .RuleFor(x => x.NoOfBeds, f => f.Random.Int(1, 4))
                                 .RuleFor(x => x.PropertyValue, f => Math.Round(f.Random.Decimal(50000, 130000), 2))
                                 .RuleFor(x => x.PurchasePrice, f => Math.Round(f.Random.Decimal(42000, 120000), 2))
                                 .RuleFor(x => x.RentalPrice, f => Math.Round(f.Random.Decimal(400, 1300), 2))
                                 .RuleFor(x => x.Tenants, personFaker.Generate(rnd.Next(2, 6)))
                                 .RuleFor(x => x.PurchaseDate, f => f.Date.Past().Date);

                var portfolioList = new AutoFaker <Portfolio>()
                                    .RuleFor(x => x.Properties, properties.Generate(rnd.Next(2, 5)))
                                    .RuleFor(x => x.OwnerId, f => f.PickRandom(users).Id)
                                    .RuleFor(x => x.Name, f => f.PickRandom(townNames));

                var portList = portfolioList.Generate(10);

                await _context.Portfolios.AddRangeAsync(portList);

                await _context.SaveChangesAsync();
            }
        }