public IObjectStoryArcModel Update(IObjectStoryArcModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = ObjectStoryArcsRepository.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 (ObjectStoryArcMapper.AreEqual(model, existingEntity)) { return(ObjectStoryArcMapper.MapToModel(existingEntity)); } // Map model to an existing entity ObjectStoryArcMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it ObjectStoryArcsRepository.Update(ObjectStoryArcMapper.MapToEntity(model)); // Try to Save Changes ObjectStoryArcsRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
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_AreEqual_WithDifferentObjects_ReturnsFalse() { // Arrange var mapper = new ObjectStoryArcMapper(); var model = ObjectStoryArcsMockingSetup.DoMockingSetupForObjectStoryArcModel(1); var entity = ObjectStoryArcsMockingSetup.DoMockingSetupForObjectStoryArc(2); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.False(result); }
public void Verify_MapToModelLite_AssignsLiteOnlyObjectStoryArcProperties() { // Arrange var mapper = new ObjectStoryArcMapper(); var entity = ObjectStoryArcsMockingSetup.DoMockingSetupForObjectStoryArc(); // Act var model = mapper.MapToModelLite(entity.Object); // Assert // <None> // Related Objects Assert.Equal(entity.Object.ObjectId, model.ObjectId); Assert.Equal(entity.Object.StoryArcId, model.StoryArcId); }
public void Verify_MapToEntity_AssignsObjectStoryArcProperties() { // Arrange var mapper = new ObjectStoryArcMapper(); var model = ObjectStoryArcsMockingSetup.DoMockingSetupForObjectStoryArcModel(); // Act var entity = mapper.MapToEntity(model.Object); // Assert // <None> // Related Objects Assert.Equal(model.Object.ObjectId, entity.ObjectId); Assert.Equal(model.Object.StoryArcId, entity.StoryArcId); // Associated Objects // <None> }
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); }
public void Verify_MapToModel_AssignsObjectStoryArcProperties() { // Arrange var mapper = new ObjectStoryArcMapper(); var entity = ObjectStoryArcsMockingSetup.DoMockingSetupForObjectStoryArc(); // Act var model = mapper.MapToModel(entity.Object); // Assert // <None> // Related Objects Assert.Equal(entity.Object.ObjectId, model.ObjectId); Assert.Equal(entity.Object.StoryArcId, model.StoryArcId); // Associated Objects // <None> }
public void Verify_MapToEntity_WithExistingEntity_AssignsObjectStoryArcProperties() { // Arrange var mapper = new ObjectStoryArcMapper(); var model = ObjectStoryArcsMockingSetup.DoMockingSetupForObjectStoryArcModel(); // Act IObjectStoryArc existingEntity = new ObjectStoryArc { Id = 1 }; mapper.MapToEntity(model.Object, ref existingEntity); // Assert // <None> // Related Objects Assert.Equal(model.Object.ObjectId, existingEntity.ObjectId); Assert.Equal(model.Object.StoryArcId, existingEntity.StoryArcId); // Associated Objects // <None> }
public void Verify_AreEqual_WithEqualObjects_ReturnsTrue() { // Arrange var mapper = new ObjectStoryArcMapper(); var model = ObjectStoryArcsMockingSetup.DoMockingSetupForObjectStoryArcModel(1); var entity = ObjectStoryArcsMockingSetup.DoMockingSetupForObjectStoryArc(1); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.True(result); }
public IObjectStoryArcModel Get(string key) { BusinessWorkflowBase.ValidateRequiredKey(key); return(ObjectStoryArcMapper.MapToModel(ObjectStoryArcsRepository.Get(key))); }
public IObjectStoryArcModel Get(int id) { BusinessWorkflowBase.ValidateRequiredID(id); return(ObjectStoryArcMapper.MapToModel(ObjectStoryArcsRepository.Get(id))); }