public void Verify_MapToModel_AssignsPersonProperties() { // Arrange var mapper = new PersonMapper(); var entity = PeopleMockingSetup.DoMockingSetupForPerson(); // Act var model = mapper.MapToModel(entity.Object); // Assert Assert.Equal(entity.Object.Hometown, model.Hometown); Assert.Equal(entity.Object.Country, model.Country); Assert.Equal(entity.Object.Email, model.Email); Assert.Equal(entity.Object.Website, model.Website); Assert.Equal(entity.Object.BirthDate, model.BirthDate); Assert.Equal(entity.Object.DeathDate, model.DeathDate); // Related Objects Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId); Assert.Equal(entity.Object.GenderId, model.GenderId); // Associated Objects Assert.Equal(entity.Object.CharactersCreated?.Count, model.CharactersCreated?.Count); Assert.Equal(entity.Object.PersonAliases?.Count, model.PersonAliases?.Count); Assert.Equal(entity.Object.IssuesWritten?.Count, model.IssuesWritten?.Count); Assert.Equal(entity.Object.MoviesProduced?.Count, model.MoviesProduced?.Count); Assert.Equal(entity.Object.MoviesWritten?.Count, model.MoviesWritten?.Count); Assert.Equal(entity.Object.PromosWritten?.Count, model.PromosWritten?.Count); Assert.Equal(entity.Object.StoryArcsWritten?.Count, model.StoryArcsWritten?.Count); Assert.Equal(entity.Object.VolumesWritten?.Count, model.VolumesWritten?.Count); }
public IPersonModel Update(IPersonModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = PeopleRepository.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 (PersonMapper.AreEqual(model, existingEntity)) { return(PersonMapper.MapToModel(existingEntity)); } // Map model to an existing entity PersonMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it PeopleRepository.Update(PersonMapper.MapToEntity(model)); // Try to Save Changes PeopleRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public IPersonModel Get(int id) { BusinessWorkflowBase.ValidateRequiredID(id); return(PersonMapper.MapToModel(PeopleRepository.Get(id))); }
public IPersonModel Get(string key) { BusinessWorkflowBase.ValidateRequiredKey(key); return(PersonMapper.MapToModel(PeopleRepository.Get(key))); }