public ICharacterDiedInIssueModel Update(ICharacterDiedInIssueModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = CharacterDiedInIssuesRepository.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 (CharacterDiedInIssueMapper.AreEqual(model, existingEntity)) { return(CharacterDiedInIssueMapper.MapToModel(existingEntity)); } // Map model to an existing entity CharacterDiedInIssueMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it CharacterDiedInIssuesRepository.Update(CharacterDiedInIssueMapper.MapToEntity(model)); // Try to Save Changes CharacterDiedInIssuesRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public ICharacterDiedInIssueModel Create(ICharacterDiedInIssueModel 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(CharacterDiedInIssueMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = CharacterDiedInIssueMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it CharacterDiedInIssuesRepository.Add(newEntity); // Try to Save Changes CharacterDiedInIssuesRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public void Verify_AreEqual_WithDifferentObjects_ReturnsFalse() { // Arrange var mapper = new CharacterDiedInIssueMapper(); var model = CharacterDiedInIssuesMockingSetup.DoMockingSetupForCharacterDiedInIssueModel(1); var entity = CharacterDiedInIssuesMockingSetup.DoMockingSetupForCharacterDiedInIssue(2); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.False(result); }
public void Verify_MapToModelLite_AssignsLiteOnlyCharacterDiedInIssueProperties() { // Arrange var mapper = new CharacterDiedInIssueMapper(); var entity = CharacterDiedInIssuesMockingSetup.DoMockingSetupForCharacterDiedInIssue(); // Act var model = mapper.MapToModelLite(entity.Object); // Assert // <None> // Related Objects Assert.Equal(entity.Object.CharacterId, model.CharacterId); Assert.Equal(entity.Object.DiedInIssueId, model.DiedInIssueId); }
public void Verify_MapToEntity_AssignsCharacterDiedInIssueProperties() { // Arrange var mapper = new CharacterDiedInIssueMapper(); var model = CharacterDiedInIssuesMockingSetup.DoMockingSetupForCharacterDiedInIssueModel(); // Act var entity = mapper.MapToEntity(model.Object); // Assert // <None> // Related Objects Assert.Equal(model.Object.CharacterId, entity.CharacterId); Assert.Equal(model.Object.DiedInIssueId, entity.DiedInIssueId); // Associated Objects // <None> }
public void Verify_MapToSearchModel_AssignsCharacterDiedInIssueSearchProperties() { // Arrange var mapper = new CharacterDiedInIssueMapper(); var model = CharacterDiedInIssuesMockingSetup.DoMockingSetupForCharacterDiedInIssueModel(); // Act var searchModel = mapper.MapToSearchModel(model.Object); // Assert 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); Assert.Equal(model.Object.DiedInIssueId, searchModel.DiedInIssueId); Assert.Equal(model.Object.DiedInIssue?.CustomKey, searchModel.DiedInIssueCustomKey); Assert.Equal(model.Object.DiedInIssue?.ApiDetailUrl, searchModel.DiedInIssueApiDetailUrl); Assert.Equal(model.Object.DiedInIssue?.SiteDetailUrl, searchModel.DiedInIssueSiteDetailUrl); Assert.Equal(model.Object.DiedInIssue?.Name, searchModel.DiedInIssueName); Assert.Equal(model.Object.DiedInIssue?.ShortDescription, searchModel.DiedInIssueShortDescription); Assert.Equal(model.Object.DiedInIssue?.Description, searchModel.DiedInIssueDescription); }
public void Verify_MapToModel_AssignsCharacterDiedInIssueProperties() { // Arrange var mapper = new CharacterDiedInIssueMapper(); var entity = CharacterDiedInIssuesMockingSetup.DoMockingSetupForCharacterDiedInIssue(); // Act var model = mapper.MapToModel(entity.Object); // Assert // <None> // Related Objects Assert.Equal(entity.Object.CharacterId, model.CharacterId); Assert.Equal(entity.Object.DiedInIssueId, model.DiedInIssueId); // Associated Objects // <None> }
public void Verify_MapToEntity_WithExistingEntity_AssignsCharacterDiedInIssueProperties() { // Arrange var mapper = new CharacterDiedInIssueMapper(); var model = CharacterDiedInIssuesMockingSetup.DoMockingSetupForCharacterDiedInIssueModel(); // Act ICharacterDiedInIssue existingEntity = new CharacterDiedInIssue { Id = 1 }; mapper.MapToEntity(model.Object, ref existingEntity); // Assert // <None> // Related Objects Assert.Equal(model.Object.CharacterId, existingEntity.CharacterId); Assert.Equal(model.Object.DiedInIssueId, existingEntity.DiedInIssueId); // Associated Objects // <None> }
public void Verify_AreEqual_WithEqualObjects_ReturnsTrue() { // Arrange var mapper = new CharacterDiedInIssueMapper(); var model = CharacterDiedInIssuesMockingSetup.DoMockingSetupForCharacterDiedInIssueModel(1); var entity = CharacterDiedInIssuesMockingSetup.DoMockingSetupForCharacterDiedInIssue(1); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.True(result); }
public ICharacterDiedInIssueModel Get(string key) { BusinessWorkflowBase.ValidateRequiredKey(key); return(CharacterDiedInIssueMapper.MapToModel(CharacterDiedInIssuesRepository.Get(key))); }
public ICharacterDiedInIssueModel Get(int id) { BusinessWorkflowBase.ValidateRequiredID(id); return(CharacterDiedInIssueMapper.MapToModel(CharacterDiedInIssuesRepository.Get(id))); }