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

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

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            OriginsRepository.Add(newEntity);
            // Try to Save Changes
            OriginsRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
示例#3
0
 public void Verify_MapToSearchModel_AssignsOriginSearchProperties()
 {
     // Arrange
     var mapper = new OriginMapper();
     var model  = OriginsMockingSetup.DoMockingSetupForOriginModel();
     // Act
     var searchModel = mapper.MapToSearchModel(model.Object);
     // Assert
 }
示例#4
0
        public void Verify_AreEqual_WithDifferentObjects_ReturnsFalse()
        {
            // Arrange
            var mapper = new OriginMapper();
            var model  = OriginsMockingSetup.DoMockingSetupForOriginModel(1);
            var entity = OriginsMockingSetup.DoMockingSetupForOrigin(2);
            // Act
            var result = mapper.AreEqual(model.Object, entity.Object);

            // Assert
            Assert.False(result);
        }
示例#5
0
        public void Verify_MapToModelLite_AssignsLiteOnlyOriginProperties()
        {
            // Arrange
            var mapper = new OriginMapper();
            var entity = OriginsMockingSetup.DoMockingSetupForOrigin();
            // Act
            var model = mapper.MapToModelLite(entity.Object);

            // Assert
            Assert.Equal(entity.Object.CharacterSet, model.CharacterSet);
            // Related Objects
            // <None>
        }
示例#6
0
        public void Verify_MapToModel_AssignsOriginProperties()
        {
            // Arrange
            var mapper = new OriginMapper();
            var entity = OriginsMockingSetup.DoMockingSetupForOrigin();
            // Act
            var model = mapper.MapToModel(entity.Object);

            // Assert
            Assert.Equal(entity.Object.CharacterSet, model.CharacterSet);
            // Related Objects
            // <None>
            // Associated Objects
            Assert.Equal(entity.Object.OriginProfiles?.Count, model.OriginProfiles?.Count);
        }
示例#7
0
        public void Verify_MapToEntity_AssignsOriginProperties()
        {
            // Arrange
            var mapper = new OriginMapper();
            var model  = OriginsMockingSetup.DoMockingSetupForOriginModel();
            // Act
            var entity = mapper.MapToEntity(model.Object);

            // Assert
            Assert.Equal(model.Object.CharacterSet, entity.CharacterSet);
            // Related Objects
            // <None>
            // Associated Objects
            //Assert.Equal(model.Object.OriginProfiles?.Count, entity.OriginProfiles?.Count);
            model.VerifyGet(x => x.OriginProfiles, Times.Once);
        }
 public IOriginModel Get(string key)
 {
     BusinessWorkflowBase.ValidateRequiredKey(key);
     return(OriginMapper.MapToModel(OriginsRepository.Get(key)));
 }
 public IOriginModel Get(int id)
 {
     BusinessWorkflowBase.ValidateRequiredID(id);
     return(OriginMapper.MapToModel(OriginsRepository.Get(id)));
 }
 public void Verify_MapToSearchModel_AssignsOriginSearchProperties()
 {
     // Arrange
     var mapper = new OriginMapper();
     var model = OriginsMockingSetup.DoMockingSetupForOriginModel();
     // Act
     var searchModel = mapper.MapToSearchModel(model.Object);
     // Assert
 }
 public void Verify_MapToModel_AssignsOriginProperties()
 {
     // Arrange
     var mapper = new OriginMapper();
     var entity = OriginsMockingSetup.DoMockingSetupForOrigin();
     // Act
     var model = mapper.MapToModel(entity.Object);
     // Assert
     Assert.Equal(entity.Object.CharacterSet, model.CharacterSet);
     // Related Objects
     // <None>
     // Associated Objects
     Assert.Equal(entity.Object.OriginProfiles?.Count, model.OriginProfiles?.Count);
 }
 public void Verify_MapToModelLite_AssignsLiteOnlyOriginProperties()
 {
     // Arrange
     var mapper = new OriginMapper();
     var entity = OriginsMockingSetup.DoMockingSetupForOrigin();
     // Act
     var model = mapper.MapToModelLite(entity.Object);
     // Assert
     Assert.Equal(entity.Object.CharacterSet, model.CharacterSet);
     // Related Objects
     // <None>
 }
 public void Verify_MapToEntity_WithExistingEntity_AssignsOriginProperties()
 {
     // Arrange
     var mapper = new OriginMapper();
     var model = OriginsMockingSetup.DoMockingSetupForOriginModel();
     // Act
     IOrigin existingEntity = new Origin { Id = 1 };
     mapper.MapToEntity(model.Object, ref existingEntity);
     // Assert
     Assert.Equal(model.Object.CharacterSet, existingEntity.CharacterSet);
     // Related Objects
     // <None>
     // Associated Objects
     model.VerifyGet(x => x.OriginProfiles, Times.Once);
     //Assert.Equal(model.Object.OriginProfiles?.Count, existingEntity.OriginProfiles?.Count);
 }
 public void Verify_AreEqual_WithEqualObjects_ReturnsTrue()
 {
     // Arrange
     var mapper = new OriginMapper();
     var model = OriginsMockingSetup.DoMockingSetupForOriginModel(1);
     var entity = OriginsMockingSetup.DoMockingSetupForOrigin(1);
     // Act
     var result = mapper.AreEqual(model.Object, entity.Object);
     // Assert
     Assert.True(result);
 }