public IEpisodeTeamModel Update(IEpisodeTeamModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = EpisodeTeamsRepository.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 (EpisodeTeamMapper.AreEqual(model, existingEntity)) { return(EpisodeTeamMapper.MapToModel(existingEntity)); } // Map model to an existing entity EpisodeTeamMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it EpisodeTeamsRepository.Update(EpisodeTeamMapper.MapToEntity(model)); // Try to Save Changes EpisodeTeamsRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public IEpisodeTeamModel Create(IEpisodeTeamModel 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(EpisodeTeamMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = EpisodeTeamMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it EpisodeTeamsRepository.Add(newEntity); // Try to Save Changes EpisodeTeamsRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public void Verify_AreEqual_WithDifferentObjects_ReturnsFalse() { // Arrange var mapper = new EpisodeTeamMapper(); var model = EpisodeTeamsMockingSetup.DoMockingSetupForEpisodeTeamModel(1); var entity = EpisodeTeamsMockingSetup.DoMockingSetupForEpisodeTeam(2); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.False(result); }
public void Verify_MapToModelLite_AssignsLiteOnlyEpisodeTeamProperties() { // Arrange var mapper = new EpisodeTeamMapper(); var entity = EpisodeTeamsMockingSetup.DoMockingSetupForEpisodeTeam(); // Act var model = mapper.MapToModelLite(entity.Object); // Assert // <None> // Related Objects Assert.Equal(entity.Object.EpisodeId, model.EpisodeId); Assert.Equal(entity.Object.TeamId, model.TeamId); }
public void Verify_MapToEntity_AssignsEpisodeTeamProperties() { // Arrange var mapper = new EpisodeTeamMapper(); var model = EpisodeTeamsMockingSetup.DoMockingSetupForEpisodeTeamModel(); // Act var entity = mapper.MapToEntity(model.Object); // Assert // <None> // Related Objects Assert.Equal(model.Object.EpisodeId, entity.EpisodeId); Assert.Equal(model.Object.TeamId, entity.TeamId); // Associated Objects // <None> }
public void Verify_MapToSearchModel_AssignsEpisodeTeamSearchProperties() { // Arrange var mapper = new EpisodeTeamMapper(); var model = EpisodeTeamsMockingSetup.DoMockingSetupForEpisodeTeamModel(); // Act var searchModel = mapper.MapToSearchModel(model.Object); // Assert Assert.Equal(model.Object.EpisodeId, searchModel.EpisodeId); Assert.Equal(model.Object.Episode?.CustomKey, searchModel.EpisodeCustomKey); Assert.Equal(model.Object.Episode?.ApiDetailUrl, searchModel.EpisodeApiDetailUrl); Assert.Equal(model.Object.Episode?.SiteDetailUrl, searchModel.EpisodeSiteDetailUrl); Assert.Equal(model.Object.Episode?.Name, searchModel.EpisodeName); Assert.Equal(model.Object.Episode?.ShortDescription, searchModel.EpisodeShortDescription); Assert.Equal(model.Object.Episode?.Description, searchModel.EpisodeDescription); Assert.Equal(model.Object.TeamId, searchModel.TeamId); Assert.Equal(model.Object.Team?.CustomKey, searchModel.TeamCustomKey); Assert.Equal(model.Object.Team?.ApiDetailUrl, searchModel.TeamApiDetailUrl); Assert.Equal(model.Object.Team?.SiteDetailUrl, searchModel.TeamSiteDetailUrl); Assert.Equal(model.Object.Team?.Name, searchModel.TeamName); Assert.Equal(model.Object.Team?.ShortDescription, searchModel.TeamShortDescription); Assert.Equal(model.Object.Team?.Description, searchModel.TeamDescription); }
public IEpisodeTeamModel Get(string key) { BusinessWorkflowBase.ValidateRequiredKey(key); return(EpisodeTeamMapper.MapToModel(EpisodeTeamsRepository.Get(key))); }
public IEpisodeTeamModel Get(int id) { BusinessWorkflowBase.ValidateRequiredID(id); return(EpisodeTeamMapper.MapToModel(EpisodeTeamsRepository.Get(id))); }
public void Verify_MapToSearchModel_AssignsEpisodeTeamSearchProperties() { // Arrange var mapper = new EpisodeTeamMapper(); var model = EpisodeTeamsMockingSetup.DoMockingSetupForEpisodeTeamModel(); // Act var searchModel = mapper.MapToSearchModel(model.Object); // Assert Assert.Equal(model.Object.EpisodeId, searchModel.EpisodeId); Assert.Equal(model.Object.Episode?.CustomKey, searchModel.EpisodeCustomKey); Assert.Equal(model.Object.Episode?.ApiDetailUrl, searchModel.EpisodeApiDetailUrl); Assert.Equal(model.Object.Episode?.SiteDetailUrl, searchModel.EpisodeSiteDetailUrl); Assert.Equal(model.Object.Episode?.Name, searchModel.EpisodeName); Assert.Equal(model.Object.Episode?.ShortDescription, searchModel.EpisodeShortDescription); Assert.Equal(model.Object.Episode?.Description, searchModel.EpisodeDescription); Assert.Equal(model.Object.TeamId, searchModel.TeamId); Assert.Equal(model.Object.Team?.CustomKey, searchModel.TeamCustomKey); Assert.Equal(model.Object.Team?.ApiDetailUrl, searchModel.TeamApiDetailUrl); Assert.Equal(model.Object.Team?.SiteDetailUrl, searchModel.TeamSiteDetailUrl); Assert.Equal(model.Object.Team?.Name, searchModel.TeamName); Assert.Equal(model.Object.Team?.ShortDescription, searchModel.TeamShortDescription); Assert.Equal(model.Object.Team?.Description, searchModel.TeamDescription); }
public void Verify_MapToModel_AssignsEpisodeTeamProperties() { // Arrange var mapper = new EpisodeTeamMapper(); var entity = EpisodeTeamsMockingSetup.DoMockingSetupForEpisodeTeam(); // Act var model = mapper.MapToModel(entity.Object); // Assert // <None> // Related Objects Assert.Equal(entity.Object.EpisodeId, model.EpisodeId); Assert.Equal(entity.Object.TeamId, model.TeamId); // Associated Objects // <None> }
public void Verify_MapToEntity_WithExistingEntity_AssignsEpisodeTeamProperties() { // Arrange var mapper = new EpisodeTeamMapper(); var model = EpisodeTeamsMockingSetup.DoMockingSetupForEpisodeTeamModel(); // Act IEpisodeTeam existingEntity = new EpisodeTeam { Id = 1 }; mapper.MapToEntity(model.Object, ref existingEntity); // Assert // <None> // Related Objects Assert.Equal(model.Object.EpisodeId, existingEntity.EpisodeId); Assert.Equal(model.Object.TeamId, existingEntity.TeamId); // Associated Objects // <None> }
public void Verify_AreEqual_WithEqualObjects_ReturnsTrue() { // Arrange var mapper = new EpisodeTeamMapper(); var model = EpisodeTeamsMockingSetup.DoMockingSetupForEpisodeTeamModel(1); var entity = EpisodeTeamsMockingSetup.DoMockingSetupForEpisodeTeam(1); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.True(result); }