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

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

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            CharacterEnemyTeamsRepository.Add(newEntity);
            // Try to Save Changes
            CharacterEnemyTeamsRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
Example #3
0
        public void Verify_AreEqual_WithDifferentObjects_ReturnsFalse()
        {
            // Arrange
            var mapper = new CharacterEnemyTeamMapper();
            var model  = CharacterEnemyTeamsMockingSetup.DoMockingSetupForCharacterEnemyTeamModel(1);
            var entity = CharacterEnemyTeamsMockingSetup.DoMockingSetupForCharacterEnemyTeam(2);
            // Act
            var result = mapper.AreEqual(model.Object, entity.Object);

            // Assert
            Assert.False(result);
        }
Example #4
0
        public void Verify_MapToModelLite_AssignsLiteOnlyCharacterEnemyTeamProperties()
        {
            // Arrange
            var mapper = new CharacterEnemyTeamMapper();
            var entity = CharacterEnemyTeamsMockingSetup.DoMockingSetupForCharacterEnemyTeam();
            // Act
            var model = mapper.MapToModelLite(entity.Object);

            // Assert
            // <None>
            // Related Objects
            Assert.Equal(entity.Object.CharacterId, model.CharacterId);
            Assert.Equal(entity.Object.EnemyTeamId, model.EnemyTeamId);
        }
Example #5
0
        public void Verify_MapToEntity_AssignsCharacterEnemyTeamProperties()
        {
            // Arrange
            var mapper = new CharacterEnemyTeamMapper();
            var model  = CharacterEnemyTeamsMockingSetup.DoMockingSetupForCharacterEnemyTeamModel();
            // Act
            var entity = mapper.MapToEntity(model.Object);

            // Assert
            // <None>
            // Related Objects
            Assert.Equal(model.Object.CharacterId, entity.CharacterId);
            Assert.Equal(model.Object.EnemyTeamId, entity.EnemyTeamId);
            // Associated Objects
            // <None>
        }
Example #6
0
        public void Verify_MapToSearchModel_AssignsCharacterEnemyTeamSearchProperties()
        {
            // Arrange
            var mapper = new CharacterEnemyTeamMapper();
            var model  = CharacterEnemyTeamsMockingSetup.DoMockingSetupForCharacterEnemyTeamModel();
            // 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.EnemyTeamId, searchModel.EnemyTeamId);
            Assert.Equal(model.Object.EnemyTeam?.CustomKey, searchModel.EnemyTeamCustomKey);
            Assert.Equal(model.Object.EnemyTeam?.ApiDetailUrl, searchModel.EnemyTeamApiDetailUrl);
            Assert.Equal(model.Object.EnemyTeam?.SiteDetailUrl, searchModel.EnemyTeamSiteDetailUrl);
            Assert.Equal(model.Object.EnemyTeam?.Name, searchModel.EnemyTeamName);
            Assert.Equal(model.Object.EnemyTeam?.ShortDescription, searchModel.EnemyTeamShortDescription);
            Assert.Equal(model.Object.EnemyTeam?.Description, searchModel.EnemyTeamDescription);
        }
 public void Verify_MapToSearchModel_AssignsCharacterEnemyTeamSearchProperties()
 {
     // Arrange
     var mapper = new CharacterEnemyTeamMapper();
     var model = CharacterEnemyTeamsMockingSetup.DoMockingSetupForCharacterEnemyTeamModel();
     // 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.EnemyTeamId, searchModel.EnemyTeamId);
     Assert.Equal(model.Object.EnemyTeam?.CustomKey, searchModel.EnemyTeamCustomKey);
     Assert.Equal(model.Object.EnemyTeam?.ApiDetailUrl, searchModel.EnemyTeamApiDetailUrl);
     Assert.Equal(model.Object.EnemyTeam?.SiteDetailUrl, searchModel.EnemyTeamSiteDetailUrl);
     Assert.Equal(model.Object.EnemyTeam?.Name, searchModel.EnemyTeamName);
     Assert.Equal(model.Object.EnemyTeam?.ShortDescription, searchModel.EnemyTeamShortDescription);
     Assert.Equal(model.Object.EnemyTeam?.Description, searchModel.EnemyTeamDescription);
 }
 public void Verify_MapToModel_AssignsCharacterEnemyTeamProperties()
 {
     // Arrange
     var mapper = new CharacterEnemyTeamMapper();
     var entity = CharacterEnemyTeamsMockingSetup.DoMockingSetupForCharacterEnemyTeam();
     // Act
     var model = mapper.MapToModel(entity.Object);
     // Assert
     // <None>
     // Related Objects
     Assert.Equal(entity.Object.CharacterId, model.CharacterId);
     Assert.Equal(entity.Object.EnemyTeamId, model.EnemyTeamId);
     // Associated Objects
     // <None>
 }
 public void Verify_MapToEntity_WithExistingEntity_AssignsCharacterEnemyTeamProperties()
 {
     // Arrange
     var mapper = new CharacterEnemyTeamMapper();
     var model = CharacterEnemyTeamsMockingSetup.DoMockingSetupForCharacterEnemyTeamModel();
     // Act
     ICharacterEnemyTeam existingEntity = new CharacterEnemyTeam { Id = 1 };
     mapper.MapToEntity(model.Object, ref existingEntity);
     // Assert
     // <None>
     // Related Objects
     Assert.Equal(model.Object.CharacterId, existingEntity.CharacterId);
     Assert.Equal(model.Object.EnemyTeamId, existingEntity.EnemyTeamId);
     // Associated Objects
     // <None>
 }
 public void Verify_AreEqual_WithEqualObjects_ReturnsTrue()
 {
     // Arrange
     var mapper = new CharacterEnemyTeamMapper();
     var model = CharacterEnemyTeamsMockingSetup.DoMockingSetupForCharacterEnemyTeamModel(1);
     var entity = CharacterEnemyTeamsMockingSetup.DoMockingSetupForCharacterEnemyTeam(1);
     // Act
     var result = mapper.AreEqual(model.Object, entity.Object);
     // Assert
     Assert.True(result);
 }
 public ICharacterEnemyTeamModel Get(string key)
 {
     BusinessWorkflowBase.ValidateRequiredKey(key);
     return(CharacterEnemyTeamMapper.MapToModel(CharacterEnemyTeamsRepository.Get(key)));
 }
 public ICharacterEnemyTeamModel Get(int id)
 {
     BusinessWorkflowBase.ValidateRequiredID(id);
     return(CharacterEnemyTeamMapper.MapToModel(CharacterEnemyTeamsRepository.Get(id)));
 }