public async Task Create(string name, string description, bool enabled) { //Arrange var postRequest = new FeatureToggleViewModel { Name = name, Description = description, Enabled = enabled }; //Act var response = await Client.PostAsync(ApiUrl, CreateHttpContent(postRequest)); //Assert AssertOkResponse(response); var models = await GetToggles(); Assert.AreEqual(1, models.Count); var model = models[0]; Assert.AreEqual(name, model.Name); Assert.AreEqual(description, model.Description); Assert.AreEqual(enabled, model.Enabled); }
public async Task Create_When_Name_Is_Null() { //Arrange var postRequest = new FeatureToggleViewModel { Name = null, Description = "description", Enabled = true }; //Act var response = await Client.PostAsync(ApiUrl, CreateHttpContent(postRequest)); //Assert AssertBadRequestResponse(response); }
public async Task <ActionResult> Post(FeatureToggleViewModel model) { if (IsValid(model)) { try { var savedModel = await _service.Create(model, GetContext()); return(Ok(new { Id = savedModel.Id.ToString() })); } catch (DuplicateFeatureToggleNameException) { return(Conflict("duplicate toggle name")); } } return(BadRequest()); }
public async Task Create_When_Name_Is_Duplicate() { //Arrange DataSeed.SeedFeatureToggles(new[] { new MongoDbFeatureToggleModel { Name = "ft1" } }); var postRequest = new FeatureToggleViewModel { Name = "ft1", Description = "description", Enabled = true }; //Act var response = await Client.PostAsync(ApiUrl, CreateHttpContent(postRequest)); //Assert AssertConflictResponse(response); }
public async Task <IActionResult> View([FromRoute] Guid applicationId, [FromQuery] Guid?environmentId = null, [FromQuery] string search = null) { ViewData["ApplicationId"] = applicationId; var environments = await environmentService.GetEnvironments(applicationId); ApplicationEnvironment selectedEnvironment = environments.FirstOrDefault(x => x.Id == environmentId); if (selectedEnvironment == null) { selectedEnvironment = environments.First(x => x.IsDefault); } var featureToggles = await featureToggleService.GetKeyValues(selectedEnvironment.Id); if (!string.IsNullOrEmpty(search)) { featureToggles = featureToggles.Where(f => f.Key.ToLower().Contains(search.ToLower())); ViewData["Search"] = search; } var model = new FeatureToggleViewModel { Environments = environments.Select(x => new ApplicationEnvironmentModel { Name = x.Name, EnvironmentId = x.Id, ApplicationId = x.ApplicationId }), FeatureToggles = featureToggles.Select(x => new ApplicationFeatureToggleModel { Id = x.SettingId, Key = x.Key, IsEnabled = x.IsEnabled, LastModifiedAt = x.LastModifiedAt }).OrderBy(x => x.Key), SelectedEnvironment = new ApplicationEnvironmentModel { ApplicationId = applicationId, EnvironmentId = selectedEnvironment.Id, Name = selectedEnvironment.Name } }; return(View(model)); }
private bool IsValid(FeatureToggleViewModel model) { return(!string.IsNullOrWhiteSpace(model.Name)); }
public async Task <IFeatureToggleViewModel> GetById(string id) { var model = await _repository.Get(id); return(model != null ? new FeatureToggleViewModel(model) : FeatureToggleViewModel.Empty()); }