public IEpisodeModel Update(IEpisodeModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = EpisodesRepository.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 (EpisodeMapper.AreEqual(model, existingEntity)) { return(EpisodeMapper.MapToModel(existingEntity)); } // Map model to an existing entity EpisodeMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it EpisodesRepository.Update(EpisodeMapper.MapToEntity(model)); // Try to Save Changes EpisodesRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public void Verify_MapToModel_AssignsEpisodeProperties() { // Arrange var mapper = new EpisodeMapper(); var entity = EpisodesMockingSetup.DoMockingSetupForEpisode(); // Act var model = mapper.MapToModel(entity.Object); // Assert Assert.Equal(entity.Object.HasStaffReview, model.HasStaffReview); Assert.Equal(entity.Object.AirDate, model.AirDate); Assert.Equal(entity.Object.EpisodeCode, model.EpisodeCode); Assert.Equal(entity.Object.SeasonNumber, model.SeasonNumber); Assert.Equal(entity.Object.EpisodeNumber, model.EpisodeNumber); // Related Objects Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId); Assert.Equal(entity.Object.SeriesId, model.SeriesId); // Associated Objects Assert.Equal(entity.Object.EpisodeAliases?.Count, model.EpisodeAliases?.Count); Assert.Equal(entity.Object.EpisodeCharacters?.Count, model.EpisodeCharacters?.Count); Assert.Equal(entity.Object.EpisodeCharactersDied?.Count, model.EpisodeCharactersDied?.Count); Assert.Equal(entity.Object.EpisodeCharacterFirstAppearances?.Count, model.EpisodeCharacterFirstAppearances?.Count); Assert.Equal(entity.Object.EpisodeConcepts?.Count, model.EpisodeConcepts?.Count); Assert.Equal(entity.Object.EpisodeConceptFirstAppearances?.Count, model.EpisodeConceptFirstAppearances?.Count); Assert.Equal(entity.Object.EpisodeLocations?.Count, model.EpisodeLocations?.Count); Assert.Equal(entity.Object.EpisodeLocationFirstAppearances?.Count, model.EpisodeLocationFirstAppearances?.Count); Assert.Equal(entity.Object.EpisodeObjects?.Count, model.EpisodeObjects?.Count); Assert.Equal(entity.Object.EpisodeObjectFirstAppearances?.Count, model.EpisodeObjectFirstAppearances?.Count); Assert.Equal(entity.Object.EpisodePeople?.Count, model.EpisodePeople?.Count); Assert.Equal(entity.Object.EpisodeStoryArcs?.Count, model.EpisodeStoryArcs?.Count); Assert.Equal(entity.Object.EpisodeStoryArcFirstAppearances?.Count, model.EpisodeStoryArcFirstAppearances?.Count); Assert.Equal(entity.Object.EpisodeTeams?.Count, model.EpisodeTeams?.Count); Assert.Equal(entity.Object.EpisodeTeamFirstAppearances?.Count, model.EpisodeTeamFirstAppearances?.Count); }
public IEpisodeModel Create(IEpisodeModel 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(EpisodeMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = EpisodeMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it EpisodesRepository.Add(newEntity); // Try to Save Changes EpisodesRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public void Verify_MapToSearchModel_AssignsEpisodeSearchProperties() { // Arrange var mapper = new EpisodeMapper(); var model = EpisodesMockingSetup.DoMockingSetupForEpisodeModel(); // 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); Assert.Equal(model.Object.SeriesId, searchModel.SeriesId); Assert.Equal(model.Object.Series?.CustomKey, searchModel.SeriesCustomKey); Assert.Equal(model.Object.Series?.ApiDetailUrl, searchModel.SeriesApiDetailUrl); Assert.Equal(model.Object.Series?.SiteDetailUrl, searchModel.SeriesSiteDetailUrl); Assert.Equal(model.Object.Series?.Name, searchModel.SeriesName); Assert.Equal(model.Object.Series?.ShortDescription, searchModel.SeriesShortDescription); Assert.Equal(model.Object.Series?.Description, searchModel.SeriesDescription); Assert.Equal(model.Object.HasStaffReview, searchModel.HasStaffReview); }
public async Task MapAniDbEpisodeAsync_GroupMappingWithoutTvDbSeriesId_ReturnsNone() { var episodeMapper = new EpisodeMapper(this.defaultSeasonEpisodeMapper, this.groupMappingEpisodeMapper); var episodeData = await episodeMapper.MapAniDbEpisodeAsync(3, this.seriesMapping, new EpisodeGroupMapping(1, 1, 3, 1, 1, new List <EpisodeMapping>())) .ToOption(); episodeData.IsNone.Should().BeTrue(); }
public void Verify_AreEqual_WithDifferentObjects_ReturnsFalse() { // Arrange var mapper = new EpisodeMapper(); var model = EpisodesMockingSetup.DoMockingSetupForEpisodeModel(1); var entity = EpisodesMockingSetup.DoMockingSetupForEpisode(2); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.False(result); }
public void Verify_MapToEntity_WithExistingEntity_AssignsEpisodeProperties() { // Arrange var mapper = new EpisodeMapper(); var model = EpisodesMockingSetup.DoMockingSetupForEpisodeModel(); // Act IEpisode existingEntity = new Episode { Id = 1 }; mapper.MapToEntity(model.Object, ref existingEntity); // Assert Assert.Equal(model.Object.HasStaffReview, existingEntity.HasStaffReview); Assert.Equal(model.Object.AirDate, existingEntity.AirDate); Assert.Equal(model.Object.EpisodeCode, existingEntity.EpisodeCode); Assert.Equal(model.Object.SeasonNumber, existingEntity.SeasonNumber); Assert.Equal(model.Object.EpisodeNumber, existingEntity.EpisodeNumber); // Related Objects Assert.Equal(model.Object.PrimaryImageFileId, existingEntity.PrimaryImageFileId); Assert.Equal(model.Object.SeriesId, existingEntity.SeriesId); // Associated Objects model.VerifyGet(x => x.EpisodeAliases, Times.Once); //Assert.Equal(model.Object.EpisodeAliases?.Count, existingEntity.EpisodeAliases?.Count); model.VerifyGet(x => x.EpisodeCharacters, Times.Once); //Assert.Equal(model.Object.EpisodeCharacters?.Count, existingEntity.EpisodeCharacters?.Count); model.VerifyGet(x => x.EpisodeCharactersDied, Times.Once); //Assert.Equal(model.Object.EpisodeCharactersDied?.Count, existingEntity.EpisodeCharactersDied?.Count); model.VerifyGet(x => x.EpisodeCharacterFirstAppearances, Times.Once); //Assert.Equal(model.Object.EpisodeCharacterFirstAppearances?.Count, existingEntity.EpisodeCharacterFirstAppearances?.Count); model.VerifyGet(x => x.EpisodeConcepts, Times.Once); //Assert.Equal(model.Object.EpisodeConcepts?.Count, existingEntity.EpisodeConcepts?.Count); model.VerifyGet(x => x.EpisodeConceptFirstAppearances, Times.Once); //Assert.Equal(model.Object.EpisodeConceptFirstAppearances?.Count, existingEntity.EpisodeConceptFirstAppearances?.Count); model.VerifyGet(x => x.EpisodeLocations, Times.Once); //Assert.Equal(model.Object.EpisodeLocations?.Count, existingEntity.EpisodeLocations?.Count); model.VerifyGet(x => x.EpisodeLocationFirstAppearances, Times.Once); //Assert.Equal(model.Object.EpisodeLocationFirstAppearances?.Count, existingEntity.EpisodeLocationFirstAppearances?.Count); model.VerifyGet(x => x.EpisodeObjects, Times.Once); //Assert.Equal(model.Object.EpisodeObjects?.Count, existingEntity.EpisodeObjects?.Count); model.VerifyGet(x => x.EpisodeObjectFirstAppearances, Times.Once); //Assert.Equal(model.Object.EpisodeObjectFirstAppearances?.Count, existingEntity.EpisodeObjectFirstAppearances?.Count); model.VerifyGet(x => x.EpisodePeople, Times.Once); //Assert.Equal(model.Object.EpisodePeople?.Count, existingEntity.EpisodePeople?.Count); model.VerifyGet(x => x.EpisodeStoryArcs, Times.Once); //Assert.Equal(model.Object.EpisodeStoryArcs?.Count, existingEntity.EpisodeStoryArcs?.Count); model.VerifyGet(x => x.EpisodeStoryArcFirstAppearances, Times.Once); //Assert.Equal(model.Object.EpisodeStoryArcFirstAppearances?.Count, existingEntity.EpisodeStoryArcFirstAppearances?.Count); model.VerifyGet(x => x.EpisodeTeams, Times.Once); //Assert.Equal(model.Object.EpisodeTeams?.Count, existingEntity.EpisodeTeams?.Count); model.VerifyGet(x => x.EpisodeTeamFirstAppearances, Times.Once); //Assert.Equal(model.Object.EpisodeTeamFirstAppearances?.Count, existingEntity.EpisodeTeamFirstAppearances?.Count); }
public async Task MapAniDbEpisodeAsync_NoGroupMapping_UsesDefaultSeasonMapper() { var expected = TvDbTestData.Episode(3); this.defaultSeasonEpisodeMapper.MapEpisodeAsync(3, this.seriesMapping).Returns(expected); var episodeMapper = new EpisodeMapper(this.defaultSeasonEpisodeMapper, this.groupMappingEpisodeMapper); var episodeData = await episodeMapper .MapAniDbEpisodeAsync(3, this.seriesMapping, Option <EpisodeGroupMapping> .None) .ToOption(); episodeData.ValueUnsafe().Should().Be(expected); }
public async Task MapTvDbEpisodeAsync_UsesGroupMappingEpisodeMapper() { this.seriesMapping = new SeriesMapping(new SeriesIds(324, 523, Option <int> .None, Option <int> .None), new AbsoluteTvDbSeason(), 2, new List <EpisodeGroupMapping>(), new List <SpecialEpisodePosition>()); var episodeGroupMapping = new EpisodeGroupMapping(1, 1, 3, 1, 1, new List <EpisodeMapping>()); var expected = new AniDbEpisodeData(); this.groupMappingEpisodeMapper.MapTvDbEpisodeAsync(3, episodeGroupMapping, 324).Returns(expected); var episodeMapper = new EpisodeMapper(this.defaultSeasonEpisodeMapper, this.groupMappingEpisodeMapper); var episodeData = await episodeMapper.MapTvDbEpisodeAsync(3, this.seriesMapping, episodeGroupMapping).ToOption(); episodeData.ValueUnsafe().Should().Be(expected); }
public async Task MapAniDbEpisodeAsync_GroupMappingWithTvDbSeriesId_UsesGroupMappingEpisodeMapper() { _seriesMapping = new SeriesMapping(new SeriesIds(123, 523, Option <int> .None, Option <int> .None), new AbsoluteTvDbSeason(), 2, new List <EpisodeGroupMapping>(), new List <SpecialEpisodePosition>()); var episodeGroupMapping = new EpisodeGroupMapping(1, 1, 3, 1, 1, new List <EpisodeMapping>()); var expected = TvDbTestData.Episode(3); _groupMappingEpisodeMapper.MapAniDbEpisodeAsync(3, episodeGroupMapping, 523).Returns(expected); var episodeMapper = new EpisodeMapper(_defaultSeasonEpisodeMapper, _groupMappingEpisodeMapper); var episodeData = await episodeMapper.MapAniDbEpisodeAsync(3, _seriesMapping, episodeGroupMapping).ToOption(); episodeData.ValueUnsafe().Should().Be(expected); }
public void Verify_MapToModelLite_AssignsLiteOnlyEpisodeProperties() { // Arrange var mapper = new EpisodeMapper(); var entity = EpisodesMockingSetup.DoMockingSetupForEpisode(); // Act var model = mapper.MapToModelLite(entity.Object); // Assert Assert.Equal(entity.Object.HasStaffReview, model.HasStaffReview); Assert.Equal(entity.Object.AirDate, model.AirDate); Assert.Equal(entity.Object.EpisodeCode, model.EpisodeCode); Assert.Equal(entity.Object.SeasonNumber, model.SeasonNumber); Assert.Equal(entity.Object.EpisodeNumber, model.EpisodeNumber); // Related Objects Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId); Assert.Equal(entity.Object.SeriesId, model.SeriesId); }
public void Verify_MapToEntity_WithExistingEntity_AssignsEpisodeProperties() { // Arrange var mapper = new EpisodeMapper(); var model = EpisodesMockingSetup.DoMockingSetupForEpisodeModel(); // Act IEpisode existingEntity = new Episode { Id = 1 }; mapper.MapToEntity(model.Object, ref existingEntity); // Assert Assert.Equal(model.Object.HasStaffReview, existingEntity.HasStaffReview); Assert.Equal(model.Object.AirDate, existingEntity.AirDate); Assert.Equal(model.Object.EpisodeCode, existingEntity.EpisodeCode); Assert.Equal(model.Object.SeasonNumber, existingEntity.SeasonNumber); Assert.Equal(model.Object.EpisodeNumber, existingEntity.EpisodeNumber); // Related Objects Assert.Equal(model.Object.PrimaryImageFileId, existingEntity.PrimaryImageFileId); Assert.Equal(model.Object.SeriesId, existingEntity.SeriesId); // Associated Objects model.VerifyGet(x => x.EpisodeAliases, Times.Once); //Assert.Equal(model.Object.EpisodeAliases?.Count, existingEntity.EpisodeAliases?.Count); model.VerifyGet(x => x.EpisodeCharacters, Times.Once); //Assert.Equal(model.Object.EpisodeCharacters?.Count, existingEntity.EpisodeCharacters?.Count); model.VerifyGet(x => x.EpisodeCharactersDied, Times.Once); //Assert.Equal(model.Object.EpisodeCharactersDied?.Count, existingEntity.EpisodeCharactersDied?.Count); model.VerifyGet(x => x.EpisodeCharacterFirstAppearances, Times.Once); //Assert.Equal(model.Object.EpisodeCharacterFirstAppearances?.Count, existingEntity.EpisodeCharacterFirstAppearances?.Count); model.VerifyGet(x => x.EpisodeConcepts, Times.Once); //Assert.Equal(model.Object.EpisodeConcepts?.Count, existingEntity.EpisodeConcepts?.Count); model.VerifyGet(x => x.EpisodeConceptFirstAppearances, Times.Once); //Assert.Equal(model.Object.EpisodeConceptFirstAppearances?.Count, existingEntity.EpisodeConceptFirstAppearances?.Count); model.VerifyGet(x => x.EpisodeLocations, Times.Once); //Assert.Equal(model.Object.EpisodeLocations?.Count, existingEntity.EpisodeLocations?.Count); model.VerifyGet(x => x.EpisodeLocationFirstAppearances, Times.Once); //Assert.Equal(model.Object.EpisodeLocationFirstAppearances?.Count, existingEntity.EpisodeLocationFirstAppearances?.Count); model.VerifyGet(x => x.EpisodeObjects, Times.Once); //Assert.Equal(model.Object.EpisodeObjects?.Count, existingEntity.EpisodeObjects?.Count); model.VerifyGet(x => x.EpisodeObjectFirstAppearances, Times.Once); //Assert.Equal(model.Object.EpisodeObjectFirstAppearances?.Count, existingEntity.EpisodeObjectFirstAppearances?.Count); model.VerifyGet(x => x.EpisodePeople, Times.Once); //Assert.Equal(model.Object.EpisodePeople?.Count, existingEntity.EpisodePeople?.Count); model.VerifyGet(x => x.EpisodeStoryArcs, Times.Once); //Assert.Equal(model.Object.EpisodeStoryArcs?.Count, existingEntity.EpisodeStoryArcs?.Count); model.VerifyGet(x => x.EpisodeStoryArcFirstAppearances, Times.Once); //Assert.Equal(model.Object.EpisodeStoryArcFirstAppearances?.Count, existingEntity.EpisodeStoryArcFirstAppearances?.Count); model.VerifyGet(x => x.EpisodeTeams, Times.Once); //Assert.Equal(model.Object.EpisodeTeams?.Count, existingEntity.EpisodeTeams?.Count); model.VerifyGet(x => x.EpisodeTeamFirstAppearances, Times.Once); //Assert.Equal(model.Object.EpisodeTeamFirstAppearances?.Count, existingEntity.EpisodeTeamFirstAppearances?.Count); }
public IEpisodeModel Get(int id) { BusinessWorkflowBase.ValidateRequiredID(id); return(EpisodeMapper.MapToModel(EpisodesRepository.Get(id))); }
public IEpisodeModel Get(string key) { BusinessWorkflowBase.ValidateRequiredKey(key); return(EpisodeMapper.MapToModel(EpisodesRepository.Get(key))); }
public void Verify_AreEqual_WithEqualObjects_ReturnsTrue() { // Arrange var mapper = new EpisodeMapper(); var model = EpisodesMockingSetup.DoMockingSetupForEpisodeModel(1); var entity = EpisodesMockingSetup.DoMockingSetupForEpisode(1); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.True(result); }
public void Verify_MapToSearchModel_AssignsEpisodeSearchProperties() { // Arrange var mapper = new EpisodeMapper(); var model = EpisodesMockingSetup.DoMockingSetupForEpisodeModel(); // 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); Assert.Equal(model.Object.SeriesId, searchModel.SeriesId); Assert.Equal(model.Object.Series?.CustomKey, searchModel.SeriesCustomKey); Assert.Equal(model.Object.Series?.ApiDetailUrl, searchModel.SeriesApiDetailUrl); Assert.Equal(model.Object.Series?.SiteDetailUrl, searchModel.SeriesSiteDetailUrl); Assert.Equal(model.Object.Series?.Name, searchModel.SeriesName); Assert.Equal(model.Object.Series?.ShortDescription, searchModel.SeriesShortDescription); Assert.Equal(model.Object.Series?.Description, searchModel.SeriesDescription); Assert.Equal(model.Object.HasStaffReview, searchModel.HasStaffReview); }
public void Verify_MapToModel_AssignsEpisodeProperties() { // Arrange var mapper = new EpisodeMapper(); var entity = EpisodesMockingSetup.DoMockingSetupForEpisode(); // Act var model = mapper.MapToModel(entity.Object); // Assert Assert.Equal(entity.Object.HasStaffReview, model.HasStaffReview); Assert.Equal(entity.Object.AirDate, model.AirDate); Assert.Equal(entity.Object.EpisodeCode, model.EpisodeCode); Assert.Equal(entity.Object.SeasonNumber, model.SeasonNumber); Assert.Equal(entity.Object.EpisodeNumber, model.EpisodeNumber); // Related Objects Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId); Assert.Equal(entity.Object.SeriesId, model.SeriesId); // Associated Objects Assert.Equal(entity.Object.EpisodeAliases?.Count, model.EpisodeAliases?.Count); Assert.Equal(entity.Object.EpisodeCharacters?.Count, model.EpisodeCharacters?.Count); Assert.Equal(entity.Object.EpisodeCharactersDied?.Count, model.EpisodeCharactersDied?.Count); Assert.Equal(entity.Object.EpisodeCharacterFirstAppearances?.Count, model.EpisodeCharacterFirstAppearances?.Count); Assert.Equal(entity.Object.EpisodeConcepts?.Count, model.EpisodeConcepts?.Count); Assert.Equal(entity.Object.EpisodeConceptFirstAppearances?.Count, model.EpisodeConceptFirstAppearances?.Count); Assert.Equal(entity.Object.EpisodeLocations?.Count, model.EpisodeLocations?.Count); Assert.Equal(entity.Object.EpisodeLocationFirstAppearances?.Count, model.EpisodeLocationFirstAppearances?.Count); Assert.Equal(entity.Object.EpisodeObjects?.Count, model.EpisodeObjects?.Count); Assert.Equal(entity.Object.EpisodeObjectFirstAppearances?.Count, model.EpisodeObjectFirstAppearances?.Count); Assert.Equal(entity.Object.EpisodePeople?.Count, model.EpisodePeople?.Count); Assert.Equal(entity.Object.EpisodeStoryArcs?.Count, model.EpisodeStoryArcs?.Count); Assert.Equal(entity.Object.EpisodeStoryArcFirstAppearances?.Count, model.EpisodeStoryArcFirstAppearances?.Count); Assert.Equal(entity.Object.EpisodeTeams?.Count, model.EpisodeTeams?.Count); Assert.Equal(entity.Object.EpisodeTeamFirstAppearances?.Count, model.EpisodeTeamFirstAppearances?.Count); }
public void Verify_MapToModelLite_AssignsLiteOnlyEpisodeProperties() { // Arrange var mapper = new EpisodeMapper(); var entity = EpisodesMockingSetup.DoMockingSetupForEpisode(); // Act var model = mapper.MapToModelLite(entity.Object); // Assert Assert.Equal(entity.Object.HasStaffReview, model.HasStaffReview); Assert.Equal(entity.Object.AirDate, model.AirDate); Assert.Equal(entity.Object.EpisodeCode, model.EpisodeCode); Assert.Equal(entity.Object.SeasonNumber, model.SeasonNumber); Assert.Equal(entity.Object.EpisodeNumber, model.EpisodeNumber); // Related Objects Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId); Assert.Equal(entity.Object.SeriesId, model.SeriesId); }