public IConceptVolumeModel Update(IConceptVolumeModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = ConceptVolumesRepository.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 (ConceptVolumeMapper.AreEqual(model, existingEntity)) { return(ConceptVolumeMapper.MapToModel(existingEntity)); } // Map model to an existing entity ConceptVolumeMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it ConceptVolumesRepository.Update(ConceptVolumeMapper.MapToEntity(model)); // Try to Save Changes ConceptVolumesRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public IConceptVolumeModel Create(IConceptVolumeModel 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(ConceptVolumeMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = ConceptVolumeMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it ConceptVolumesRepository.Add(newEntity); // Try to Save Changes ConceptVolumesRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public void Verify_AreEqual_WithDifferentObjects_ReturnsFalse() { // Arrange var mapper = new ConceptVolumeMapper(); var model = ConceptVolumesMockingSetup.DoMockingSetupForConceptVolumeModel(1); var entity = ConceptVolumesMockingSetup.DoMockingSetupForConceptVolume(2); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.False(result); }
public void Verify_MapToModelLite_AssignsLiteOnlyConceptVolumeProperties() { // Arrange var mapper = new ConceptVolumeMapper(); var entity = ConceptVolumesMockingSetup.DoMockingSetupForConceptVolume(); // Act var model = mapper.MapToModelLite(entity.Object); // Assert // <None> // Related Objects Assert.Equal(entity.Object.ConceptId, model.ConceptId); Assert.Equal(entity.Object.VolumeId, model.VolumeId); }
public void Verify_MapToEntity_AssignsConceptVolumeProperties() { // Arrange var mapper = new ConceptVolumeMapper(); var model = ConceptVolumesMockingSetup.DoMockingSetupForConceptVolumeModel(); // Act var entity = mapper.MapToEntity(model.Object); // Assert // <None> // Related Objects Assert.Equal(model.Object.ConceptId, entity.ConceptId); Assert.Equal(model.Object.VolumeId, entity.VolumeId); // Associated Objects // <None> }
public void Verify_MapToSearchModel_AssignsConceptVolumeSearchProperties() { // Arrange var mapper = new ConceptVolumeMapper(); var model = ConceptVolumesMockingSetup.DoMockingSetupForConceptVolumeModel(); // Act var searchModel = mapper.MapToSearchModel(model.Object); // Assert Assert.Equal(model.Object.ConceptId, searchModel.ConceptId); Assert.Equal(model.Object.Concept?.CustomKey, searchModel.ConceptCustomKey); Assert.Equal(model.Object.Concept?.ApiDetailUrl, searchModel.ConceptApiDetailUrl); Assert.Equal(model.Object.Concept?.SiteDetailUrl, searchModel.ConceptSiteDetailUrl); Assert.Equal(model.Object.Concept?.Name, searchModel.ConceptName); Assert.Equal(model.Object.Concept?.ShortDescription, searchModel.ConceptShortDescription); Assert.Equal(model.Object.Concept?.Description, searchModel.ConceptDescription); Assert.Equal(model.Object.VolumeId, searchModel.VolumeId); Assert.Equal(model.Object.Volume?.CustomKey, searchModel.VolumeCustomKey); Assert.Equal(model.Object.Volume?.ApiDetailUrl, searchModel.VolumeApiDetailUrl); Assert.Equal(model.Object.Volume?.SiteDetailUrl, searchModel.VolumeSiteDetailUrl); Assert.Equal(model.Object.Volume?.Name, searchModel.VolumeName); Assert.Equal(model.Object.Volume?.ShortDescription, searchModel.VolumeShortDescription); Assert.Equal(model.Object.Volume?.Description, searchModel.VolumeDescription); }
public IConceptVolumeModel Get(string key) { BusinessWorkflowBase.ValidateRequiredKey(key); return(ConceptVolumeMapper.MapToModel(ConceptVolumesRepository.Get(key))); }
public IConceptVolumeModel Get(int id) { BusinessWorkflowBase.ValidateRequiredID(id); return(ConceptVolumeMapper.MapToModel(ConceptVolumesRepository.Get(id))); }
public void Verify_MapToModel_AssignsConceptVolumeProperties() { // Arrange var mapper = new ConceptVolumeMapper(); var entity = ConceptVolumesMockingSetup.DoMockingSetupForConceptVolume(); // Act var model = mapper.MapToModel(entity.Object); // Assert // <None> // Related Objects Assert.Equal(entity.Object.ConceptId, model.ConceptId); Assert.Equal(entity.Object.VolumeId, model.VolumeId); // Associated Objects // <None> }
public void Verify_MapToEntity_WithExistingEntity_AssignsConceptVolumeProperties() { // Arrange var mapper = new ConceptVolumeMapper(); var model = ConceptVolumesMockingSetup.DoMockingSetupForConceptVolumeModel(); // Act IConceptVolume existingEntity = new ConceptVolume { Id = 1 }; mapper.MapToEntity(model.Object, ref existingEntity); // Assert // <None> // Related Objects Assert.Equal(model.Object.ConceptId, existingEntity.ConceptId); Assert.Equal(model.Object.VolumeId, existingEntity.VolumeId); // Associated Objects // <None> }
public void Verify_AreEqual_WithEqualObjects_ReturnsTrue() { // Arrange var mapper = new ConceptVolumeMapper(); var model = ConceptVolumesMockingSetup.DoMockingSetupForConceptVolumeModel(1); var entity = ConceptVolumesMockingSetup.DoMockingSetupForConceptVolume(1); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.True(result); }