public void CreateItemsWithComposedStrategy()
        {
            var cities = new[] { "Berlin", "Köln", "Dresden" };

            // define the strategy for Person
            var personStrategy = new DataCreationStrategy <Person>();

            personStrategy.Add(p => p.Age, new IntegerStrategy()).Min(10).Max(100);
            personStrategy.Add(p => p.FirstName, new StringStrategy()).Length(35);
            personStrategy.Add(p => p.LastName, new StringStrategy()).Length(20).Prefix("CC_");

            // define the strategy for Address
            var addressStrategy = new DataCreationStrategy <Address>();

            addressStrategy.Add(a => a.City, new StringStrategy()).OneOfTheseValues(cities);

            // add the strategy for adress to the strategy for person
            personStrategy.Add <Address, DataCreationStrategy <Address> >(p => p.HomeAddress, addressStrategy);

            var items = Common.CreateItems(100, personStrategy);

            Assert.IsTrue(items.All(i => i.HomeAddress != null));
            Assert.IsTrue(items.All(i => i.FirstName.Length == 35));
            Assert.IsTrue(items.All(i => i.LastName.Length == 20));
            Assert.IsTrue(items.All(i => i.LastName.StartsWith("CC_")));
            Assert.IsTrue(items.All(i => cities.Contains(i.HomeAddress.City)));
        }
        public void CreateItemsWithCombinedStringStrategyPrefixMaxLength()
        {
            var strategy = new DataCreationStrategy <Person>();

            strategy.Add(p => p.FirstName, new StringStrategy()).Prefix("ABCD");
            strategy.Add(p => p.LastName, new StringStrategy()).Length(20);

            var items = Common.CreateItems(10, strategy).ToList();

            Assert.IsTrue(items.All(i => i.FirstName.StartsWith("ABCD")));
            Assert.IsTrue(items.All(i => i.FirstName.Length != 20));
            Assert.IsTrue(items.All(i => i.LastName.Length == 20));
        }
        public void CreateItemsWithStringStrategySuffix()
        {
            var strategy = new DataCreationStrategy <Person>();

            strategy.Add(p => p.FirstName, new StringStrategy()).Suffix("WXYZ").Length(20);
            strategy.Add(p => p.Age, new IntegerStrategy()).Min(10).Max(90);

            var items = Common.CreateItems(10, strategy).ToList();

            Assert.IsTrue(items.All(i => i.FirstName.EndsWith("WXYZ")));
            Assert.IsTrue(items.All(i => i.FirstName.Length == 20));
            Assert.IsTrue(items.All(i => i.Age >= 10 && i.Age <= 90));
        }
        public void CreateValueConditional()
        {
            DataCreationStrategy <Person> strategyPerson = new DataCreationStrategy <Person>();

            // create default values
            strategyPerson.Add(p => p.Age, new IntegerStrategy()).OneOfTheseValues(30, 31, 32, 33);
            strategyPerson.Add(p => p.IsMember, new BooleanStrategy()).Toggle();

            // apply conditional values
            strategyPerson.When(p => p.Age == 32).Then(p => p.IsMember, new BooleanStrategy()).Value(true);

            // create items
            var items = Common.CreateItems(1000, strategyPerson).ToList();

            // assert data
            Assert.IsTrue(items.Where(p => p.Age == 32).All(p => p.IsMember == true));
            Assert.IsFalse(items.Where(p => p.Age != 32).All(p => p.IsMember == true));
        }
Ejemplo n.º 5
0
        public void TestToggleValue()
        {
            var strategy = new DataCreationStrategy <Person>();

            strategy.Add(p => p.IsMember, new BooleanStrategy()).Toggle();

            var items = Common.CreateItems(100, strategy).ToList();

            Assert.IsTrue(items.Count(p => p.IsMember == true) == items.Count(p => p.IsMember == false));
        }
Ejemplo n.º 6
0
        public void TestStaticValue()
        {
            var strategy = new DataCreationStrategy <Person>();

            strategy.Add(p => p.IsMember, new BooleanStrategy()).Value(true);

            var items = Common.CreateItems(100, strategy);

            Assert.IsTrue(items.All(p => p.IsMember == true));
        }
        public void CreateItemsWithValue()
        {
            var personStrategy = new DataCreationStrategy <Person>();

            personStrategy.Add(p => p.FirstName, new StringStrategy()).Value("Hallo");

            var items = Common.CreateItems(200, personStrategy);

            Assert.IsTrue(items.All(p => p.FirstName.Equals("Hallo")));
        }
        public void CreateItemWithGuidStrategyNotEmpty()
        {
            var personStrategy = new DataCreationStrategy <Person>();

            personStrategy.Add(p => p.Id, new GuidStrategy()).CreateNew();

            var items = Common.CreateItems(100, personStrategy);

            Assert.IsTrue(items.All(i => !i.Id.Equals(Guid.Empty)));
        }
        public void CreateItemsWithExplicitValue()
        {
            var personStrategy = new DataCreationStrategy <Person>();

            personStrategy.Add(p => p.Age, new IntegerStrategy()).Value(42);

            var people = Common.CreateItems(100, personStrategy).ToList();

            Assert.IsTrue(people.All(p => p.Age == 42));
        }
        public void CreateItemsWithUniqueValue()
        {
            var personStrategy = new DataCreationStrategy <Person>();

            personStrategy.Add(p => p.Age, new IntegerStrategy()).Unique();

            var people = Common.CreateItems(200, personStrategy).ToList();

            Assert.IsTrue(people.Select(p => p.Age).Distinct().Count() == 200);
        }
        public void CreateItemsWithStringStrategyOneOfTheseValuesInTwoFields()
        {
            var firstNameTemplates = new[] { "John", "Paul", "George", "Ringo" };
            var lastNameTemplates  = new[] { "Lennon", "McCartney", "Harrison", "Starr" };

            var strategy = new DataCreationStrategy <Person>();

            strategy.Add(p => p.FirstName, new StringStrategy()).OneOfTheseValues(firstNameTemplates);
            strategy.Add(p => p.LastName, new StringStrategy()).OneOfTheseValues(lastNameTemplates);

            var items = Common.CreateItems(100, strategy).ToList();


            Assert.IsTrue(items.All(i => firstNameTemplates.Contains(i.FirstName)));
            Assert.IsTrue(items.All(i => i.FirstName.IsOneOfTheseValues(firstNameTemplates)));

            Assert.IsTrue(items.All(i => lastNameTemplates.Contains(i.LastName)));
            Assert.IsTrue(items.All(i => i.LastName.IsOneOfTheseValues(lastNameTemplates)));
        }
        public void CreateItemsWithMinMax()
        {
            // Definiere die Datenstrategy
            var strategy = new DataCreationStrategy <Person>();

            strategy.Add(p => p.Age, new IntegerStrategy()).Min(10).Max(100);

            var peoply = Common.CreateItems(10, strategy).ToList();

            Assert.IsFalse(peoply.Any(p => p.Age < 10 || p.Age > 100));
        }
        public void CreateItemsWithStringStrategyOneOfTheseValuesIgnoringMaxLength()
        {
            var strategy = new DataCreationStrategy <Person>();

            strategy.Add(p => p.FirstName, new StringStrategy())
            .Length(2)
            .OneOfTheseValues("John", "Paul", "George", "Ringo");

            var items = Common.CreateItems(10, strategy).ToList();

            Assert.IsFalse(items.Any(i => i.FirstName.Length <= 2));
        }
        public void CreateItemsWithDecrement()
        {
            // Definiere die Datenstrategy
            var strategy = new DataCreationStrategy <Person>();

            strategy.Add(p => p.Age, new IntegerStrategy()).Decrement(20);

            var people = Common.CreateItems(100, strategy).ToList();

            Assert.IsTrue(people.Distinct().Count() == 100);
            Assert.IsTrue(people.Select(p => p.Age).IsDescending());
        }
Ejemplo n.º 15
0
        public void CreateItemsWithCustomStrategy()
        {
            var emailStrategy = new EmailStrategy();

            var strategy = new DataCreationStrategy <Person>();

            strategy.Add(p => p.EMail, emailStrategy);

            var items = Common.CreateItems(100, strategy);

            Assert.IsTrue(items.All(i => i.EMail.Equals("*****@*****.**")));
        }
        public void CreateItemWithSpecificValue()
        {
            var personStrategy = new DataCreationStrategy <Person>();

            Guid value = Guid.NewGuid();

            personStrategy.Add(p => p.Id, new GuidStrategy()).Value(value);

            var items = Common.CreateItems(100, personStrategy);

            Assert.IsTrue(items.All(p => p.Id.Equals(value)));
        }
        public void CreateItemsWithStringStrategyMaxLength()
        {
            var strategy = new DataCreationStrategy <Person>();

            strategy.Add(p => p.FirstName, new StringStrategy())

            .Length(153);

            var items = Common.CreateItems(10, strategy).ToList();

            Assert.IsTrue(items.All(i => i.FirstName.Length == 153));
        }
        public void UseCustomStrategyWithInitialize()
        {
            var strategy = new DataCreationStrategy<Person>();

            strategy.Add(p => p.FirstName, new CustomStrategyWithInitialize());

            var items = Common.CreateItems(200, strategy);

            Assert.IsTrue(items.All(p => p.FirstName.Equals(nameof(Person.FirstName))));



        }
        public void CreateItemsWithStringStrategyOneOfTheseValues()
        {
            var strategy = new DataCreationStrategy <Person>();

            strategy.Add(p => p.FirstName, new StringStrategy()).OneOfTheseValues("John", "Paul", "George", "Ringo");

            var items = Common.CreateItems(100, strategy).ToList();

            var template = new[] { "John", "Paul", "George", "Ringo" };

            Assert.IsTrue(items.All(i => template.Contains(i.FirstName)));

            template.ToList().ForEach(name => Assert.IsTrue(items.Any(i => i.FirstName.Equals(name))));
        }
        public TestResult CreateItemsWithComposedStrategy(TestStrategy strategy)
        {
            // define the strategy for Person
            var personStrategy = new DataCreationStrategy <Person>();

            personStrategy.Add(p => p.Age, new IntegerStrategy()).Min(10).Max(100);
            personStrategy.Add(p => p.FirstName, new StringStrategy()).Length(35);
            personStrategy.Add(p => p.LastName, new StringStrategy()).Length(20).Prefix("CC_");

            // add the strategy for adress to the strategy for person
            personStrategy.Add(p => p.HomeAddress, strategy.HomeAddress);
            personStrategy.Add(p => p.BusinessAddress, strategy.BusinessAddress);

            var items = Common.CreateItems(100, personStrategy);

            Assert.IsTrue(items.All(i => i.FirstName.Length == 35));
            Assert.IsTrue(items.All(i => i.LastName.Length == 20));
            Assert.IsTrue(items.All(i => i.LastName.StartsWith("CC_")));

            return(new TestResult {
                Persons = new List <Person>(items)
            });
        }
Ejemplo n.º 21
0
        public void TestListOfItemsWithReset()
        {
            var subtypeStrategy = new DataCreationStrategy <SubType>();

            subtypeStrategy.Add(s => s.Value, new IntegerStrategy()).Increment(100);

            var primaryTypeStrategy = new DataCreationStrategy <PrimaryType>();

            primaryTypeStrategy.Add(p => p.SubTypes, new ListStrategy <SubType>(subtypeStrategy)).Amount(10);

            var items = Common.CreateItems(100, primaryTypeStrategy).ToList();

            Assert.IsTrue(items.All(p => p.SubTypes.First().Value == 100));
        }
        public void CreateItemsWithOneOfTheseChars()
        {
            var strategy = new DataCreationStrategy <Person>();

            var requestedChars = new[] { '%', (char)34, (char)32, '{', '}' };

            strategy.Add(p => p.LastName, new StringStrategy())
            .Length(20)
            .HasOneOfTheseChars(requestedChars);

            var items = Common.CreateItems(100, strategy).ToList();

            Assert.IsTrue(items.All(p => p.LastName.Length == 20));
            Assert.IsTrue(items.All(p => p.LastName.IndexOfAny(requestedChars) >= 0));
        }
        public void CreateItemsWithOneOfTheseValuesByCreatedStrategy()
        {
            // Definiere die Datenstrategy
            var strategy = new DataCreationStrategy <Person>();

            strategy.Add <int, IntegerStrategy>(p => p.Age).OneOfTheseValues(10, 20, 30);

            var people = Common.CreateItems(100, strategy).ToList();

            var template = new[] { 10, 20, 30 };

            Assert.IsTrue(people.All(p => template.Contains(p.Age)));
            Assert.IsTrue(people.Any(p => p.Age == 10));
            Assert.IsTrue(people.Any(p => p.Age == 20));
            Assert.IsTrue(people.Any(p => p.Age == 30));
        }
Ejemplo n.º 24
0
        public void TestListOfNumbers()
        {
            var strategy = new DataCreationStrategy <Person>();

            var intstrategy = new IntegerStrategy();

            intstrategy.Value(42);

            var liststrategy = new ListStrategy <int>(intstrategy);

            strategy.Add(p => p.Changes, liststrategy).Amount(249);

            var items = Common.CreateItems(10, strategy).ToList();

            Assert.IsTrue(items.All(p => p.Changes.Count == 249));
            Assert.IsTrue(items.All(p => p.Changes.All(c => c == 42)));
        }
Ejemplo n.º 25
0
        public void TestListOfNumbersWithVariableItems()
        {
            var strategy = new DataCreationStrategy <Person>();

            var intstrategy = new IntegerStrategy();

            intstrategy.Value(42);

            var liststrategy = new ListStrategy <int>(intstrategy);

            strategy.Add(p => p.Changes, liststrategy).Min(10).Max(20);

            var items = Common.CreateItems(100, strategy).ToList();

            Assert.IsTrue(items.Select(p => p.Changes.Count).Distinct().ToList().Count == 10);
            Assert.IsTrue(items.All(p => p.Changes.All(c => c == 42)));
        }