示例#1
0
文件: Company.cs 项目: salixzs/Bogus
        /// <summary>
        /// Get a company name
        /// </summary>
        /// <param name="formatIndex">0: name + suffix, 1: name-name, 2: name, name and name."</param>
        public string CompanyName(int? formatIndex = null)
        {
            var formats = new[]
                {
                    "{{name.lastName}} {{company.companySuffix}}",
                    "{{name.lastName}} - {{name.lastName}}",
                    "{{name.lastName}}, {{name.lastName}} and {{name.lastName}}"
                };

            var index = formatIndex ?? Random.Number(formats.Length - 1);
            return CompanyName(formats[index]);
        }
示例#2
0
文件: System.cs 项目: Mpdreamz/Bogus
        /// <summary>
        /// Returns a commonly used file extension
        /// </summary>
        /// <returns></returns>
        public string CommonFileExt()
        {
            var types = new[]
                {
                    "application/pdf",
                    "audio/mpeg",
                    "audio/wav",
                    "image/png",
                    "image/jpeg",
                    "image/gif",
                    "video/mp4",
                    "video/mpeg",
                    "text/html"
                };

            return FileExt(this.Random.ArrayElement(types));
        }
示例#3
0
        public void TestAPIDesign()
        {
            //Set the randomzier seed if you wish to generate repeatable data sets.
            Randomizer.Seed = new Random(3897234);

            var fruit = new[] { "apple", "banana", "orange", "strawberry", "kiwi" };

            var orderIds = 0;
            var testOrders = new Faker<Order>()
                //Ensure all properties have rules. By default, StrictMode is false
                //Set a global policy by using Faker.DefaultStrictMode if you prefer.
                .StrictMode(true)
                //OrderId is deterministic
                .RuleFor(o => o.OrderId, f => orderIds++)
                //Pick some fruit from a basket
                .RuleFor(o => o.Item, f => f.PickRandom(fruit))
                //A random quantity from 1 to 10
                .RuleFor(o => o.Quantity, f => f.Random.Number(1, 10));

            var userIds = 0;
            var testUsers = new Faker<User>()
                //Optional: Call for objects that have complex initialization
                .CustomInstantiator(f => new User(userIds++, f.Random.Replace("###-##-####")))

                //Basic rules using built-in generators
                .RuleFor(u => u.FirstName, f => f.Name.FirstName())
                .RuleFor(u => u.LastName, f => f.Name.LastName())
                .RuleFor(u => u.Avatar, f => f.Internet.Avatar())
                .RuleFor(u => u.UserName, (f, u) => f.Internet.UserName(u.FirstName, u.LastName))
                .RuleFor(u => u.Email, (f, u) => f.Internet.Email(u.FirstName, u.LastName))
                .RuleFor(u => u.SomethingUnique, f => $"Value {f.UniqueIndex}")
                .RuleFor(u => u.SomeGuid, Guid.NewGuid)

                //Use an enum outside scope.
                .RuleFor(u => u.Gender, f => f.PickRandom<Gender>())
                //Use a method outside scope.
                .RuleFor(u => u.CartId, f => Guid.NewGuid())
                //Compound property with context, use the first/last name properties
                .RuleFor(u => u.FullName, (f, u) => u.FirstName + " " + u.LastName)
                //And composability of a complex collection.
                .RuleFor(u => u.Orders, f => testOrders.Generate(3).ToList())
                //After all rules are applied finish with the following action
                .FinishWith((f, u) =>
                    {
                        Console.WriteLine("User Created! Name={0}", u.FullName);
                    });

            //RunAfter
            //InvokeAfterRules
            //FinalizeWith
            //AfterRulesInvoke
            //PostProcess
            //InvokeAfterAll
            //BeforeReturn
            //FinallyInvoke
            //FinishWith

            var user = testUsers.Generate(3);

            user.Dump();
        }
示例#4
0
文件: Finance.cs 项目: Mpdreamz/Bogus
        //We could do better at generating these I suppose.
        /// <summary>
        /// Returns a credit card number that should pass validation. See [here](https://developers.braintreepayments.com/ios+ruby/reference/general/testing).
        /// </summary>
        /// <returns></returns>
        public string CreditCardNumber()
        {
            var cards = new[]
                {
                    "378282246310005",
                    "371449635398431",
                    "6011111111111117",
                    "3530111333300000",
                    "6304000000000000",
                    "5555555555554444",
                    "4111111111111111",
                    "4005519200000004",
                    "4009348888881881",
                    "4012000033330026",
                    "4012000077777777",
                    "4012888888881881",
                    "4217651111111119",
                    "4500600000000061"
                };

            return Random.ArrayElement(cards);
        }
示例#5
0
文件: Internet.cs 项目: salixzs/Bogus
        /// <summary>
        /// Returns a random protocol. HTTP or HTTPS.
        /// </summary>
        public string Protocol()
        {
            var protocols = new[] {"http", "https"};

            return Random.ArrayElement(protocols);
        }
示例#6
0
文件: System.cs 项目: Mpdreamz/Bogus
 /// <summary>
 /// Returns a commonly used file type
 /// </summary>
 public string CommonFileType()
 {
     var types = new[] {"video", "audio", "image", "text", "application"};
     return this.Random.ArrayElement(types);
 }