public async Task Should_toggle_application_feature() { var application = new Application("App01", "0.1"); var feature = new Feature("isButtonGreen", false); await AddEntity(application, feature); var newFeature = await ExecuteCommand((context) => { FeatureAppService featureAppService = GetFeatureAppService(context); return(featureAppService.AddApplicationFeature(new ApplicationFeatureModel("App01", "0.1", "isButtonGreen", true))); }); await ExecuteCommand((context) => { FeatureAppService featureAppService = GetFeatureAppService(context); return(featureAppService.ToggleApplicationFeature(new ApplicationFeatureModel("App01", "0.1", "isButtonGreen", false))); }); var persistedEntity = await ExecuteCommand((contexto) => { var featureRepository = new ApplicationFeatureRepository(contexto); return(featureRepository.GetAsync(newFeature.Id)); }); using (new AssertionScope()) { persistedEntity.ApplicationId.Should().Be(application.Id); persistedEntity.FeatureId.Should().Be(feature.Id); persistedEntity.IsActive.Should().BeFalse(); } }
protected virtual async Task SaveAsync() { try { var features = new UpdateFeaturesDto { Features = Groups.SelectMany(g => g.Features).Select(f => new UpdateFeatureDto { Name = f.Name, Value = f.ValueType is ToggleStringValueType ? ToggleValues[f.Name].ToString() : f.ValueType is SelectionStringValueType ? SelectionStringValues[f.Name] : f.Value }).ToList() }; await FeatureAppService.UpdateAsync(ProviderName, ProviderKey, features); await CurrentApplicationConfigurationCacheResetService.ResetAsync(); await InvokeAsync(Modal.Hide); } catch (Exception ex) { await HandleErrorAsync(ex); } }
public async Task Should_check_application_feature() { var application = new Application("App01", "0.1"); var feature = new Feature("isButtonGreen", false); await AddEntity(application, feature); var newFeature = await ExecuteCommand((context) => { FeatureAppService featureAppService = GetFeatureAppService(context); return(featureAppService.AddApplicationFeature(new ApplicationFeatureModel("App01", "0.1", "isButtonGreen", true))); }); var featureCheck = await ExecuteCommand((context) => { FeatureAppService featureAppService = GetFeatureAppService(context); return(featureAppService.Check("App01", "0.1", "isButtonGreen")); }); using (new AssertionScope()) { featureCheck.Enabled.Should().BeTrue(); featureCheck.Mesage.Should().Be(DomainMessage.FeatureEnabled); } }
public async Task Should_toggle_feature() { var feature = new Feature("isButtonGreen", false); await AddEntity(feature); await ExecuteCommand((context) => { FeatureAppService featureAppService = GetFeatureAppService(context); return(featureAppService.ToggleFeature(new FeatureModel { Name = "isButtonGreen", IsActive = true })); }); var persistedEntity = await ExecuteCommand((contexto) => { var featureRepository = new FeatureRepository(contexto); return(featureRepository.GetAsync(feature.Id)); }); using (new AssertionScope()) { persistedEntity.Name.Should().Be("isButtonGreen"); persistedEntity.IsActive.Should().BeTrue(); } }
public virtual async Task OpenAsync([NotNull] string providerName, string providerKey = null) { ProviderName = providerName; ProviderKey = providerKey; ToggleValues = new Dictionary <string, bool>(); SelectionStringValues = new Dictionary <string, string>(); Groups = (await FeatureAppService.GetAsync(ProviderName, ProviderKey)).Groups; SelectedTabName = GetNormalizedGroupName(Groups.First().Name); foreach (var featureGroupDto in Groups) { foreach (var featureDto in featureGroupDto.Features) { if (featureDto.ValueType is ToggleStringValueType) { ToggleValues.Add(featureDto.Name, bool.Parse(featureDto.Value)); } if (featureDto.ValueType is SelectionStringValueType) { SelectionStringValues.Add(featureDto.Name, featureDto.Value); } } } Modal.Show(); }
public virtual async Task <IActionResult> OnGetAsync() { ValidateModel(); FeatureListResultDto = await FeatureAppService.GetAsync(ProviderName, ProviderKey); return(Page()); }
private FeatureAppService GetFeatureAppService(TogglerContext context) { var featureRepository = new FeatureRepository(context); var applicationFeatureRepository = new ApplicationFeatureRepository(context); var applicationRepository = new ApplicationRepository(context); var uow = new UnitOfWork(context); var featureDomainService = new FeatureDomainService(_mediator, featureRepository); var applicationFeatureDomainService = new ApplicationFeatureDomainService(_mediator, applicationFeatureRepository, featureRepository); var featureAppService = new FeatureAppService(uow, applicationRepository, featureRepository, featureDomainService, applicationFeatureDomainService, applicationFeatureRepository); return(featureAppService); }
public async Task OpenAsync(string providerName, string providerKey) { _providerName = providerName; _providerKey = providerKey; _groups = (await FeatureAppService.GetAsync(_providerName, _providerKey)).Groups; ToggleValues = _groups .SelectMany(x => x.Features) .Where(x => x.ValueType is ToggleStringValueType) .ToDictionary(x => x.Name, x => bool.Parse(x.Value)); _modal.Show(); }
private async Task SaveAsync() { var features = new UpdateFeaturesDto { Features = _groups.SelectMany(g => g.Features).Select(f => new UpdateFeatureDto { Name = f.Name, Value = f.ValueType is ToggleStringValueType ? ToggleValues[f.Name].ToString() : f.Value }).ToList() }; await FeatureAppService.UpdateAsync(_providerName, _providerKey, features); _modal.Hide(); }
public async Task Should_return_null_and_raise_error_when_invalid_data_is_provided() { var newFeature = await ExecuteCommand((context) => { FeatureAppService featureAppService = GetFeatureAppService(context); return(featureAppService.Add(new FeatureModel { Name = "", IsActive = true })); }); using (new AssertionScope()) { newFeature.Should().BeNull(); await _mediator.Received(1).Publish(Arg.Is <ErrorNotification>(d => d.Error.Equals(DomainMessageError.FeatureNameCannotBeNulllOrEmpty))); } }
protected virtual async Task SaveAsync() { var features = new UpdateFeaturesDto { Features = Groups.SelectMany(g => g.Features).Select(f => new UpdateFeatureDto { Name = f.Name, Value = f.ValueType is ToggleStringValueType ? ToggleValues[f.Name].ToString() : f.ValueType is SelectionStringValueType ? SelectionStringValues[f.Name] : f.Value }).ToList() }; await FeatureAppService.UpdateAsync(ProviderName, ProviderKey, features); Modal.Hide(); }
public async Task Should_return_null_and_raise_error_when_adding_new_application_feature_with_invalid_data() { var feature = new Feature("isButtonGreen", false); await AddEntity(feature); var newFeature = await ExecuteCommand((context) => { FeatureAppService featureAppService = GetFeatureAppService(context); return(featureAppService.AddApplicationFeature(new ApplicationFeatureModel("App01", "0.1", "isButtonGreen", true))); }); using (new AssertionScope()) { newFeature.Should().BeNull(); await _mediator.Received(1).Publish(Arg.Is <ErrorNotification>(d => d.Error.Equals(DomainMessageError.ApplicationCannotBeNull))); } }
public virtual async Task <IActionResult> OnPostAsync() { var features = new UpdateFeaturesDto { Features = FeatureGroups.SelectMany(g => g.Features).Select(f => new UpdateFeatureDto { Name = f.Name, Value = f.Type == nameof(ToggleStringValueType) ? f.BoolValue.ToString() : f.Value }).ToList() }; await FeatureAppService.UpdateAsync(ProviderName, ProviderKey, features); await LocalEventBus.PublishAsync( new CurrentApplicationConfigurationCacheResetEventData() ); return(NoContent()); }
public virtual async Task OpenAsync([NotNull] string providerName, string providerKey = null) { try { ProviderName = providerName; ProviderKey = providerKey; ToggleValues = new Dictionary <string, bool>(); SelectionStringValues = new Dictionary <string, string>(); Groups = (await FeatureAppService.GetAsync(ProviderName, ProviderKey))?.Groups; Groups ??= new List <FeatureGroupDto>(); if (Groups.Any()) { SelectedTabName = GetNormalizedGroupName(Groups.First().Name); } foreach (var featureGroupDto in Groups) { foreach (var featureDto in featureGroupDto.Features) { if (featureDto.ValueType is ToggleStringValueType) { ToggleValues.Add(featureDto.Name, bool.Parse(featureDto.Value)); } if (featureDto.ValueType is SelectionStringValueType) { SelectionStringValues.Add(featureDto.Name, featureDto.Value); } } } await InvokeAsync(Modal.Show); } catch (Exception ex) { await HandleErrorAsync(ex); } }
public async Task Should_add_new_feature() { var newFeature = await ExecuteCommand((context) => { FeatureAppService featureAppService = GetFeatureAppService(context); return(featureAppService.Add(new FeatureModel { Name = "isButtonGreen", IsActive = true })); }); var persistedEntity = await ExecuteCommand((contexto) => { var featureRepository = new FeatureRepository(contexto); return(featureRepository.GetAsync(newFeature.Id)); }); using (new AssertionScope()) { persistedEntity.Should().NotBeNull(); newFeature.Name.Should().Be("isButtonGreen"); newFeature.IsActive.Should().BeTrue(); } }
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"); } }