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

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

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            CharacterPowersRepository.Add(newEntity);
            // Try to Save Changes
            CharacterPowersRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
コード例 #3
0
        public void Verify_AreEqual_WithDifferentObjects_ReturnsFalse()
        {
            // Arrange
            var mapper = new CharacterPowerMapper();
            var model  = CharacterPowersMockingSetup.DoMockingSetupForCharacterPowerModel(1);
            var entity = CharacterPowersMockingSetup.DoMockingSetupForCharacterPower(2);
            // Act
            var result = mapper.AreEqual(model.Object, entity.Object);

            // Assert
            Assert.False(result);
        }
コード例 #4
0
        public void Verify_MapToModelLite_AssignsLiteOnlyCharacterPowerProperties()
        {
            // Arrange
            var mapper = new CharacterPowerMapper();
            var entity = CharacterPowersMockingSetup.DoMockingSetupForCharacterPower();
            // Act
            var model = mapper.MapToModelLite(entity.Object);

            // Assert
            // <None>
            // Related Objects
            Assert.Equal(entity.Object.CharacterId, model.CharacterId);
            Assert.Equal(entity.Object.PowerId, model.PowerId);
        }
コード例 #5
0
        public void Verify_MapToEntity_AssignsCharacterPowerProperties()
        {
            // Arrange
            var mapper = new CharacterPowerMapper();
            var model  = CharacterPowersMockingSetup.DoMockingSetupForCharacterPowerModel();
            // Act
            var entity = mapper.MapToEntity(model.Object);

            // Assert
            // <None>
            // Related Objects
            Assert.Equal(model.Object.CharacterId, entity.CharacterId);
            Assert.Equal(model.Object.PowerId, entity.PowerId);
            // Associated Objects
            // <None>
        }
コード例 #6
0
        public void Verify_MapToSearchModel_AssignsCharacterPowerSearchProperties()
        {
            // Arrange
            var mapper = new CharacterPowerMapper();
            var model  = CharacterPowersMockingSetup.DoMockingSetupForCharacterPowerModel();
            // Act
            var searchModel = mapper.MapToSearchModel(model.Object);

            // Assert
            Assert.Equal(model.Object.CharacterId, searchModel.CharacterId);
            Assert.Equal(model.Object.Character?.CustomKey, searchModel.CharacterCustomKey);
            Assert.Equal(model.Object.Character?.ApiDetailUrl, searchModel.CharacterApiDetailUrl);
            Assert.Equal(model.Object.Character?.SiteDetailUrl, searchModel.CharacterSiteDetailUrl);
            Assert.Equal(model.Object.Character?.Name, searchModel.CharacterName);
            Assert.Equal(model.Object.Character?.ShortDescription, searchModel.CharacterShortDescription);
            Assert.Equal(model.Object.Character?.Description, searchModel.CharacterDescription);
            Assert.Equal(model.Object.PowerId, searchModel.PowerId);
            Assert.Equal(model.Object.Power?.CustomKey, searchModel.PowerCustomKey);
            Assert.Equal(model.Object.Power?.ApiDetailUrl, searchModel.PowerApiDetailUrl);
            Assert.Equal(model.Object.Power?.SiteDetailUrl, searchModel.PowerSiteDetailUrl);
            Assert.Equal(model.Object.Power?.Name, searchModel.PowerName);
            Assert.Equal(model.Object.Power?.ShortDescription, searchModel.PowerShortDescription);
            Assert.Equal(model.Object.Power?.Description, searchModel.PowerDescription);
        }
 public void Verify_MapToSearchModel_AssignsCharacterPowerSearchProperties()
 {
     // Arrange
     var mapper = new CharacterPowerMapper();
     var model = CharacterPowersMockingSetup.DoMockingSetupForCharacterPowerModel();
     // Act
     var searchModel = mapper.MapToSearchModel(model.Object);
     // Assert
     Assert.Equal(model.Object.CharacterId, searchModel.CharacterId);
     Assert.Equal(model.Object.Character?.CustomKey, searchModel.CharacterCustomKey);
     Assert.Equal(model.Object.Character?.ApiDetailUrl, searchModel.CharacterApiDetailUrl);
     Assert.Equal(model.Object.Character?.SiteDetailUrl, searchModel.CharacterSiteDetailUrl);
     Assert.Equal(model.Object.Character?.Name, searchModel.CharacterName);
     Assert.Equal(model.Object.Character?.ShortDescription, searchModel.CharacterShortDescription);
     Assert.Equal(model.Object.Character?.Description, searchModel.CharacterDescription);
     Assert.Equal(model.Object.PowerId, searchModel.PowerId);
     Assert.Equal(model.Object.Power?.CustomKey, searchModel.PowerCustomKey);
     Assert.Equal(model.Object.Power?.ApiDetailUrl, searchModel.PowerApiDetailUrl);
     Assert.Equal(model.Object.Power?.SiteDetailUrl, searchModel.PowerSiteDetailUrl);
     Assert.Equal(model.Object.Power?.Name, searchModel.PowerName);
     Assert.Equal(model.Object.Power?.ShortDescription, searchModel.PowerShortDescription);
     Assert.Equal(model.Object.Power?.Description, searchModel.PowerDescription);
 }
 public void Verify_MapToModel_AssignsCharacterPowerProperties()
 {
     // Arrange
     var mapper = new CharacterPowerMapper();
     var entity = CharacterPowersMockingSetup.DoMockingSetupForCharacterPower();
     // Act
     var model = mapper.MapToModel(entity.Object);
     // Assert
     // <None>
     // Related Objects
     Assert.Equal(entity.Object.CharacterId, model.CharacterId);
     Assert.Equal(entity.Object.PowerId, model.PowerId);
     // Associated Objects
     // <None>
 }
 public void Verify_MapToEntity_WithExistingEntity_AssignsCharacterPowerProperties()
 {
     // Arrange
     var mapper = new CharacterPowerMapper();
     var model = CharacterPowersMockingSetup.DoMockingSetupForCharacterPowerModel();
     // Act
     ICharacterPower existingEntity = new CharacterPower { Id = 1 };
     mapper.MapToEntity(model.Object, ref existingEntity);
     // Assert
     // <None>
     // Related Objects
     Assert.Equal(model.Object.CharacterId, existingEntity.CharacterId);
     Assert.Equal(model.Object.PowerId, existingEntity.PowerId);
     // Associated Objects
     // <None>
 }
 public void Verify_AreEqual_WithEqualObjects_ReturnsTrue()
 {
     // Arrange
     var mapper = new CharacterPowerMapper();
     var model = CharacterPowersMockingSetup.DoMockingSetupForCharacterPowerModel(1);
     var entity = CharacterPowersMockingSetup.DoMockingSetupForCharacterPower(1);
     // Act
     var result = mapper.AreEqual(model.Object, entity.Object);
     // Assert
     Assert.True(result);
 }
コード例 #11
0
 public ICharacterPowerModel Get(string key)
 {
     BusinessWorkflowBase.ValidateRequiredKey(key);
     return(CharacterPowerMapper.MapToModel(CharacterPowersRepository.Get(key)));
 }
コード例 #12
0
 public ICharacterPowerModel Get(int id)
 {
     BusinessWorkflowBase.ValidateRequiredID(id);
     return(CharacterPowerMapper.MapToModel(CharacterPowersRepository.Get(id)));
 }