public ISeriesLocationModel Update(ISeriesLocationModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = SeriesLocationsRepository.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 (SeriesLocationMapper.AreEqual(model, existingEntity)) { return(SeriesLocationMapper.MapToModel(existingEntity)); } // Map model to an existing entity SeriesLocationMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it SeriesLocationsRepository.Update(SeriesLocationMapper.MapToEntity(model)); // Try to Save Changes SeriesLocationsRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public ISeriesLocationModel Create(ISeriesLocationModel 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(SeriesLocationMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = SeriesLocationMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it SeriesLocationsRepository.Add(newEntity); // Try to Save Changes SeriesLocationsRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public void Verify_AreEqual_WithDifferentObjects_ReturnsFalse() { // Arrange var mapper = new SeriesLocationMapper(); var model = SeriesLocationsMockingSetup.DoMockingSetupForSeriesLocationModel(1); var entity = SeriesLocationsMockingSetup.DoMockingSetupForSeriesLocation(2); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.False(result); }
public void Verify_MapToModelLite_AssignsLiteOnlySeriesLocationProperties() { // Arrange var mapper = new SeriesLocationMapper(); var entity = SeriesLocationsMockingSetup.DoMockingSetupForSeriesLocation(); // Act var model = mapper.MapToModelLite(entity.Object); // Assert // <None> // Related Objects Assert.Equal(entity.Object.SeriesId, model.SeriesId); Assert.Equal(entity.Object.LocationId, model.LocationId); }
public void Verify_MapToEntity_AssignsSeriesLocationProperties() { // Arrange var mapper = new SeriesLocationMapper(); var model = SeriesLocationsMockingSetup.DoMockingSetupForSeriesLocationModel(); // Act var entity = mapper.MapToEntity(model.Object); // Assert // <None> // Related Objects Assert.Equal(model.Object.SeriesId, entity.SeriesId); Assert.Equal(model.Object.LocationId, entity.LocationId); // Associated Objects // <None> }
public void Verify_MapToSearchModel_AssignsSeriesLocationSearchProperties() { // Arrange var mapper = new SeriesLocationMapper(); var model = SeriesLocationsMockingSetup.DoMockingSetupForSeriesLocationModel(); // Act var searchModel = mapper.MapToSearchModel(model.Object); // Assert Assert.Equal(model.Object.SeriesId, searchModel.SeriesId); Assert.Equal(model.Object.Series?.CustomKey, searchModel.SeriesCustomKey); Assert.Equal(model.Object.Series?.ApiDetailUrl, searchModel.SeriesApiDetailUrl); Assert.Equal(model.Object.Series?.SiteDetailUrl, searchModel.SeriesSiteDetailUrl); Assert.Equal(model.Object.Series?.Name, searchModel.SeriesName); Assert.Equal(model.Object.Series?.ShortDescription, searchModel.SeriesShortDescription); Assert.Equal(model.Object.Series?.Description, searchModel.SeriesDescription); Assert.Equal(model.Object.LocationId, searchModel.LocationId); Assert.Equal(model.Object.Location?.CustomKey, searchModel.LocationCustomKey); Assert.Equal(model.Object.Location?.ApiDetailUrl, searchModel.LocationApiDetailUrl); Assert.Equal(model.Object.Location?.SiteDetailUrl, searchModel.LocationSiteDetailUrl); Assert.Equal(model.Object.Location?.Name, searchModel.LocationName); Assert.Equal(model.Object.Location?.ShortDescription, searchModel.LocationShortDescription); Assert.Equal(model.Object.Location?.Description, searchModel.LocationDescription); }
public void Verify_MapToModel_AssignsSeriesLocationProperties() { // Arrange var mapper = new SeriesLocationMapper(); var entity = SeriesLocationsMockingSetup.DoMockingSetupForSeriesLocation(); // Act var model = mapper.MapToModel(entity.Object); // Assert // <None> // Related Objects Assert.Equal(entity.Object.SeriesId, model.SeriesId); Assert.Equal(entity.Object.LocationId, model.LocationId); // Associated Objects // <None> }
public void Verify_MapToEntity_WithExistingEntity_AssignsSeriesLocationProperties() { // Arrange var mapper = new SeriesLocationMapper(); var model = SeriesLocationsMockingSetup.DoMockingSetupForSeriesLocationModel(); // Act ISeriesLocation existingEntity = new SeriesLocation { Id = 1 }; mapper.MapToEntity(model.Object, ref existingEntity); // Assert // <None> // Related Objects Assert.Equal(model.Object.SeriesId, existingEntity.SeriesId); Assert.Equal(model.Object.LocationId, existingEntity.LocationId); // Associated Objects // <None> }
public void Verify_AreEqual_WithEqualObjects_ReturnsTrue() { // Arrange var mapper = new SeriesLocationMapper(); var model = SeriesLocationsMockingSetup.DoMockingSetupForSeriesLocationModel(1); var entity = SeriesLocationsMockingSetup.DoMockingSetupForSeriesLocation(1); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.True(result); }
public ISeriesLocationModel Get(string key) { BusinessWorkflowBase.ValidateRequiredKey(key); return(SeriesLocationMapper.MapToModel(SeriesLocationsRepository.Get(key))); }
public ISeriesLocationModel Get(int id) { BusinessWorkflowBase.ValidateRequiredID(id); return(SeriesLocationMapper.MapToModel(SeriesLocationsRepository.Get(id))); }