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 }); }
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 SeedingMultipleEntities() { // 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") .WithEntity("2", "MyString 1", "true", "2016/05/03", "123,12", "12,33") .Build(), new EntityDataBuilder("CherrySeed.Test.Models.EntityWithNullableProperties", "MyInteger", "MyString", "MyBool", "MyDateTime", "MyDouble", "MyDecimal") .WithEntity("1", "MyString 1", "true", "2016/05/03", "123,12", "12,33") .WithEntity("2", "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>(); cfg.ForEntity <EntityWithNullableProperties>(); }); // Assert Assert.AreEqual(repository.CountSeededObjects(), 4); Assert.AreEqual(repository.CountSeededObjects <EntityWithSimpleProperties>(), 2); Assert.AreEqual(repository.CountSeededObjects <EntityWithNullableProperties>(), 2); Assert.IsTrue(repository.GetSeedingDateTime <EntityWithSimpleProperties>().Ticks < repository.GetSeedingDateTime <EntityWithNullableProperties>().Ticks); }
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" }); }
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 }); }
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() }); }
public void SeedAndClear_ClearedSuccessfully() { // Arrange var countryTable = ObjectMother.CreateCountryTable(table => { table.AddRow("C1", "Austria"); table.AddRow("C2", "Germany"); }); var projectTable = ObjectMother.CreateProjectTable(table => { table.AddRow("P1", "Project1", "C1"); table.AddRow("P2", "Project2", "C2"); }); var repository = new InMemoryRepository(); var cherrySeedConfiguration = new CherrySeedConfiguration(cfg => { cfg.WithSpecFlowConfiguration(); cfg.WithRepository(repository); cfg.WithCountryAndProjectEntities(); cfg.ForEntity <Country>() .WithPrimaryKeyIdGenerationInApplicationAsInteger(); cfg.ForEntity <Project>() .WithPrimaryKeyIdGenerationInApplicationAsInteger(); }); var cherrySeeder = cherrySeedConfiguration.CreateSeeder(); cherrySeeder.Seed("Country", countryTable); cherrySeeder.Seed("Project", projectTable); Assert.AreEqual(4, repository.CountSeededObjects()); // Act - seeding countries cherrySeeder.Clear(); Assert.AreEqual(0, repository.CountSeededObjects()); }
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 SeedCountryAndProject_SeededSuccessfully() { // Arrange var countryTable = ObjectMother.CreateCountryTable(table => { table.AddRow("C1", "Austria"); table.AddRow("C2", "Germany"); }); var projectTable = ObjectMother.CreateProjectTable(table => { table.AddRow("P1", "Project1", "C1"); table.AddRow("P2", "Project2", "C2"); }); // Act - seeding countries var repository = new InMemoryRepository(); var cherrySeedConfiguration = new CherrySeedConfiguration(cfg => { cfg.WithSpecFlowConfiguration(); cfg.WithRepository(repository); cfg.WithCountryAndProjectEntities(); cfg.ForEntity <Country>() .WithPrimaryKeyIdGenerationInApplicationAsInteger(); cfg.ForEntity <Project>() .WithPrimaryKeyIdGenerationInApplicationAsInteger(); }); var cherrySeeder = cherrySeedConfiguration.CreateSeeder(); cherrySeeder.Seed("Country", countryTable); // Assert - countries Assert.AreEqual(2, repository.CountSeededObjects()); Assert.AreEqual(2, repository.CountSeededObjects <Country>()); EntityAsserts.AssertCountry(repository.GetEntities <Country>()[0], new Country { Id = 1, Name = "Austria" }); EntityAsserts.AssertCountry(repository.GetEntities <Country>()[1], new Country { Id = 2, Name = "Germany" }); // Act - seeding projects cherrySeeder.Seed("Project", projectTable); // Assert - projects Assert.AreEqual(4, repository.CountSeededObjects()); Assert.AreEqual(2, repository.CountSeededObjects <Project>()); EntityAsserts.AssertProject(repository.GetEntities <Project>()[0], new Project { Id = 1, Name = "Project1", CountryId = 1 }); EntityAsserts.AssertProject(repository.GetEntities <Project>()[1], new Project { Id = 2, Name = "Project2", CountryId = 2 }); }
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 } }); }