Пример #1
0
        public void TestCustomGeneratorClass()
        {
            _config.Add <WithCustomGeneratorClass, int, CustomIntGenerator>(elem => elem.testInt);
            WithCustomGeneratorClass testClass = _faker.Create <WithCustomGeneratorClass>();

            Assert.AreEqual(-1, testClass.testInt);
            Assert.NotZero(testClass.TestDouble);
        }
Пример #2
0
        public void Setup()
        {
            var config = new FakerConfig();

            config.Add <Foo, string, ShoGenerator>(ex => ex.DeterminedString);
            config.Add <Example, int, GACGenerator>(ex => ex.IntNumber);
            config.Add <Example2, string, PopGenerator>(ex => ex.name);
            config.Add <Example2, int, GACGenerator>(ex => ex.numa);
            config.Add <StructExample, int, GACGenerator>(ex => ex.d);
            faker = new Faker(config);
        }
Пример #3
0
        static void Main(string[] args)
        {
            FakerConfig config = new FakerConfig();

            config.Add <TestClassWithProperties, byte, ByteNotRandomGenerator>(exspression => exspression.CustomGeneratorCheckProperty1);
            config.Add <TestClassWithConstructor, byte, ByteNotRandomGenerator>(exspression => exspression.CustomGeneratorCheckProperty2);
            Faker.Faker faker = new Faker.Faker(config);
            ConsoleJsonSerializer.Serialize(faker.Create <TestClassWithProperties>());
            Console.WriteLine();
            ConsoleJsonSerializer.Serialize(faker.Create <TestClassWithConstructor>());

            Console.ReadKey();
        }
Пример #4
0
        public void ConfigTest()
        {
            config.Add <TestClass, int, IntPropertyGenerator>(obj => obj.intProperty);
            config.Add <TestClass, string, StringPropertyGenerator>(obj => obj.stringProperty);
            config.Add <TestClass, TestSubClass, TestSubClassGenerator>(obj => obj.testSubClass);
            Faker     faker     = new Faker(config);
            TestClass testClass = faker.Create <TestClass>();

            Assert.AreEqual(851004, testClass.intProperty);
            Assert.AreEqual("851004", testClass.stringProperty);
            Assert.AreEqual(13, testClass.testSubClass.A);
            Assert.AreEqual("пятница", testClass.testSubClass.B);
        }
Пример #5
0
        static void Main(string[] args)
        {
            var config = new FakerConfig();

            config.Add <Foo, string, CityGeneratorDelegate>(foo => foo.city, CityGenerator);
            config.Add <Foo, int, Func <int> >(foo => foo.citizensCount, new IntGenerator().CountGenerator);
            var faker = new Faker(config);
            var ex    = (Foo)faker.Create <Foo>();

            Console.WriteLine(ex.citizensCount.ToString() + " " + ex.city);
            //Console.WriteLine(typeof(IntGenerator).GetMethod("CountGenerator").ToString());
            Console.ReadLine();
        }
Пример #6
0
        static void Main(string[] args)
        {
            var config = new FakerConfig();

            config.Add <Example, string, ShoGenerator>(ex => ex.StringItem);
            config.Add <Example, int, GacGenerator>(ex => ex.IntNumber);
            config.Add <Example2, string, PopGenerator>(ex => ex.name);
            config.Add <StructExample, int, GacGenerator>(ex => ex.d);
            var     faker = new Faker(config);
            Example obj   = faker.Create <Example>();

            //Console.WriteLine(new CustomXmlSerializer().Serialize(obj));
            Console.ReadKey();
        }
Пример #7
0
        public static void Main(string[] args)
        {
            FakerConfig config = new FakerConfig();

            config.Add <ExampleClassProperties, int, IntNonRandomGenerator>(ex => ex.CustomGeneratorCheckProperty);
            config.Add <ExampleClassConstructor, int, IntNonRandomGenerator>(ex => ex.CustomGeneratorCheckProperty2);

            Faker faker = new Faker(config);

            ConsoleJsonSerializer.Serialize(faker.Create <ExampleClassProperties>());
            ConsoleJsonSerializer.Serialize(faker.Create <ExampleClassConstructor>());

            Console.ReadKey();
        }
Пример #8
0
        public void ConfigCreationWithNoCtorTest()
        {
            Faker _faker = new Faker();

            IConfig config = new FakerConfig();

            config.Add <QuestionWithNoCtor, int, Generator42>(Question => Question.Answer);
            config.Add <QuestionWithNoCtor, string, GeneratorMambo>(Question => Question.Mambo);
            var faker            = new Faker(config);
            QuestionWithNoCtor q = faker.Create <QuestionWithNoCtor>();

            Assert.AreEqual(42, q.Answer);
            Assert.AreEqual(default(int), q.UnsettedAnswer);
            Assert.AreEqual("Mambo", q.Mambo);
            Assert.AreNotEqual(42, q.NoAnswerField);
        }
Пример #9
0
        public void TestInit()
        {
            FakerConfig fc = new FakerConfig();

            fc.Add <Bar, string, StandStringGenerator>(Bar => Bar.stand);
            faker = new Faker(fc, 2);
        }
Пример #10
0
        public void Config()
        {
            var fakerConfig = new FakerConfig();

            fakerConfig.Add <Foo, string, FooStringGenerator>(Foo => Foo.Field);
            var faker = new Faker(fakerConfig);
            var foo   = faker.Create <Foo>() as Foo;

            Assert.AreEqual(foo.Field, "TEST");
        }
Пример #11
0
        public void ConfigInt()
        {
            var fakerConfig = new FakerConfig();

            fakerConfig.Add <Foo, int, FooIntGenerator>(Foo => Foo.FieldInt);
            var faker = new Faker(fakerConfig);
            var foo   = faker.Create <Foo>() as Foo;

            Assert.AreEqual(foo.FieldInt, 123);
        }
Пример #12
0
        public void Config()
        {
            FakerConfig fakerConfig = new FakerConfig();

            fakerConfig.Add <Bar, int, BarIisGenerator>(Bar => Bar.isS);
            Faker.Faker configFaker = new Faker.Faker(fakerConfig);
            Bar         bar         = (Bar)configFaker.Create <Bar>();

            Assert.AreEqual(bar.isS, 123);
        }
Пример #13
0
        public void TestCustomFakerInConstructor()
        {
            FakerConfig config = new FakerConfig();

            config.Add <TestClosedClass, Int32>(CustomIntGenerator, obj => obj.TestInt);
            Faker faker = new Faker(config);

            TestClosedClass testClass = (TestClosedClass)faker.Create(typeof(TestClosedClass));

            Assert.AreEqual(testClass.TestInt, -1);
        }
Пример #14
0
        public void ShoulUseUserGeneratorForFieldWithoutSetter()
        {
            FakerConfig fakerConfig = new FakerConfig();

            fakerConfig.Add <Foo, string>(foo => foo.City, new CityGenerator());
            Faker faker = new Faker(fakerConfig);

            Foo foo = faker.Create <Foo>();

            Assert.NotNull(foo.City);
            Assert.Contains(foo.City, CityGenerator.cityList);
        }
Пример #15
0
        public void CustomGenerationTest()
        {
            IFakerConfig config = new FakerConfig();

            config.Add <CustomGenerationPropertyClass, int, IntNonRandomGenerator>(cl => cl.SomeValue);
            config.Add <CustomGenerationConstructorClass, int, IntNonRandomGenerator>(cl => cl.SomeValue2);
            Assert.ThrowsException <ArgumentException>(() => config.Add <CustomGenerationPropertyClass, string, IntNonRandomGenerator>(err => err.SomeString));

            faker = new Faker(config);

            CustomGenerationPropertyClass propertyClass = faker.Create <CustomGenerationPropertyClass>();

            Assert.AreEqual(IntNonRandomGenerator.DefaultGeneratedValue, propertyClass.SomeValue);
            Assert.AreEqual(IntNonRandomGenerator.DefaultGeneratedValue, propertyClass.someValue);

            CustomGenerationConstructorClass constructorClass = faker.Create <CustomGenerationConstructorClass>();

            Assert.AreEqual(IntNonRandomGenerator.DefaultGeneratedValue, constructorClass.SomeValue2);
            Assert.AreNotEqual(IntNonRandomGenerator.DefaultGeneratedValue, constructorClass.SomeValue);
            Assert.AreNotEqual(IntNonRandomGenerator.DefaultGeneratedValue, constructorClass.someValue);
        }
Пример #16
0
        public void CustomGenerationTest()
        {
            IFakerConfig config = new FakerConfig();

            config.Add <CustomClassWithProperty, byte, ByteNotRandomGenerator>(cl => cl.ByteValue1);
            config.Add <CustomClassWithConstructor, byte, ByteNotRandomGenerator>(cl => cl.ByteValue2);
            Assert.ThrowsException <ArgumentException>(() => config.Add <CustomClassWithProperty, string, ByteNotRandomGenerator>(err => err.SomeString));

            faker = new Faker.Faker(config);

            CustomClassWithProperty propertyClass = faker.Create <CustomClassWithProperty>();

            Assert.AreEqual(ByteNotRandomGenerator.DefaultGeneratedValue, propertyClass.ByteValue1);
            Assert.AreNotEqual(ByteNotRandomGenerator.DefaultGeneratedValue, propertyClass._byteValue);

            CustomClassWithConstructor constructorClass = faker.Create <CustomClassWithConstructor>();

            Assert.AreNotEqual(ByteNotRandomGenerator.DefaultGeneratedValue, constructorClass.ByteValue2);
            Assert.AreNotEqual(ByteNotRandomGenerator.DefaultGeneratedValue, constructorClass.ByteValue1);
            Assert.AreNotEqual(ByteNotRandomGenerator.DefaultGeneratedValue, constructorClass._byteValue);
        }
Пример #17
0
        static void Main(string[] args)
        {
            FakerConfig fakerConfig = new FakerConfig();

            fakerConfig.Add <Foo, string>(foo => foo.City, new CityGenerator());
            Faker faker = new Faker(fakerConfig);

            Foo a = faker.Create <Foo>();

            ISerializer jsonSerializer = new JSONSerializer();

            Console.WriteLine(jsonSerializer.Serizlize(a));
        }
Пример #18
0
        public void FakerConfig_TestNumberOfSmallLetters()
        {
            DictionaryOfGenerators dict = new DictionaryOfGenerators();
            var config = new FakerConfig(dict);

            config.Add <TestClass1, string, StringConfigGenerator>(TestClass1 => TestClass1.str);
            Faker.Faker faker = new Faker.Faker(dict);
            TestClass1  obj   = faker.Create <TestClass1>();
            var         a     = from b in obj.str.ToLower()
                                where b >= 'a' && b <= 'z'
                                select b;

            Assert.AreEqual(obj.str.Length, a.Count());
        }
Пример #19
0
        public void Faker_TestClassWithFakerConfig()
        {
            DictionaryOfGenerators dict = new DictionaryOfGenerators();
            var config = new FakerConfig(dict);

            config.Add <TestClass1, string, StringConfigGenerator>(TestClass1 => TestClass1.str);
            Faker.Faker faker = new Faker.Faker(dict);
            TestClass1  obj   = faker.Create <TestClass1>();
            var         a     = from b in obj.str
                                where b >= '0' && b <= '9'
                                select b;

            Assert.AreEqual(0, a.Count());
        }
Пример #20
0
        static void Main(string[] args)
        {
            FakerConfig config = new FakerConfig();

            config.Add <Test, string, HelloGenerator>(x => x.stringField);
            Faker       faker   = new Faker(config);
            Test        test    = faker.Create <Test>();
            TestStruct  s       = faker.Create <TestStruct>();
            List <Test> lt      = faker.Create <List <Test> >();
            UriBuilder  builder = new UriBuilder();
            Uri         uri     = faker.Create <Uri>();
            DateTime    dt      = faker.Create <DateTime>();

            Console.WriteLine(Serialize(test));
        }
Пример #21
0
        public void TestCustomFaker()
        {
            FakerConfig config = new FakerConfig();

            config.Add <TestOpenClass2, Int32>(CustomIntGenerator, obj => obj.TestCustomInt);
            Faker faker = new Faker(config);

            TestOpenClass2 testClass = (TestOpenClass2)faker.Create(typeof(TestOpenClass2));

            Assert.AreNotEqual(testClass.TestInt, -1);
            Assert.AreEqual(testClass.TestCustomInt, -1);

            TestOpenClass5 testClass2 = (TestOpenClass5)faker.Create(typeof(TestOpenClass5));

            Assert.AreEqual(-1, testClass2.TestObject.TestCustomInt);
        }
Пример #22
0
        static void Main(string[] args)
        {
            Faker    _faker   = new Faker();
            Bar      bar      = _faker.Create <Bar>();
            FooArray fooArray = _faker.Create <FooArray>();

            decimal[]  decArr = _faker.Create <decimal[]> ();
            FileStream fs     = _faker.Create <FileStream>();

            IConfig config = new FakerConfig();

            config.Add <Question, int, Generator42>(Question => Question.Answer);
            var      faker = new Faker(config);
            Question q     = faker.Create <Question>();

            Console.ReadKey();
        }
Пример #23
0
        static void Main(string[] args)
        {
            FakerConfig fc = new FakerConfig();
            fc.Add<Foo, string, StandStringGenerator>(Foo => Foo.Stand);
            Faker faker = new Faker(fc);

            Foo foo = faker.Create<Foo>();
            DateTime dt = faker.Create<DateTime>();
            List<float> l = faker.Create<List<float>>();

            Console.WriteLine(foo);
            Console.WriteLine(dt);
            foreach (float f in l)
                Console.WriteLine(f);

            Console.ReadLine();
        }
Пример #24
0
        public void ShouldDetectWrongGeneratorType()
        {
            FakerConfig fakerConfig = new FakerConfig();

            Assert.Throws <FakerConfigException>(() => fakerConfig.Add <Foo, double>(foo => foo.doubleValue, new CityGenerator()));
        }