public IEpisodeObjectModel Create(IEpisodeObjectModel 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(EpisodeObjectMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = EpisodeObjectMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it EpisodeObjectsRepository.Add(newEntity); // Try to Save Changes EpisodeObjectsRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public void Verify_MapToSearchModel_AssignsEpisodeObjectSearchProperties() { // Arrange var mapper = new EpisodeObjectMapper(); var model = EpisodeObjectsMockingSetup.DoMockingSetupForEpisodeObjectModel(); // 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.ObjectId, searchModel.ObjectId); Assert.Equal(model.Object.Object?.CustomKey, searchModel.ObjectCustomKey); Assert.Equal(model.Object.Object?.ApiDetailUrl, searchModel.ObjectApiDetailUrl); Assert.Equal(model.Object.Object?.SiteDetailUrl, searchModel.ObjectSiteDetailUrl); Assert.Equal(model.Object.Object?.Name, searchModel.ObjectName); Assert.Equal(model.Object.Object?.ShortDescription, searchModel.ObjectShortDescription); Assert.Equal(model.Object.Object?.Description, searchModel.ObjectDescription); }