public IVolumeCharacterModel Update(IVolumeCharacterModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = VolumeCharactersRepository.Get(model.Id.Value); // Check if we would be applying identical information, if we are, just return the original // ReSharper disable once SuspiciousTypeConversion.Global if (VolumeCharacterMapper.AreEqual(model, existingEntity)) { return(VolumeCharacterMapper.MapToModel(existingEntity)); } // Map model to an existing entity VolumeCharacterMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it VolumeCharactersRepository.Update(VolumeCharacterMapper.MapToEntity(model)); // Try to Save Changes VolumeCharactersRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public IVolumeCharacterModel Create(IVolumeCharacterModel model) { // Validate model BusinessWorkflowBase.ValidateIDIsNull(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Search for an Existing Record (Don't allow Duplicates var results = Search(VolumeCharacterMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = VolumeCharacterMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it VolumeCharactersRepository.Add(newEntity); // Try to Save Changes VolumeCharactersRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public void Verify_AreEqual_WithDifferentObjects_ReturnsFalse() { // Arrange var mapper = new VolumeCharacterMapper(); var model = VolumeCharactersMockingSetup.DoMockingSetupForVolumeCharacterModel(1); var entity = VolumeCharactersMockingSetup.DoMockingSetupForVolumeCharacter(2); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.False(result); }
public void Verify_MapToModelLite_AssignsLiteOnlyVolumeCharacterProperties() { // Arrange var mapper = new VolumeCharacterMapper(); var entity = VolumeCharactersMockingSetup.DoMockingSetupForVolumeCharacter(); // Act var model = mapper.MapToModelLite(entity.Object); // Assert // <None> // Related Objects Assert.Equal(entity.Object.VolumeId, model.VolumeId); Assert.Equal(entity.Object.CharacterId, model.CharacterId); }
public void Verify_MapToEntity_AssignsVolumeCharacterProperties() { // Arrange var mapper = new VolumeCharacterMapper(); var model = VolumeCharactersMockingSetup.DoMockingSetupForVolumeCharacterModel(); // Act var entity = mapper.MapToEntity(model.Object); // Assert // <None> // Related Objects Assert.Equal(model.Object.VolumeId, entity.VolumeId); Assert.Equal(model.Object.CharacterId, entity.CharacterId); // Associated Objects // <None> }
public void Verify_MapToSearchModel_AssignsVolumeCharacterSearchProperties() { // Arrange var mapper = new VolumeCharacterMapper(); var model = VolumeCharactersMockingSetup.DoMockingSetupForVolumeCharacterModel(); // Act var searchModel = mapper.MapToSearchModel(model.Object); // Assert Assert.Equal(model.Object.VolumeId, searchModel.VolumeId); Assert.Equal(model.Object.Volume?.CustomKey, searchModel.VolumeCustomKey); Assert.Equal(model.Object.Volume?.ApiDetailUrl, searchModel.VolumeApiDetailUrl); Assert.Equal(model.Object.Volume?.SiteDetailUrl, searchModel.VolumeSiteDetailUrl); Assert.Equal(model.Object.Volume?.Name, searchModel.VolumeName); Assert.Equal(model.Object.Volume?.ShortDescription, searchModel.VolumeShortDescription); Assert.Equal(model.Object.Volume?.Description, searchModel.VolumeDescription); Assert.Equal(model.Object.CharacterId, searchModel.CharacterId); Assert.Equal(model.Object.Character?.CustomKey, searchModel.CharacterCustomKey); Assert.Equal(model.Object.Character?.ApiDetailUrl, searchModel.CharacterApiDetailUrl); Assert.Equal(model.Object.Character?.SiteDetailUrl, searchModel.CharacterSiteDetailUrl); Assert.Equal(model.Object.Character?.Name, searchModel.CharacterName); Assert.Equal(model.Object.Character?.ShortDescription, searchModel.CharacterShortDescription); Assert.Equal(model.Object.Character?.Description, searchModel.CharacterDescription); }
public void Verify_MapToModel_AssignsVolumeCharacterProperties() { // Arrange var mapper = new VolumeCharacterMapper(); var entity = VolumeCharactersMockingSetup.DoMockingSetupForVolumeCharacter(); // Act var model = mapper.MapToModel(entity.Object); // Assert // <None> // Related Objects Assert.Equal(entity.Object.VolumeId, model.VolumeId); Assert.Equal(entity.Object.CharacterId, model.CharacterId); // Associated Objects // <None> }
public void Verify_MapToEntity_WithExistingEntity_AssignsVolumeCharacterProperties() { // Arrange var mapper = new VolumeCharacterMapper(); var model = VolumeCharactersMockingSetup.DoMockingSetupForVolumeCharacterModel(); // Act IVolumeCharacter existingEntity = new VolumeCharacter { Id = 1 }; mapper.MapToEntity(model.Object, ref existingEntity); // Assert // <None> // Related Objects Assert.Equal(model.Object.VolumeId, existingEntity.VolumeId); Assert.Equal(model.Object.CharacterId, existingEntity.CharacterId); // Associated Objects // <None> }
public void Verify_AreEqual_WithEqualObjects_ReturnsTrue() { // Arrange var mapper = new VolumeCharacterMapper(); var model = VolumeCharactersMockingSetup.DoMockingSetupForVolumeCharacterModel(1); var entity = VolumeCharactersMockingSetup.DoMockingSetupForVolumeCharacter(1); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.True(result); }
public IVolumeCharacterModel Get(string key) { BusinessWorkflowBase.ValidateRequiredKey(key); return(VolumeCharacterMapper.MapToModel(VolumeCharactersRepository.Get(key))); }
public IVolumeCharacterModel Get(int id) { BusinessWorkflowBase.ValidateRequiredID(id); return(VolumeCharacterMapper.MapToModel(VolumeCharactersRepository.Get(id))); }