Ejemplo n.º 1
0
        public ILocationAliasModel Update(ILocationAliasModel model)
        {
            // Validate model
            BusinessWorkflowBase.ValidateRequiredNullableID(model.Id);
            //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
            // Find existing entity
            // ReSharper disable once PossibleInvalidOperationException
            var existingEntity = LocationAliasesRepository.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 (LocationAliasMapper.AreEqual(model, existingEntity))
            {
                return(LocationAliasMapper.MapToModel(existingEntity));
            }
            // Map model to an existing entity
            LocationAliasMapper.MapToEntity(model, ref existingEntity);
            existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime;
            // Update it
            LocationAliasesRepository.Update(LocationAliasMapper.MapToEntity(model));
            // Try to Save Changes
            LocationAliasesRepository.SaveChanges();
            // Return the new value
            return(Get(existingEntity.Id));
        }
Ejemplo n.º 2
0
        public ILocationAliasModel Create(ILocationAliasModel 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(LocationAliasMapper.MapToSearchModel(model));

            if (results.Any())
            {
                return(results.First());
            }                                              // Return the first that matches
            // Map model to a new entity
            var newEntity = LocationAliasMapper.MapToEntity(model);

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            LocationAliasesRepository.Add(newEntity);
            // Try to Save Changes
            LocationAliasesRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
 public void Verify_AreEqual_WithEqualObjects_ReturnsTrue()
 {
     // Arrange
     var mapper = new LocationAliasMapper();
     var model = LocationAliasesMockingSetup.DoMockingSetupForLocationAliasModel(1);
     var entity = LocationAliasesMockingSetup.DoMockingSetupForLocationAlias(1);
     // Act
     var result = mapper.AreEqual(model.Object, entity.Object);
     // Assert
     Assert.True(result);
 }
Ejemplo n.º 4
0
        public void Verify_AreEqual_WithDifferentObjects_ReturnsFalse()
        {
            // Arrange
            var mapper = new LocationAliasMapper();
            var model  = LocationAliasesMockingSetup.DoMockingSetupForLocationAliasModel(1);
            var entity = LocationAliasesMockingSetup.DoMockingSetupForLocationAlias(2);
            // Act
            var result = mapper.AreEqual(model.Object, entity.Object);

            // Assert
            Assert.False(result);
        }
Ejemplo n.º 5
0
        public void Verify_MapToModelLite_AssignsLiteOnlyLocationAliasProperties()
        {
            // Arrange
            var mapper = new LocationAliasMapper();
            var entity = LocationAliasesMockingSetup.DoMockingSetupForLocationAlias();
            // Act
            var model = mapper.MapToModelLite(entity.Object);

            // Assert
            // <None>
            // Related Objects
            Assert.Equal(entity.Object.LocationId, model.LocationId);
        }
 public void Verify_MapToEntity_AssignsLocationAliasProperties()
 {
     // Arrange
     var mapper = new LocationAliasMapper();
     var model = LocationAliasesMockingSetup.DoMockingSetupForLocationAliasModel();
     // Act
     var entity = mapper.MapToEntity(model.Object);
     // Assert
     // <None>
     // Related Objects
     Assert.Equal(model.Object.LocationId, entity.LocationId);
     // Associated Objects
     // <None>
 }
Ejemplo n.º 7
0
        public void Verify_MapToEntity_AssignsLocationAliasProperties()
        {
            // Arrange
            var mapper = new LocationAliasMapper();
            var model  = LocationAliasesMockingSetup.DoMockingSetupForLocationAliasModel();
            // Act
            var entity = mapper.MapToEntity(model.Object);

            // Assert
            // <None>
            // Related Objects
            Assert.Equal(model.Object.LocationId, entity.LocationId);
            // Associated Objects
            // <None>
        }
Ejemplo n.º 8
0
        public void Verify_MapToSearchModel_AssignsLocationAliasSearchProperties()
        {
            // Arrange
            var mapper = new LocationAliasMapper();
            var model  = LocationAliasesMockingSetup.DoMockingSetupForLocationAliasModel();
            // Act
            var searchModel = mapper.MapToSearchModel(model.Object);

            // Assert
            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);
        }
Ejemplo n.º 9
0
 public ILocationAliasModel Get(string key)
 {
     BusinessWorkflowBase.ValidateRequiredKey(key);
     return(LocationAliasMapper.MapToModel(LocationAliasesRepository.Get(key)));
 }
Ejemplo n.º 10
0
 public ILocationAliasModel Get(int id)
 {
     BusinessWorkflowBase.ValidateRequiredID(id);
     return(LocationAliasMapper.MapToModel(LocationAliasesRepository.Get(id)));
 }
 public void Verify_MapToModelListing_AssignsListingOnlyLocationAliasProperties()
 {
     // Arrange
     var mapper = new LocationAliasMapper();
     var entity = LocationAliasesMockingSetup.DoMockingSetupForLocationAlias();
     // Act
     var model = mapper.MapToModelListing(entity.Object);
     // Assert
     // <None>
     // Related Objects
     Assert.Equal(entity.Object.LocationId, model.LocationId);
     // Return Entity
 }
 public void Verify_MapToSearchModel_AssignsLocationAliasSearchProperties()
 {
     // Arrange
     var mapper = new LocationAliasMapper();
     var model = LocationAliasesMockingSetup.DoMockingSetupForLocationAliasModel();
     // Act
     var searchModel = mapper.MapToSearchModel(model.Object);
     // Assert
     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);
 }