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 TransformNullablePropertyTypes() { // Arrange var entityData = new List <EntityData> { new EntityDataBuilder("CherrySeed.Test.Models.EntityWithNullableProperties", "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 <EntityWithNullableProperties>(); }); // Assert Assert.AreEqual(1, repository.CountSeededObjects()); Assert.AreEqual(1, repository.CountSeededObjects <EntityWithNullableProperties>()); EntityAsserts.AssertEntityWithNullableProperties(repository.GetEntities <EntityWithNullableProperties>().First(), new EntityWithNullableProperties { MyInteger = 1, MyString = "MyString 1", MyBool = true, MyDateTime = new DateTime(2016, 5, 3), MyDouble = 123.12, MyDecimal = 12.33m }); }
public void TransformNullableEnumTypes() { // Arrange var entityData = new List <EntityData> { new EntityDataBuilder("CherrySeed.Test.Models.EntityWithNullableEnumProperty", "EnumProperty1", "EnumProperty2") .WithEntity("EnumValue1", "EnumValue2") .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 SetEntityNameAsFullNameInDataProvider() { // Arrange var entityData = new List <EntityData> { new EntityDataBuilder("CherrySeed.Test.Models.EntityWithSimpleProperties", "MyInteger") .WithEntity("1") .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 }); }
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_PrimaryKeyWithNameId() { // Arrange var entityData = new List <EntityData> { new EntityDataBuilder("CherrySeed.Test.Models.EntityWithConformIntPk", "Id") .WithEntity("E1") .Build() }; // Act var repository = new InMemoryRepository(); _cherrySeedDriver.InitAndSeed(entityData.ToDictionaryDataProvider(), repository, cfg => { cfg.WithPrimaryKeyIdGenerationInApplicationAsInteger(); cfg.ForEntity <EntityWithConformIntPk>(); }); // Assert Assert.AreEqual(1, repository.CountSeededObjects()); Assert.AreEqual(1, repository.CountSeededObjects <EntityWithConformIntPk>()); EntityAsserts.AssertEntityWithConformIntPk(repository.GetEntities <EntityWithConformIntPk>().First(), new EntityWithConformIntPk { Id = 1 }); }
public void EntityPropertiesWithDefaultValues() { // Arrange var entityData = new List <EntityData> { new EntityDataBuilder("CherrySeed.Test.Models.EntityWithSimpleProperties") .WithEntity() .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 default string", MyBool = true, MyDateTime = new DateTime(2016, 10, 15), MyDouble = 123.123, MyDecimal = 12.12m }); }
public void IntegerIdReference() { // Arrange var entityData = new List <EntityData> { new EntityDataBuilder("CherrySeed.Test.Models.EntityWithConformIntPk", "Id") .WithEntity("E1") .WithEntity("E2") .Build(), new EntityDataBuilder("CherrySeed.Test.Models.EntityWithIntReference", "ReferenceId") .WithEntity("E2") .WithEntity("E2") .Build(), }; // Act var repository = new InMemoryRepository(); _cherrySeedDriver.InitAndSeed(entityData.ToDictionaryDataProvider(), repository, cfg => { cfg.WithPrimaryKeyIdGenerationInApplicationAsInteger(); cfg.ForEntity <EntityWithConformIntPk>(); cfg.ForEntity <EntityWithIntReference>() .WithReference(e => e.ReferenceId, typeof(EntityWithConformIntPk)); }); // Assert Assert.AreEqual(4, repository.CountSeededObjects()); Assert.AreEqual(2, repository.CountSeededObjects <EntityWithConformIntPk>()); Assert.AreEqual(2, repository.CountSeededObjects <EntityWithIntReference>()); EntityAsserts.AssertEntityWithConformIntPk(repository.GetEntities <EntityWithConformIntPk>()[0], new EntityWithConformIntPk { Id = 1 }); EntityAsserts.AssertEntityWithConformIntPk(repository.GetEntities <EntityWithConformIntPk>()[1], new EntityWithConformIntPk { Id = 2 }); EntityAsserts.AssertEntityWithIntReference(repository.GetEntities <EntityWithIntReference>()[0], new EntityWithIntReference { ReferenceId = 2 }); EntityAsserts.AssertEntityWithIntReference(repository.GetEntities <EntityWithIntReference>()[1], new EntityWithIntReference { ReferenceId = 2 }); }
public void SetGlobalAndEntitySpecificActions() { // Arrange var entityData = new List <EntityData> { new EntityDataBuilder("CherrySeed.Test.Models.EntityWithSimpleProperties", "MyInteger", "MyString") .WithEntity("1", "MyString 1") .Build() }; var globalBeforeSaveCallCounter = 0; var globalAfterSaveCallCounter = 0; var entityAfterSaveCallCounter = 0; // Act var repository = new InMemoryRepository(); _cherrySeedDriver.InitAndSeed(entityData.ToDictionaryDataProvider(), repository, cfg => { cfg.BeforeSave((dictionary, o) => { globalBeforeSaveCallCounter++; }); cfg.AfterSave(((dictionary, o) => { globalAfterSaveCallCounter++; })); cfg.ForEntity <EntityWithSimpleProperties>() .AfterSave((o => { entityAfterSaveCallCounter++; })); }); // Assert Assert.AreEqual(1, globalBeforeSaveCallCounter); Assert.AreEqual(1, globalAfterSaveCallCounter); Assert.AreEqual(1, entityAfterSaveCallCounter); }