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 Mapper() { AuthorMapper = new AuthorMapper(); BookMapper = new BookMapper(); PublisherMapper = new PublisherMapper(); UserMapper = new UserMapper(); }
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_AreEqual_WithDifferentObjects_ReturnsFalse() { // Arrange var mapper = new PublisherMapper(); var model = PublishersMockingSetup.DoMockingSetupForPublisherModel(1); var entity = PublishersMockingSetup.DoMockingSetupForPublisher(2); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.False(result); }
public void Verify_MapToModelLite_AssignsLiteOnlyPublisherProperties() { // Arrange var mapper = new PublisherMapper(); var entity = PublishersMockingSetup.DoMockingSetupForPublisher(); // Act var model = mapper.MapToModelLite(entity.Object); // Assert Assert.Equal(entity.Object.LocationAddress, model.LocationAddress); Assert.Equal(entity.Object.LocationCity, model.LocationCity); Assert.Equal(entity.Object.LocationState, model.LocationState); // Related Objects Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId); }
public void Verify_MapToSearchModel_AssignsPublisherSearchProperties() { // Arrange var mapper = new PublisherMapper(); var model = PublishersMockingSetup.DoMockingSetupForPublisherModel(); // Act var searchModel = mapper.MapToSearchModel(model.Object); // Assert Assert.Equal(model.Object.PrimaryImageFileId, searchModel.PrimaryImageFileId); Assert.Equal(model.Object.PrimaryImageFile?.CustomKey, searchModel.PrimaryImageFileCustomKey); Assert.Equal(model.Object.PrimaryImageFile?.ApiDetailUrl, searchModel.PrimaryImageFileApiDetailUrl); Assert.Equal(model.Object.PrimaryImageFile?.SiteDetailUrl, searchModel.PrimaryImageFileSiteDetailUrl); Assert.Equal(model.Object.PrimaryImageFile?.Name, searchModel.PrimaryImageFileName); Assert.Equal(model.Object.PrimaryImageFile?.ShortDescription, searchModel.PrimaryImageFileShortDescription); Assert.Equal(model.Object.PrimaryImageFile?.Description, searchModel.PrimaryImageFileDescription); }
public void Verify_MapToModel_AssignsPublisherProperties() { // Arrange var mapper = new PublisherMapper(); var entity = PublishersMockingSetup.DoMockingSetupForPublisher(); // Act var model = mapper.MapToModel(entity.Object); // Assert Assert.Equal(entity.Object.LocationAddress, model.LocationAddress); Assert.Equal(entity.Object.LocationCity, model.LocationCity); Assert.Equal(entity.Object.LocationState, model.LocationState); // Related Objects Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId); // Associated Objects Assert.Equal(entity.Object.CharactersPublished?.Count, model.CharactersPublished?.Count); Assert.Equal(entity.Object.PublisherAliases?.Count, model.PublisherAliases?.Count); Assert.Equal(entity.Object.SeriesPublished?.Count, model.SeriesPublished?.Count); Assert.Equal(entity.Object.StoryArcsPublished?.Count, model.StoryArcsPublished?.Count); Assert.Equal(entity.Object.TeamsPublished?.Count, model.TeamsPublished?.Count); Assert.Equal(entity.Object.VolumesPublished?.Count, model.VolumesPublished?.Count); }
public void Verify_AreEqual_WithEqualObjects_ReturnsTrue() { // Arrange var mapper = new PublisherMapper(); var model = PublishersMockingSetup.DoMockingSetupForPublisherModel(1); var entity = PublishersMockingSetup.DoMockingSetupForPublisher(1); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.True(result); }
public IPublisherModel Get(string key) { BusinessWorkflowBase.ValidateRequiredKey(key); return(PublisherMapper.MapToModel(PublishersRepository.Get(key))); }
public IPublisherModel Get(int id) { BusinessWorkflowBase.ValidateRequiredID(id); return(PublisherMapper.MapToModel(PublishersRepository.Get(id))); }