コード例 #1
0
ファイル: BankDBTest.cs プロジェクト: cheeyixu/SQLStressTest
        private static Customer CreateCustomer(_CustomerType type)
        {
            var name    = new Bogus.DataSets.Name();
            var address = new Bogus.DataSets.Address();
            var random  = new Randomizer();

            if (type == _CustomerType.Individual)
            {
                var phoneNo = new Bogus.DataSets.PhoneNumbers();

                return(new IndividualCustomer()
                {
                    FirstName = name.FirstName(),
                    LastName = name.LastName(),
                    CustomerType = type.ToString(),
                    Street = address.StreetName(),
                    City = address.City(),
                    State = address.State(),
                    Zipcode = int.Parse(address.ZipCode("######")),
                    PhoneNo = int.Parse(phoneNo.PhoneNumber("########")),
                    Age = random.Number(18, 100),
                    Gender = (int)random.Enum <_Gender>()
                });
            }
            else if (type == _CustomerType.Enterprise)
            {
                var companyName = new Bogus.DataSets.Company();

                return(new EnterpriseCustomer()
                {
                    FirstName = name.FirstName(),
                    LastName = name.LastName(),
                    CustomerType = type.ToString(),
                    Street = address.StreetName(),
                    City = address.City(),
                    State = address.State(),
                    Zipcode = int.Parse(address.ZipCode("######")),
                    OrganizationName = companyName.CompanyName() + companyName.CompanySuffix(),
                    OrganizationType = random.Enum <_OrganizationType>().ToString()
                });
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
        /// <summary>
        /// Generates a random address using the Bogus library (a port of Faker.js)
        /// </summary>
        /// <returns></returns>
        private static IEnumerable <Address> RandomAddresses()
        {
            List <Address> addresses = new List <Address>();

            var random = new Random();

            for (int i = 0; i < random.Next(1, 5); i++)
            {
                var bogusAddress = new Bogus.DataSets.Address();


                Country country;
                State   state;

                var countries = Enum.GetValues(typeof(Country));
                var states    = Enum.GetValues(typeof(State));

                if (random.Next(1, 100) > 75)
                {
                    country = (Country)countries.GetValue(random.Next(countries.Length));
                }
                else
                {
                    country = Country.United_States;
                }

                if (country == Country.United_States)
                {
                    state = (State)states.GetValue(random.Next(states.Length));
                }
                else
                {
                    state = State.NA;
                }

                addresses.Add(new Address()
                {
                    HouseNum    = bogusAddress.BuildingNumber(),
                    Street      = bogusAddress.StreetName() + (random.Next() % 2 == 0 ? bogusAddress.StreetSuffix() : ""),
                    City        = bogusAddress.City(),
                    CountryCode = country,
                    StateCode   = state,
                    Zip         = bogusAddress.ZipCode(),
                    Pid         = System.Guid.NewGuid()
                });
            }

            return(addresses);
        }