public void Verify_MapToEntity_WithExistingEntity_AssignsPublisherProperties() { // Arrange var mapper = new PublisherMapper(); var model = PublishersMockingSetup.DoMockingSetupForPublisherModel(); // Act IPublisher existingEntity = new Publisher { Id = 1 }; mapper.MapToEntity(model.Object, ref existingEntity); // Assert Assert.Equal(model.Object.LocationAddress, existingEntity.LocationAddress); Assert.Equal(model.Object.LocationCity, existingEntity.LocationCity); Assert.Equal(model.Object.LocationState, existingEntity.LocationState); // Related Objects Assert.Equal(model.Object.PrimaryImageFileId, existingEntity.PrimaryImageFileId); // Associated Objects model.VerifyGet(x => x.CharactersPublished, Times.Once); //Assert.Equal(model.Object.CharactersPublished?.Count, existingEntity.CharactersPublished?.Count); model.VerifyGet(x => x.PublisherAliases, Times.Once); //Assert.Equal(model.Object.PublisherAliases?.Count, existingEntity.PublisherAliases?.Count); model.VerifyGet(x => x.SeriesPublished, Times.Once); //Assert.Equal(model.Object.SeriesPublished?.Count, existingEntity.SeriesPublished?.Count); model.VerifyGet(x => x.StoryArcsPublished, Times.Once); //Assert.Equal(model.Object.StoryArcsPublished?.Count, existingEntity.StoryArcsPublished?.Count); model.VerifyGet(x => x.TeamsPublished, Times.Once); //Assert.Equal(model.Object.TeamsPublished?.Count, existingEntity.TeamsPublished?.Count); model.VerifyGet(x => x.VolumesPublished, Times.Once); //Assert.Equal(model.Object.VolumesPublished?.Count, existingEntity.VolumesPublished?.Count); }
public IPublisherModel Update(IPublisherModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = PublishersRepository.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 (PublisherMapper.AreEqual(model, existingEntity)) { return(PublisherMapper.MapToModel(existingEntity)); } // Map model to an existing entity PublisherMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it PublishersRepository.Update(PublisherMapper.MapToEntity(model)); // Try to Save Changes PublishersRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public IPublisherModel Create(IPublisherModel 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(PublisherMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = PublisherMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it PublishersRepository.Add(newEntity); // Try to Save Changes PublishersRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public void Verify_MapToEntity_WithExistingEntity_AssignsPublisherProperties() { // Arrange var mapper = new PublisherMapper(); var model = PublishersMockingSetup.DoMockingSetupForPublisherModel(); // Act IPublisher existingEntity = new Publisher { Id = 1 }; mapper.MapToEntity(model.Object, ref existingEntity); // Assert Assert.Equal(model.Object.LocationAddress, existingEntity.LocationAddress); Assert.Equal(model.Object.LocationCity, existingEntity.LocationCity); Assert.Equal(model.Object.LocationState, existingEntity.LocationState); // Related Objects Assert.Equal(model.Object.PrimaryImageFileId, existingEntity.PrimaryImageFileId); // Associated Objects model.VerifyGet(x => x.CharactersPublished, Times.Once); //Assert.Equal(model.Object.CharactersPublished?.Count, existingEntity.CharactersPublished?.Count); model.VerifyGet(x => x.PublisherAliases, Times.Once); //Assert.Equal(model.Object.PublisherAliases?.Count, existingEntity.PublisherAliases?.Count); model.VerifyGet(x => x.SeriesPublished, Times.Once); //Assert.Equal(model.Object.SeriesPublished?.Count, existingEntity.SeriesPublished?.Count); model.VerifyGet(x => x.StoryArcsPublished, Times.Once); //Assert.Equal(model.Object.StoryArcsPublished?.Count, existingEntity.StoryArcsPublished?.Count); model.VerifyGet(x => x.TeamsPublished, Times.Once); //Assert.Equal(model.Object.TeamsPublished?.Count, existingEntity.TeamsPublished?.Count); model.VerifyGet(x => x.VolumesPublished, Times.Once); //Assert.Equal(model.Object.VolumesPublished?.Count, existingEntity.VolumesPublished?.Count); }