public void GetApplicationFeatureToggles_ReturnsExistingFeaturesStatuses_ForTheGivenApplicationNameAndEnvironmentName() { //arrange var app = new Application { Id = 1, AppName = "TestApp" }; var environment = new DeployEnvironment { Application = app, ApplicationId = app.Id, EnvName = "TestEnv" }; var firstFeatureStatus = new FeatureToggleStatus { Enabled = false, Id = 1, IsDeployed = false, Environment = environment, EnvironmentId = environment.Id }; var secondFeatureStatus = new FeatureToggleStatus { Enabled = false, Id = 2, IsDeployed = false, Environment = environment, EnvironmentId = environment.Id }; var thirdFeatureStatus = new FeatureToggleStatus { Enabled = false, Id = 3, IsDeployed = false, Environment = environment, EnvironmentId = environment.Id }; var discardedFeature = new FeatureToggleStatus { Enabled = false, Id = 5, IsDeployed = false, Environment = new DeployEnvironment { EnvName = "AnotherEnv" }, EnvironmentId = 67 }; var feature = new FeatureToggle { Id = 1, Application = app, ApplicationId = app.Id, FeatureToggleStatuses = new List <FeatureToggleStatus> { firstFeatureStatus, secondFeatureStatus, thirdFeatureStatus }, ToggleName = "Test" }; _context.FeatureToggleStatuses.AddRange(firstFeatureStatus, secondFeatureStatus, thirdFeatureStatus, discardedFeature); _context.Applications.Add(app); _context.DeployEnvironments.Add(environment); _context.FeatureToggles.Add(feature); _context.SaveChanges(); var controller = new FeatureTogglesController(_context); //act var result = controller.GetApplicationFeatureToggles(app.AppName, environment.EnvName) as OkObjectResult; var okObjectResult = result.Value as IEnumerable <ApplicationFeatureToggleViewModel>; //assert okObjectResult.ToList().Count.Should().Be(3); okObjectResult.First().FeatureToggleName.Should().Be(firstFeatureStatus.FeatureToggle.ToggleName); okObjectResult.First().IsEnabled.Should().Be(firstFeatureStatus.Enabled); }
public async Task GetApplicationFeatureToggles_ReturnsFeatureToggleState_ForTheGivenApplicationNameAndEnvironmentName() { //arrange var app = Application.Create("TestApp", "DEV", false); app.AddDeployEnvironment("QA", false, false, false); app.AddFeatureToggle("t1", "", "workItemId1"); var toggle = app.FeatureToggles.FirstOrDefault(f => f.ToggleName == "t1"); app.SetToggle(toggle.Id, "DEV", true, "username"); app.SetToggle(toggle.Id, "QA", false, "username"); await _appRepository.AddAsync(app); //act var result = await _featureToggleController.GetApplicationFeatureToggles(app.AppName, "DEV") as OkObjectResult; var okObjectResult = result.Value as IEnumerable <ApplicationFeatureToggleViewModel>; //assert okObjectResult.ToList().Count.Should().Be(1); okObjectResult.First().FeatureToggleName.Should().Be("t1"); okObjectResult.First().IsEnabled.Should().BeTrue(); }