Ejemplo n.º 1
0
        public ICharacterEnemyModel Create(ICharacterEnemyModel 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(CharacterEnemyMapper.MapToSearchModel(model));

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

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            CharacterEnemiesRepository.Add(newEntity);
            // Try to Save Changes
            CharacterEnemiesRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
        public void Verify_MapToSearchModel_AssignsCharacterEnemySearchProperties()
        {
            // Arrange
            var mapper = new CharacterEnemyMapper();
            var model  = CharacterEnemiesMockingSetup.DoMockingSetupForCharacterEnemyModel();
            // 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.EnemyId, searchModel.EnemyId);
            Assert.Equal(model.Object.Enemy?.CustomKey, searchModel.EnemyCustomKey);
            Assert.Equal(model.Object.Enemy?.ApiDetailUrl, searchModel.EnemyApiDetailUrl);
            Assert.Equal(model.Object.Enemy?.SiteDetailUrl, searchModel.EnemySiteDetailUrl);
            Assert.Equal(model.Object.Enemy?.Name, searchModel.EnemyName);
            Assert.Equal(model.Object.Enemy?.ShortDescription, searchModel.EnemyShortDescription);
            Assert.Equal(model.Object.Enemy?.Description, searchModel.EnemyDescription);
        }
 public void Verify_MapToSearchModel_AssignsCharacterEnemySearchProperties()
 {
     // Arrange
     var mapper = new CharacterEnemyMapper();
     var model = CharacterEnemiesMockingSetup.DoMockingSetupForCharacterEnemyModel();
     // 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.EnemyId, searchModel.EnemyId);
     Assert.Equal(model.Object.Enemy?.CustomKey, searchModel.EnemyCustomKey);
     Assert.Equal(model.Object.Enemy?.ApiDetailUrl, searchModel.EnemyApiDetailUrl);
     Assert.Equal(model.Object.Enemy?.SiteDetailUrl, searchModel.EnemySiteDetailUrl);
     Assert.Equal(model.Object.Enemy?.Name, searchModel.EnemyName);
     Assert.Equal(model.Object.Enemy?.ShortDescription, searchModel.EnemyShortDescription);
     Assert.Equal(model.Object.Enemy?.Description, searchModel.EnemyDescription);
 }