public static void ClassInit(TestContext testContext) { FakerConfig fc = new FakerConfig(); fc.AddRule <PrivSetClass, int, CustomIntGen>(c => c.prop); faker = new Faker(fc); }
public void TestInit() { FakerConfig fc = new FakerConfig(); fc.Add <Bar, string, StandStringGenerator>(Bar => Bar.stand); faker = new Faker(fc, 2); }
private T FillClass <T>() { FakerConfig config = new FakerConfig(); Faker faker = new Faker(config); T testClass = (T)faker.Create(typeof(T)); return(testClass); }
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); }
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"); }
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); }
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); }
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); }
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); }
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(); }
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(); }
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)); }
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(); }
public void ConfigCreationWithCtorTest() { Faker _faker = new Faker(); IConfig config = new FakerConfig(); config.Add <QuestionWithCtor, int, Generator42>(Question => Question.Answer); var faker = new Faker(config); QuestionWithCtor q = faker.Create <QuestionWithCtor>(); Assert.AreEqual(42, q.Answer); Assert.AreEqual(default(int), q.UnsettedAnswer); Assert.AreEqual(default(int), q.AnswerField); }
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(); }
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()); }
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()); }
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)); }
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); }
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(); }
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(); }
static void Main(string[] args) { var fakerConfig = new FakerConfig(); fakerConfig.AddRule <StringGenClass, string, CustomStringGenerator>(c => c.s2); fakerConfig.AddRule <SimpleStruct, string, CustomStringGenerator>(c => c.field1); Faker f2 = new Faker(fakerConfig); f2.MaxCircularDependencyDepth = 1; var exp1 = f2.Create <Circular1>(); var exp2 = f2.Create <NestedClass>(); var exp3 = f2.Create <PubCtorStruct>(); var exp4 = f2.Create <StringGenClass>(); var exp5 = f2.Create <SimpleStruct>(); var exp6 = f2.Create <PrivSetClass>(); var exp7 = f2.Create <int>(); var exp8 = f2.Create <DateTime>(); var exp9 = f2.Create <string>(); }
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); }
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); }
public void Setup() { _config = new FakerConfig(); _faker = new Faker(_config); }
public Faker(FakerConfig config) : this() { _generator.Config = config; }
public void ShouldDetectWrongGeneratorType() { FakerConfig fakerConfig = new FakerConfig(); Assert.Throws <FakerConfigException>(() => fakerConfig.Add <Foo, double>(foo => foo.doubleValue, new CityGenerator())); }