public void CanDefineACustomGenerator()
        {
            var typeToFake = typeof(ItemForGenerator);

            Faker.AddGenerator(typeToFake, new TestingGenerator());

            Faker.FakeFactory.IsTypeFaked(typeToFake).Should().BeTrue();
        }
        public void WillUseTheNewGenerator()
        {
            var typeToFake = typeof(ItemForGenerator);

            Faker.AddGenerator(typeToFake, new TestingGenerator());

            var item = Faker.Create <ItemForGenerator>();

            item.SomeDate.Should().Be(new DateTime(1969, 07, 20));
            item.SomeNumber.Should().Be(11);
            item.SomeString.Should().Be("Moon");
        }
示例#3
0
文件: Main.cs 项目: maxnevans/Faker
        public static IFaker getFaker()
        {
            var faker = new Faker();

            faker.AddGenerator(new SByteGenerator());
            //faker.AddGenerator(new ByteGenerator());
            faker.AddGenerator(new BoolGenerator());
            faker.AddGenerator(new CharGenerator());
            faker.AddGenerator(new DateTimeGenerator());
            faker.AddGenerator(new DoubleGenerator());
            faker.AddGenerator(new FloatGenerator());
            faker.AddGenerator(new IntGenerator());
            //faker.AddGenerator(new LongGenerator());
            faker.AddGenerator(new ShortGenerator());
            faker.AddGenerator(new StringGenerator());

            faker.LoadPluginGenerators();

            return(faker);
        }
示例#4
0
        static void Main(string[] args)
        {
            // Configure Faker
            Faker personFaker = new Faker();

            // Add custom generator
            personFaker.AddGenerator(new IPGenerator(), "IPGenerator");

            List <string> names = new List <string>();

            names.Add("Pepito Perez");
            names.Add("Fulanito Antunez");
            names.Add("Sutanito Gutierrez");
            names.Add("Shurmano Gomez");
            names.Add("Suprimo de los Vientos");

            // Add values to Person name generator
            personFaker.AddList <string>(names, StringLists.PersonName);

            //
            // Test model
            Person person = personFaker.GetFake <Person>();

            // Results
            Console.WriteLine("*** One instance *** ");
            Console.WriteLine();
            PrintPerson(person);
            Console.WriteLine();
            Console.WriteLine("Press enter to continue.");

            Console.ReadLine();

            Console.WriteLine("********************");
            Console.WriteLine("*** 10 instances *** ");
            Console.WriteLine("********************");
            Console.WriteLine();
            List <Person> persons = personFaker.GetFake <Person>(10);

            foreach (Person item in persons)
            {
                PrintPerson(item);
            }

            Console.WriteLine();
            Console.WriteLine("Press enter to exit.");
            Console.ReadLine();
        }