public void SetEntityNameAsCustomNameInDataProvider()
        {
            // Arrange
            var entityData = new List <EntityData>
            {
                new EntityDataBuilder("MyEntity",
                                      "MyInteger")
                .WithEntity("1")
                .Build()
            };

            // Act
            var repository = new InMemoryRepository();

            _cherrySeedDriver.InitAndSeed(entityData.ToDictionaryDataProvider(), repository, cfg =>
            {
                cfg.ForEntity <EntityWithSimpleProperties>()
                .HasEntityName("MyEntity");
            });

            // Assert
            Assert.AreEqual(repository.CountSeededObjects(), 1);
            Assert.AreEqual(repository.CountSeededObjects <EntityWithSimpleProperties>(), 1);
            EntityAsserts.AssertEntityWithSimpleProperties(repository.GetEntities <EntityWithSimpleProperties>().First(), new EntityWithSimpleProperties
            {
                MyInteger = 1
            });
        }
        public void TransformNullablePropertyTypesWithNull()
        {
            // Arrange
            var entityData = new List <EntityData>
            {
                new EntityDataBuilder("CherrySeed.Test.Models.EntityWithNullableProperties",
                                      "MyInteger", "MyString", "MyBool", "MyDateTime", "MyDouble", "MyDecimal")
                .WithEntity("", "", "", "", "", "")
                .Build()
            };

            // Act
            var repository = new InMemoryRepository();

            _cherrySeedDriver.InitAndSeed(entityData.ToDictionaryDataProvider(), repository, cfg =>
            {
                cfg.ForEntity <EntityWithNullableProperties>();
            });

            // Assert
            Assert.AreEqual(1, repository.CountSeededObjects());
            Assert.AreEqual(1, repository.CountSeededObjects <EntityWithNullableProperties>());
            EntityAsserts.AssertEntityWithNullableProperties(repository.GetEntities <EntityWithNullableProperties>().First(), new EntityWithNullableProperties
            {
                MyInteger  = null,
                MyString   = null,
                MyBool     = null,
                MyDateTime = null,
                MyDouble   = null,
                MyDecimal  = null
            });
        }
Beispiel #3
0
        public void CustomPrimaryKeyIdGeneration()
        {
            // Arrange
            var entityData = new List <EntityData>
            {
                new EntityDataBuilder("CherrySeed.Test.Models.EntityWithConformStringPk",
                                      "Id")
                .WithEntity("E1")
                .WithEntity("E2")
                .Build()
            };

            // Act
            var repository = new InMemoryRepository();

            _cherrySeedDriver.InitAndSeed(entityData.ToDictionaryDataProvider(), repository, cfg =>
            {
                cfg.WithCustomPrimaryKeyIdGenerationInApplication(new SequentialStringPrimaryKeyIdGenerator("CUSTOM"));

                cfg.ForEntity <EntityWithConformStringPk>();
            });

            // Assert
            Assert.AreEqual(2, repository.CountSeededObjects());
            Assert.AreEqual(2, repository.CountSeededObjects <EntityWithConformStringPk>());
            EntityAsserts.AssertEntityWithConformStringPk(repository.GetEntities <EntityWithConformStringPk>()[0], new EntityWithConformStringPk
            {
                Id = "CUSTOM1"
            });
            EntityAsserts.AssertEntityWithConformStringPk(repository.GetEntities <EntityWithConformStringPk>()[1], new EntityWithConformStringPk
            {
                Id = "CUSTOM2"
            });
        }
Beispiel #4
0
        public void TransformNullableEnumTypesWithNumbers()
        {
            // Arrange
            var entityData = new List <EntityData>
            {
                new EntityDataBuilder("CherrySeed.Test.Models.EntityWithNullableEnumProperty",
                                      "EnumProperty1", "EnumProperty2")
                .WithEntity("0", "1")
                .Build()
            };

            // Act
            var repository = new InMemoryRepository();

            _cherrySeedDriver.InitAndSeed(entityData.ToDictionaryDataProvider(), repository, cfg =>
            {
                cfg.ForEntity <EntityWithNullableEnumProperty>();
            });

            // Assert
            Assert.AreEqual(1, repository.CountSeededObjects());
            Assert.AreEqual(1, repository.CountSeededObjects <EntityWithNullableEnumProperty>());
            EntityAsserts.AssertEntityWithNullableEnumProperty(repository.GetEntities <EntityWithNullableEnumProperty>().First(), new EntityWithNullableEnumProperty
            {
                EnumProperty1 = TestEnum.EnumValue1,
                EnumProperty2 = TestEnum.EnumValue2
            });
        }
Beispiel #5
0
        public void DisablePrimaryKeyIdGeneration()
        {
            // Arrange
            var entityData = new List <EntityData>
            {
                new EntityDataBuilder("CherrySeed.Test.Models.EntityWithConformIntPk",
                                      "Id")
                .WithEntity("10")
                .WithEntity("20")
                .Build()
            };

            // Act
            var repository = new InMemoryRepository();

            _cherrySeedDriver.InitAndSeed(entityData.ToDictionaryDataProvider(), repository, cfg =>
            {
                cfg.DisablePrimaryKeyIdGeneration();

                cfg.ForEntity <EntityWithConformIntPk>();
            });

            // Assert
            Assert.AreEqual(2, repository.CountSeededObjects());
            Assert.AreEqual(2, repository.CountSeededObjects <EntityWithConformIntPk>());
            EntityAsserts.AssertEntityWithConformIntPk(repository.GetEntities <EntityWithConformIntPk>()[0], new EntityWithConformIntPk
            {
                Id = 10
            });
            EntityAsserts.AssertEntityWithConformIntPk(repository.GetEntities <EntityWithConformIntPk>()[1], new EntityWithConformIntPk
            {
                Id = 20
            });
        }
        public void TransformSimplePropertyTypes()
        {
            // Arrange
            var entityData = new List <EntityData>
            {
                new EntityDataBuilder("CherrySeed.Test.Models.EntityWithSimpleProperties",
                                      "MyInteger", "MyString", "MyBool", "MyDateTime", "MyDouble", "MyDecimal")
                .WithEntity("1", "MyString 1", "true", "2016/05/03", "123,12", "12,33")
                .Build()
            };

            // Act
            var repository = new InMemoryRepository();

            _cherrySeedDriver.InitAndSeed(entityData.ToDictionaryDataProvider(), repository, cfg =>
            {
                cfg.ForEntity <EntityWithSimpleProperties>();
            });

            // Assert
            Assert.AreEqual(repository.CountSeededObjects(), 1);
            Assert.AreEqual(repository.CountSeededObjects <EntityWithSimpleProperties>(), 1);
            EntityAsserts.AssertEntityWithSimpleProperties(repository.GetEntities <EntityWithSimpleProperties>().First(), new EntityWithSimpleProperties
            {
                MyInteger  = 1,
                MyString   = "MyString 1",
                MyBool     = true,
                MyDateTime = new DateTime(2016, 5, 3),
                MyDouble   = 123.12,
                MyDecimal  = 12.33m
            });
        }
        public void TransformSimplePropertyTypesWithEmptyString()
        {
            // Arrange
            var entityData = new List <EntityData>
            {
                new EntityDataBuilder("CherrySeed.Test.Models.EntityWithSimpleProperties",
                                      "MyString")
                .WithEntity("$EMPTY$")
                .Build()
            };

            // Act
            var repository = new InMemoryRepository();

            _cherrySeedDriver.InitAndSeed(entityData.ToDictionaryDataProvider(), repository, cfg =>
            {
                cfg.ForEntity <EntityWithSimpleProperties>();
            });

            // Assert
            Assert.AreEqual(repository.CountSeededObjects(), 1);
            Assert.AreEqual(repository.CountSeededObjects <EntityWithSimpleProperties>(), 1);
            EntityAsserts.AssertEntityWithSimpleProperties(repository.GetEntities <EntityWithSimpleProperties>().First(), new EntityWithSimpleProperties
            {
                MyString = string.Empty
            });
        }
        public void TransformPropertyWithNotSupportedTypeTransformation()
        {
            // Arrange
            var entityData = new List <EntityData>
            {
                new EntityDataBuilder("CherrySeed.Test.Models.EntityWithNotSupportedTypeProperty",
                                      "UintProperty")
                .WithEntity("12345")
                .Build()
            };

            // Act
            var repository = new InMemoryRepository();

            _cherrySeedDriver.InitAndSeed(entityData.ToDictionaryDataProvider(), repository, cfg =>
            {
                cfg.AddTypeTransformation(typeof(uint), new CustomTypeTransformation <uint>(123));
                cfg.ForEntity <EntityWithNotSupportedTypeProperty>();
            });

            // Assert
            Assert.AreEqual(1, repository.CountSeededObjects());
            Assert.AreEqual(1, repository.CountSeededObjects <EntityWithNotSupportedTypeProperty>());
            EntityAsserts.AssertEntityWithNotSupportedProperty(repository.GetEntities <EntityWithNotSupportedTypeProperty>().First(), new EntityWithNotSupportedTypeProperty
            {
                UintProperty = 123
            });
        }
        public void TransformPropertyWithOverridenTypeTransformation()
        {
            // Arrange
            var entityData = new List <EntityData>
            {
                new EntityDataBuilder("CherrySeed.Test.Models.EntityWithSimpleProperties",
                                      "MyString")
                .WithEntity("This is a sample text")
                .Build()
            };

            // Act
            var repository = new InMemoryRepository();

            _cherrySeedDriver.InitAndSeed(entityData.ToDictionaryDataProvider(), repository, cfg =>
            {
                cfg.AddTypeTransformation(typeof(string), new CustomTypeTransformation <string>("New sample text"));
                cfg.ForEntity <EntityWithSimpleProperties>();
            });

            // Assert
            Assert.AreEqual(1, repository.CountSeededObjects());
            Assert.AreEqual(1, repository.CountSeededObjects <EntityWithSimpleProperties>());
            EntityAsserts.AssertEntityWithSimpleProperties(repository.GetEntities <EntityWithSimpleProperties>().First(), new EntityWithSimpleProperties
            {
                MyString = "New sample text"
            });
        }
        public void Convention_PrimaryKeyWithNameClassNameAndId()
        {
            // Arrange
            var entityData = new List <EntityData>
            {
                new EntityDataBuilder("CherrySeed.Test.Models.EntityWithConformIntPk3",
                                      "EntityWithConformIntPk3Id")
                .WithEntity("E1")
                .Build()
            };

            // Act
            var repository = new InMemoryRepository();

            _cherrySeedDriver.InitAndSeed(entityData.ToDictionaryDataProvider(), repository, cfg =>
            {
                cfg.WithPrimaryKeyIdGenerationInApplicationAsInteger();

                cfg.ForEntity <EntityWithConformIntPk3>();
            });

            // Assert
            Assert.AreEqual(1, repository.CountSeededObjects());
            Assert.AreEqual(1, repository.CountSeededObjects <EntityWithConformIntPk3>());
            EntityAsserts.AssertEntityWithConformIntPk3(repository.GetEntities <EntityWithConformIntPk3>().First(), new EntityWithConformIntPk3
            {
                EntityWithConformIntPk3Id = 1
            });
        }
        public void GuidIdReference()
        {
            // Arrange
            var entityData = new List <EntityData>
            {
                new EntityDataBuilder("CherrySeed.Test.Models.EntityWithConformGuidPk",
                                      "Id")
                .WithEntity("E1")
                .WithEntity("E2")
                .Build(),
                new EntityDataBuilder("CherrySeed.Test.Models.EntityWithGuidReference",
                                      "ReferenceId")
                .WithEntity("E2")
                .WithEntity("E2")
                .Build(),
            };

            // Act
            var repository = new InMemoryRepository();

            _cherrySeedDriver.InitAndSeed(entityData.ToDictionaryDataProvider(), repository, cfg =>
            {
                cfg.WithCustomPrimaryKeyIdGenerationInApplication(new SequentialGuidPrimaryKeyIdGenerator());

                cfg.ForEntity <EntityWithConformGuidPk>();
                cfg.ForEntity <EntityWithGuidReference>()
                .WithReference(e => e.ReferenceId, typeof(EntityWithConformGuidPk));
            });

            // Assert
            Assert.AreEqual(4, repository.CountSeededObjects());
            Assert.AreEqual(2, repository.CountSeededObjects <EntityWithConformGuidPk>());
            Assert.AreEqual(2, repository.CountSeededObjects <EntityWithGuidReference>());
            EntityAsserts.AssertEntityWithConformGuidPk(repository.GetEntities <EntityWithConformGuidPk>()[0], new EntityWithConformGuidPk
            {
                Id = 1.ToGuid()
            });
            EntityAsserts.AssertEntityWithConformGuidPk(repository.GetEntities <EntityWithConformGuidPk>()[1], new EntityWithConformGuidPk
            {
                Id = 2.ToGuid()
            });

            EntityAsserts.AssertEntityWithGuidReference(repository.GetEntities <EntityWithGuidReference>()[0], new EntityWithGuidReference
            {
                ReferenceId = 2.ToGuid()
            });
            EntityAsserts.AssertEntityWithGuidReference(repository.GetEntities <EntityWithGuidReference>()[1], new EntityWithGuidReference
            {
                ReferenceId = 2.ToGuid()
            });
        }
Beispiel #12
0
        public void EntityPropertiesWithDefaultValues_OverrideDefaultValuesInDataProvider()
        {
            // Arrange
            var entityData = new List <EntityData>
            {
                new EntityDataBuilder("CherrySeed.Test.Models.EntityWithSimpleProperties", "MyBool", "MyString")
                .WithEntity("false", "My string from data provider")
                .Build()
            };

            // Act
            var repository = new InMemoryRepository();

            _cherrySeedDriver.InitAndSeed(entityData.ToDictionaryDataProvider(), repository, cfg =>
            {
                cfg.ForEntity <EntityWithSimpleProperties>()
                .WithFieldWithDefaultValue(e => e.MyBool, () => true)
                .WithFieldWithDefaultValue(e => e.MyDateTime, () => new DateTime(2016, 10, 15))
                .WithFieldWithDefaultValue(e => e.MyDecimal, () => 12.12m)
                .WithFieldWithDefaultValue(e => e.MyDouble, () => 123.123)
                .WithFieldWithDefaultValue(e => e.MyInteger, () => 9988)
                .WithFieldWithDefaultValue(e => e.MyString, () => "My default string");
            });

            // Assert
            Assert.AreEqual(1, repository.CountSeededObjects());
            Assert.AreEqual(1, repository.CountSeededObjects <EntityWithSimpleProperties>());
            EntityAsserts.AssertEntityWithSimpleProperties(repository.GetEntities <EntityWithSimpleProperties>().First(), new EntityWithSimpleProperties
            {
                MyInteger  = 9988,
                MyString   = "My string from data provider",
                MyBool     = false,
                MyDateTime = new DateTime(2016, 10, 15),
                MyDouble   = 123.123,
                MyDecimal  = 12.12m
            });
        }
        public void IntegerModelReference()
        {
            // Arrange
            var entityData = new List <EntityData>
            {
                new EntityDataBuilder("CherrySeed.Test.Models.EntityWithConformIntPk",
                                      "Id")
                .WithEntity("E1")
                .WithEntity("E2")
                .Build(),
                new EntityDataBuilder("CherrySeed.Test.Models.EntityWithIntReferenceModel",
                                      "ReferenceModel")
                .WithEntity("E2")
                .WithEntity("E2")
                .Build(),
            };

            // Act
            var repository = new InMemoryRepository((o, id) =>
            {
                var pk = o as EntityWithConformIntPk;
                if (pk != null)
                {
                    return(pk.Id == (int)id);
                }

                throw new InvalidOperationException("Failed");
            });

            _cherrySeedDriver.InitAndSeed(entityData.ToDictionaryDataProvider(), repository, cfg =>
            {
                cfg.WithPrimaryKeyIdGenerationInApplicationAsInteger();

                cfg.ForEntity <EntityWithConformIntPk>();
                cfg.ForEntity <EntityWithIntReferenceModel>()
                .WithReference(e => e.ReferenceModel, typeof(EntityWithConformIntPk));
            });

            // Assert
            Assert.AreEqual(4, repository.CountSeededObjects());
            Assert.AreEqual(2, repository.CountSeededObjects <EntityWithConformIntPk>());
            Assert.AreEqual(2, repository.CountSeededObjects <EntityWithIntReferenceModel>());
            EntityAsserts.AssertEntityWithConformIntPk(repository.GetEntities <EntityWithConformIntPk>()[0], new EntityWithConformIntPk
            {
                Id = 1
            });
            EntityAsserts.AssertEntityWithConformIntPk(repository.GetEntities <EntityWithConformIntPk>()[1], new EntityWithConformIntPk
            {
                Id = 2
            });

            EntityAsserts.AssertEntityWithIntReferenceModel(repository.GetEntities <EntityWithIntReferenceModel>()[0], new EntityWithIntReferenceModel
            {
                ReferenceModel = new EntityWithConformIntPk {
                    Id = 2
                }
            });
            EntityAsserts.AssertEntityWithIntReferenceModel(repository.GetEntities <EntityWithIntReferenceModel>()[1], new EntityWithIntReferenceModel
            {
                ReferenceModel = new EntityWithConformIntPk {
                    Id = 2
                }
            });
        }