public IVolumeModel Create(IVolumeModel 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(VolumeMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = VolumeMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it VolumesRepository.Add(newEntity); // Try to Save Changes VolumesRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public void Verify_MapToSearchModel_AssignsVolumeSearchProperties() { // Arrange var mapper = new VolumeMapper(); var model = VolumesMockingSetup.DoMockingSetupForVolumeModel(); // 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.FirstIssueId, searchModel.FirstIssueId); Assert.Equal(model.Object.FirstIssue?.CustomKey, searchModel.FirstIssueCustomKey); Assert.Equal(model.Object.FirstIssue?.ApiDetailUrl, searchModel.FirstIssueApiDetailUrl); Assert.Equal(model.Object.FirstIssue?.SiteDetailUrl, searchModel.FirstIssueSiteDetailUrl); Assert.Equal(model.Object.FirstIssue?.Name, searchModel.FirstIssueName); Assert.Equal(model.Object.FirstIssue?.ShortDescription, searchModel.FirstIssueShortDescription); Assert.Equal(model.Object.FirstIssue?.Description, searchModel.FirstIssueDescription); Assert.Equal(model.Object.LastIssueId, searchModel.LastIssueId); Assert.Equal(model.Object.LastIssue?.CustomKey, searchModel.LastIssueCustomKey); Assert.Equal(model.Object.LastIssue?.ApiDetailUrl, searchModel.LastIssueApiDetailUrl); Assert.Equal(model.Object.LastIssue?.SiteDetailUrl, searchModel.LastIssueSiteDetailUrl); Assert.Equal(model.Object.LastIssue?.Name, searchModel.LastIssueName); Assert.Equal(model.Object.LastIssue?.ShortDescription, searchModel.LastIssueShortDescription); Assert.Equal(model.Object.LastIssue?.Description, searchModel.LastIssueDescription); Assert.Equal(model.Object.PublisherId, searchModel.PublisherId); Assert.Equal(model.Object.Publisher?.CustomKey, searchModel.PublisherCustomKey); Assert.Equal(model.Object.Publisher?.ApiDetailUrl, searchModel.PublisherApiDetailUrl); Assert.Equal(model.Object.Publisher?.SiteDetailUrl, searchModel.PublisherSiteDetailUrl); Assert.Equal(model.Object.Publisher?.Name, searchModel.PublisherName); Assert.Equal(model.Object.Publisher?.ShortDescription, searchModel.PublisherShortDescription); Assert.Equal(model.Object.Publisher?.Description, searchModel.PublisherDescription); }