public IObjectAppearedInIssueModel Update(IObjectAppearedInIssueModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = ObjectAppearedInIssuesRepository.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 (ObjectAppearedInIssueMapper.AreEqual(model, existingEntity)) { return(ObjectAppearedInIssueMapper.MapToModel(existingEntity)); } // Map model to an existing entity ObjectAppearedInIssueMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it ObjectAppearedInIssuesRepository.Update(ObjectAppearedInIssueMapper.MapToEntity(model)); // Try to Save Changes ObjectAppearedInIssuesRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public IObjectAppearedInIssueModel Create(IObjectAppearedInIssueModel 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(ObjectAppearedInIssueMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = ObjectAppearedInIssueMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it ObjectAppearedInIssuesRepository.Add(newEntity); // Try to Save Changes ObjectAppearedInIssuesRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public void Verify_AreEqual_WithDifferentObjects_ReturnsFalse() { // Arrange var mapper = new ObjectAppearedInIssueMapper(); var model = ObjectAppearedInIssuesMockingSetup.DoMockingSetupForObjectAppearedInIssueModel(1); var entity = ObjectAppearedInIssuesMockingSetup.DoMockingSetupForObjectAppearedInIssue(2); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.False(result); }
public void Verify_MapToModelLite_AssignsLiteOnlyObjectAppearedInIssueProperties() { // Arrange var mapper = new ObjectAppearedInIssueMapper(); var entity = ObjectAppearedInIssuesMockingSetup.DoMockingSetupForObjectAppearedInIssue(); // Act var model = mapper.MapToModelLite(entity.Object); // Assert // <None> // Related Objects Assert.Equal(entity.Object.ObjectId, model.ObjectId); Assert.Equal(entity.Object.AppearedInIssueId, model.AppearedInIssueId); }
public void Verify_MapToEntity_AssignsObjectAppearedInIssueProperties() { // Arrange var mapper = new ObjectAppearedInIssueMapper(); var model = ObjectAppearedInIssuesMockingSetup.DoMockingSetupForObjectAppearedInIssueModel(); // Act var entity = mapper.MapToEntity(model.Object); // Assert // <None> // Related Objects Assert.Equal(model.Object.ObjectId, entity.ObjectId); Assert.Equal(model.Object.AppearedInIssueId, entity.AppearedInIssueId); // Associated Objects // <None> }
public void Verify_MapToSearchModel_AssignsObjectAppearedInIssueSearchProperties() { // Arrange var mapper = new ObjectAppearedInIssueMapper(); var model = ObjectAppearedInIssuesMockingSetup.DoMockingSetupForObjectAppearedInIssueModel(); // 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.AppearedInIssueId, searchModel.AppearedInIssueId); Assert.Equal(model.Object.AppearedInIssue?.CustomKey, searchModel.AppearedInIssueCustomKey); Assert.Equal(model.Object.AppearedInIssue?.ApiDetailUrl, searchModel.AppearedInIssueApiDetailUrl); Assert.Equal(model.Object.AppearedInIssue?.SiteDetailUrl, searchModel.AppearedInIssueSiteDetailUrl); Assert.Equal(model.Object.AppearedInIssue?.Name, searchModel.AppearedInIssueName); Assert.Equal(model.Object.AppearedInIssue?.ShortDescription, searchModel.AppearedInIssueShortDescription); Assert.Equal(model.Object.AppearedInIssue?.Description, searchModel.AppearedInIssueDescription); }
public void Verify_MapToModel_AssignsObjectAppearedInIssueProperties() { // Arrange var mapper = new ObjectAppearedInIssueMapper(); var entity = ObjectAppearedInIssuesMockingSetup.DoMockingSetupForObjectAppearedInIssue(); // Act var model = mapper.MapToModel(entity.Object); // Assert // <None> // Related Objects Assert.Equal(entity.Object.ObjectId, model.ObjectId); Assert.Equal(entity.Object.AppearedInIssueId, model.AppearedInIssueId); // Associated Objects // <None> }
public void Verify_MapToEntity_WithExistingEntity_AssignsObjectAppearedInIssueProperties() { // Arrange var mapper = new ObjectAppearedInIssueMapper(); var model = ObjectAppearedInIssuesMockingSetup.DoMockingSetupForObjectAppearedInIssueModel(); // Act IObjectAppearedInIssue existingEntity = new ObjectAppearedInIssue { Id = 1 }; mapper.MapToEntity(model.Object, ref existingEntity); // Assert // <None> // Related Objects Assert.Equal(model.Object.ObjectId, existingEntity.ObjectId); Assert.Equal(model.Object.AppearedInIssueId, existingEntity.AppearedInIssueId); // Associated Objects // <None> }
public void Verify_AreEqual_WithEqualObjects_ReturnsTrue() { // Arrange var mapper = new ObjectAppearedInIssueMapper(); var model = ObjectAppearedInIssuesMockingSetup.DoMockingSetupForObjectAppearedInIssueModel(1); var entity = ObjectAppearedInIssuesMockingSetup.DoMockingSetupForObjectAppearedInIssue(1); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.True(result); }
public IObjectAppearedInIssueModel Get(string key) { BusinessWorkflowBase.ValidateRequiredKey(key); return(ObjectAppearedInIssueMapper.MapToModel(ObjectAppearedInIssuesRepository.Get(key))); }
public IObjectAppearedInIssueModel Get(int id) { BusinessWorkflowBase.ValidateRequiredID(id); return(ObjectAppearedInIssueMapper.MapToModel(ObjectAppearedInIssuesRepository.Get(id))); }