Esempio n. 1
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));
        }
Esempio n. 2
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);
 }