public IObjectStoryArcModel Create(IObjectStoryArcModel 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(ObjectStoryArcMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = ObjectStoryArcMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it ObjectStoryArcsRepository.Add(newEntity); // Try to Save Changes ObjectStoryArcsRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public void Verify_MapToSearchModel_AssignsObjectStoryArcSearchProperties() { // Arrange var mapper = new ObjectStoryArcMapper(); var model = ObjectStoryArcsMockingSetup.DoMockingSetupForObjectStoryArcModel(); // Act var searchModel = mapper.MapToSearchModel(model.Object); // Assert 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); Assert.Equal(model.Object.StoryArcId, searchModel.StoryArcId); Assert.Equal(model.Object.StoryArc?.CustomKey, searchModel.StoryArcCustomKey); Assert.Equal(model.Object.StoryArc?.ApiDetailUrl, searchModel.StoryArcApiDetailUrl); Assert.Equal(model.Object.StoryArc?.SiteDetailUrl, searchModel.StoryArcSiteDetailUrl); Assert.Equal(model.Object.StoryArc?.Name, searchModel.StoryArcName); Assert.Equal(model.Object.StoryArc?.ShortDescription, searchModel.StoryArcShortDescription); Assert.Equal(model.Object.StoryArc?.Description, searchModel.StoryArcDescription); }