public async Task <int> AddFeatureAsync(string name, string environment_name, string feature_name, bool enable, string author) { var currentUser = await _userService.GetByEmailAsync(author); var application = await GetByNameAsync(name, currentUser); var environment = await _environmentService.GetByName(name); var applicationFeature = new ApplicationFeature { ApplicationId = application.Id, EnvironmentId = environment.Id, Name = feature_name.Replace(" ", "_").ToLower(), Enable = enable, CreatedAt = DateTime.Now, CreatedBy = currentUser.Id, UpdatedAt = DateTime.Now, UpdatedBy = currentUser.Id }; await _context.ApplicationFeatures.AddAsync(applicationFeature); _logger.LogInformation($"new feature({feature_name}) adding into application({name})"); return(await _context.SaveChangesAsync()); }
public async Task Should_update_application_feature_data() { var feature = new Feature("Feature01", true); var application = new Application("Sales", "1.1"); var applicationFeature = new ApplicationFeature(feature, application, false); await AddEntity(feature, application, applicationFeature); await ExecuteCommand(async (contexto) => { var applicationFeatureRepository = new ApplicationFeatureRepository(contexto); var featureToUpdate = await applicationFeatureRepository.GetAsync(feature.Id); featureToUpdate.Enable(); await contexto.SaveChangesAsync(); }); var persistedEntity = await ExecuteCommand((contexto) => { var featureRepository = new ApplicationFeatureRepository(contexto); return(featureRepository.GetApplicationFeatureAsync(applicationFeature.Id)); }); using (new AssertionScope()) { persistedEntity.Should().NotBeNull(); persistedEntity.Application.Name.Should().Be("Sales"); persistedEntity.Application.Version.Should().Be("1.1"); persistedEntity.Feature.Name.Should().Be("Feature01"); persistedEntity.Feature.IsActive.Should().Be(true); persistedEntity.IsActive.Should().Be(true); } }
public async Task Should_get_application_feature_by_application_and_feature() { var feature = new Feature("Feature01", false); var application1 = new Application("Sales", "1.1"); var applicationFeature1 = new ApplicationFeature(feature, application1, false); var application2 = new Application("Sales", "1.2"); var applicationFeature2 = new ApplicationFeature(feature, application2, true); var application3 = new Application("Sales", "1.3"); var applicationFeature3 = new ApplicationFeature(feature, application3, false); await AddEntity(feature, application1, application2, application3, applicationFeature1, applicationFeature2, applicationFeature3); var persistedEntity = await ExecuteCommand((contexto) => { var featureRepository = new ApplicationFeatureRepository(contexto); return(featureRepository.GetAsync(application2.Id, feature.Id)); }); using (new AssertionScope()) { persistedEntity.Should().NotBeNull(); persistedEntity.ApplicationId.Should().Be(application2.Id); persistedEntity.FeatureId.Should().Be(feature.Id); persistedEntity.IsActive.Should().Be(true); } }
public void SubFeature1_WebPlatformPRODIsEnabled_ReturnsTrue() { var jsonSettings = GetJsonSettings(EnvironmentEnum.PROD, PlatformEnum.Web, _application); var feature = new ApplicationFeature(jsonSettings); Assert.IsTrue(feature.SubFeature_1().IsEnabled()); }
public void SubFeature1_LocalIsEnabled_ReturnsTrue() { var jsonSettings = GetJsonSettings(EnvironmentEnum.LOCAL, _application); var feature = new ApplicationFeature(jsonSettings); Assert.IsTrue(feature.SubFeature_1().IsEnabled()); }
public void Feature_PRODDesktopPlatformIsEnabled_ReturnsFalse() { var jsonSettings = GetJsonSettings(EnvironmentEnum.PROD, PlatformEnum.Desktop, _application); var feature = new ApplicationFeature(jsonSettings); Assert.IsFalse(feature.IsEnabled()); }
public void Feature_DEVWinPhonePlatformIsEnabled_ReturnsFalse() { var jsonSettings = GetJsonSettings(EnvironmentEnum.LOCAL, PlatformEnum.WinPhone, _application); var feature = new ApplicationFeature(jsonSettings); Assert.IsFalse(feature.IsEnabled()); }
public void Feature_LOCALIsEnabledAll_ReturnsTrue() { var jsonSettings = GetJsonSettings(EnvironmentEnum.LOCAL, _all); var feature = new ApplicationFeature(jsonSettings); Assert.IsTrue(feature.IsEnabled()); }
public void SubFeature2_DesktopPlatformQASIsEnabled_ReturnsFalse() { var jsonSettings = GetJsonSettings(EnvironmentEnum.QAS, PlatformEnum.Desktop, _application); var feature = new ApplicationFeature(jsonSettings); Assert.IsFalse(feature.SubFeature_2(jsonSettings).IsEnabled()); }
public void Feature_STAGEIsEnabled_ReturnsFalse() { var jsonSettings = GetJsonSettings(EnvironmentEnum.STAGE, _application); var feature = new ApplicationFeature(jsonSettings); Assert.IsFalse(feature.IsEnabled()); }
public void SubFeature3_QASIsEnabled_ReturnsFalse() { var jsonSettings = GetJsonSettings(EnvironmentEnum.QAS, _application); var feature = new ApplicationFeature(jsonSettings); Assert.IsFalse(feature.SubFeature_3(jsonSettings).IsEnabled()); }
public void SubFeature3_WebPlatformSTAGEIsEnabled_ReturnsFalse() { var jsonSettings = GetJsonSettings(EnvironmentEnum.STAGE, PlatformEnum.Web, _application); var feature = new ApplicationFeature(jsonSettings); Assert.IsFalse(feature.SubFeature_3(jsonSettings).IsEnabled()); }
public void Feature_DEVIsEnabledWrongApp_ReturnsFalse() { var jsonSettings = GetJsonSettings(EnvironmentEnum.DEV, _wrongApp); var feature = new ApplicationFeature(jsonSettings); Assert.IsFalse(feature.IsEnabled()); }
public void SubFeature3_iOSPlatformLocalIsEnabled_ReturnsFalse() { var jsonSettings = GetJsonSettings(EnvironmentEnum.LOCAL, PlatformEnum.iOS, _application); var feature = new ApplicationFeature(jsonSettings); Assert.IsFalse(feature.SubFeature_3(jsonSettings).IsEnabled()); }
public void SubFeature2_WinPhonePlatformDEVIsEnabled_ReturnsFalse() { var jsonSettings = GetJsonSettings(EnvironmentEnum.DEV, PlatformEnum.WinPhone, _application); var feature = new ApplicationFeature(jsonSettings); Assert.IsFalse(feature.SubFeature_2(jsonSettings).IsEnabled()); }
public void SubFeature2_AndroidPlatformQASIsEnabled_ReturnsTrue() { var jsonSettings = GetJsonSettings(EnvironmentEnum.QAS, PlatformEnum.Android, _application); var feature = new ApplicationFeature(jsonSettings); Assert.IsTrue(feature.SubFeature_2(jsonSettings).IsEnabled()); }
public void SubFeature2_WebPlatformLocalIsEnabled_ReturnsTrue() { var jsonSettings = GetJsonSettings(EnvironmentEnum.LOCAL, PlatformEnum.Web, _application); var feature = new ApplicationFeature(jsonSettings); Assert.IsTrue(feature.SubFeature_2(jsonSettings).IsEnabled()); }
public void SubFeature2_DEVIsEnabled_ReturnsTrue() { var jsonSettings = GetJsonSettings(EnvironmentEnum.DEV, _application); var feature = new ApplicationFeature(jsonSettings); Assert.IsTrue(feature.SubFeature_2(jsonSettings).IsEnabled()); }
public void SubFeature3_AndroidPlatformPRODIsEnabled_ReturnsFalse() { var jsonSettings = GetJsonSettings(EnvironmentEnum.PROD, PlatformEnum.Android, _application); var feature = new ApplicationFeature(jsonSettings); Assert.IsFalse(feature.SubFeature_3(jsonSettings).IsEnabled()); }
public void SubFeature1_DesktopPlatformPRODIsEnabled_ReturnsFalse() { var jsonSettings = GetJsonSettings(EnvironmentEnum.PROD, PlatformEnum.Desktop, _application); var feature = new ApplicationFeature(jsonSettings); var subFeat = feature.SubFeature_1(jsonSettings); Assert.IsFalse(subFeat.IsEnabled()); }
public async Task Should_return_true_if_feature_is_disabled_for_the_app() { var application = new Application("App01", "0.1"); var feature = new Feature("isBlueButtonActive", true); var applicationFeature = new ApplicationFeature(feature, application, false); _applicationFeatureRepository.GetAsync("App01", "0.1", "isBlueButtonActive").Returns(applicationFeature); var result = await _applicationFeatureDomainService.CheckFeature("App01", "0.1", "isBlueButtonActive"); result.Should().NotBeNull(); result.Enabled.Should().BeFalse(); result.Mesage.Should().Be(DomainMessage.FeatureDisabled); }
public async Task Should_toggle_feature_as_active() { var application = new Application("App01", "0.1"); var feature = new Feature("isBlueButtonActive", false); var dto = new ApplicationFeatureDTO(feature, application, true); var applicationFeature = new ApplicationFeature(feature, application, false); _applicationFeatureRepository.GetAsync(application.Id, feature.Id).Returns(applicationFeature); await _applicationFeatureDomainService.TogleApplicationFeature(dto); applicationFeature.IsActive.Should().BeTrue(); }
public void Should_disable_an_application_feature() { var name = "isButtonBlue"; var feature = new Feature(name, false); var applicationName = "sales"; var applicationVersion = "1.1"; var application = new Application(applicationName, applicationVersion); var applicationFeature = new ApplicationFeature(feature, application, false); applicationFeature.Enable(); applicationFeature.IsActive.Should().BeTrue(); }
private static ApplicationFeature UpdateApplicationFeature(ApplicationFeature existingFeature, ApplicationFeatureDTO applicationFeatureDTO) { if (applicationFeatureDTO.IsActive == existingFeature.IsActive) { return(existingFeature); } if (applicationFeatureDTO.IsActive) { existingFeature.Enable(); } else { existingFeature.Disable(); } return(existingFeature); }
public bool RemoveRoleFeature(IApplicationFeaturesAccess access, int roleId, ApplicationFeature feature) { using (var cn = new SqlConnection(connectionString)) { cn.Open(); using (var cmd = cn.CreateCommand()) { cmd.CommandText = "DELETE FROM dbo.ApplicationRoleFeature WHERE (RoleId = @roleId) AND (FeatureId = @featureId);"; cmd.AddParameter("roleId", SqlDbType.Int, roleId); cmd.AddParameter("featureId", SqlDbType.NVarChar, feature.ToString()); var nuRows = cmd.ExecuteNonQuery(); return(nuRows == 1); } } }
public void Should_construct_a_valid_application_feature() { var name = "isButtonBlue"; var feature = new Feature(name, false); var applicationName = "sales"; var applicationVersion = "1.1"; var application = new Application(applicationName, applicationVersion); var applicationFeature = new ApplicationFeature(feature, application, true); using (new AssertionScope()) { applicationFeature.IsActive.Should().BeTrue(); applicationFeature.Feature.Name.Should().Be(name); applicationFeature.Feature.IsActive.Should().BeFalse(); applicationFeature.Application.Name.Should().Be(applicationName); applicationFeature.Application.Version.Should().Be(applicationVersion); } }
public async Task Should_update_feature_if_there_is_an_existing_feature_for_the_provided_application() { var application = new Application("App01", "0.1"); var feature = new Feature("isBlueButtonActive", true); var dto = new ApplicationFeatureDTO(feature, application, false); var applicationFeature = new ApplicationFeature(feature, application, true); _applicationFeatureRepository.GetAsync(application.Id, feature.Id).Returns(applicationFeature); var appFeature = await _applicationFeatureDomainService.Add(dto); using (new AssertionScope()) { _applicationFeatureRepository.Received(0).Add(appFeature); appFeature.Application.Name.Should().Be("App01"); appFeature.Application.Version.Should().Be("0.1"); appFeature.Feature.Name.Should().Be("isBlueButtonActive"); appFeature.Feature.IsActive.Should().Be(true); appFeature.IsActive.Should().Be(false); } }
public async Task <ApplicationFeature> Add(ApplicationFeatureDTO applicationFeatureDTO) { if (!applicationFeatureDTO.IsValid()) { await NotifyValidationErrors(applicationFeatureDTO); return(null); } var existingFeature = await _applicationFeatureRepository.GetAsync(applicationFeatureDTO.Application.Id, applicationFeatureDTO.Feature.Id); if (existingFeature != null) { return(UpdateApplicationFeature(existingFeature, applicationFeatureDTO)); } var applicationFeature = new ApplicationFeature(applicationFeatureDTO.Feature, applicationFeatureDTO.Application, applicationFeatureDTO.IsActive); _applicationFeatureRepository.Add(applicationFeature); return(applicationFeature); }
public bool InsertRoleFeature(IApplicationFeaturesAccess access, int roleId, ApplicationFeature feature) { using (var cn = new SqlConnection(connectionString)) { cn.Open(); using (var cmd = cn.CreateCommand()) { cmd.CommandText = "" + "IF NOT EXISTS(SELECT * FROM dbo.ApplicationRoleFeature WHERE (RoleId = @roleId) AND (FeatureId = @featureId)) BEGIN" + " INSERT INTO dbo.ApplicationRoleFeature (RoleId,FeatureId) OUTPUT INSERTED.ID VALUES (@roleId,@featureId); " + "END ELSE BEGIN" + " SELECT ID FROM dbo.ApplicationRoleFeature WHERE (RoleId = @roleId) AND (FeatureId = @featureId)" + "END"; cmd.AddParameter("roleId", SqlDbType.Int, roleId); cmd.AddParameter("featureId", SqlDbType.NVarChar, feature.ToString()); var userRoleId = Convert.ToInt32(cmd.ExecuteScalar()); return(userRoleId > 0); } } }
public async Task Should_get_all_application_feature() { var feature = new Feature("Feature01", false); var feature2 = new Feature("Feature02", false); var application1 = new Application("Sales", "1.1"); var applicationFeature1 = new ApplicationFeature(feature, application1, false); var applicationFeature2 = new ApplicationFeature(feature2, application1, false); await AddEntity(feature, feature2, application1, applicationFeature1, applicationFeature2); var featureCheck = await ExecuteCommand((context) => { FeatureAppService featureAppService = GetFeatureAppService(context); return(featureAppService.GetAll("Sales", "1.1")); }); using (new AssertionScope()) { featureCheck.Should().NotBeNull(); featureCheck.Should().HaveCount(2); featureCheck.FirstOrDefault(d => d.Id.Equals(feature.Id)).Name.Should().Be("Feature01"); } }