public IPowerAliasModel Create(IPowerAliasModel 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(PowerAliasMapper.MapToSearchModel(model));

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

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            PowerAliasesRepository.Add(newEntity);
            // Try to Save Changes
            PowerAliasesRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
        public void Verify_MapToSearchModel_AssignsPowerAliasSearchProperties()
        {
            // Arrange
            var mapper = new PowerAliasMapper();
            var model  = PowerAliasesMockingSetup.DoMockingSetupForPowerAliasModel();
            // Act
            var searchModel = mapper.MapToSearchModel(model.Object);

            // Assert
            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_AssignsPowerAliasSearchProperties()
 {
     // Arrange
     var mapper = new PowerAliasMapper();
     var model = PowerAliasesMockingSetup.DoMockingSetupForPowerAliasModel();
     // Act
     var searchModel = mapper.MapToSearchModel(model.Object);
     // Assert
     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);
 }