示例#1
0
        public void DeleteEnvironment_EnvironmentIsDeletedWithInvalidID_ThrowsInvalidOperationException()
        {
            //arrange
            var app = new Application {
                Id = 1, AppName = "TestApp"
            };
            var environment = new DeployEnvironment
            {
                Application = app, ApplicationId = app.Id, EnvName = "TestEnv"
            };

            _context.DeployEnvironments.Add(environment);
            _context.SaveChanges();

            var controller = new FeatureTogglesController(_context);

            var environmentToRemove = new DeleteEnvironmentModel
            {
                ApplicationId = environment.ApplicationId + 1,
                EnvName       = environment.EnvName
            };

            //act
            controller.RemoveEnvironment(environmentToRemove);

            //assert
            //throws InvalidOperationException
        }
示例#2
0
        public void DeleteEnvironment_EnvironmentIsDeleted_FeatureTogglesAreNotDeleted()
        {
            //arrange
            var app = new Application {
                Id = 1, AppName = "TestApp"
            };
            var environment = new DeployEnvironment
            {
                Application = app, ApplicationId = app.Id, EnvName = "TestEnv"
            };

            var featureToggle = new FeatureToggle {
                Id = 1
            };

            var controller = new FeatureTogglesController(_context);

            var firstFeatureStatus = new FeatureToggleStatus {
                Enabled = false, Id = 1, FeatureToggle = featureToggle, IsDeployed = false, Environment = environment, EnvironmentId = environment.Id
            };
            var secondFeatureStatus = new FeatureToggleStatus {
                Enabled = false, Id = 2, FeatureToggle = featureToggle, IsDeployed = false, Environment = environment, EnvironmentId = environment.Id
            };
            var thirdFeatureStatus = new FeatureToggleStatus {
                Enabled = false, Id = 3, FeatureToggle = featureToggle, IsDeployed = false, Environment = environment, EnvironmentId = environment.Id
            };

            featureToggle.FeatureToggleStatuses.AddRange(new List <FeatureToggleStatus>()
            {
                firstFeatureStatus, secondFeatureStatus, thirdFeatureStatus
            });

            _context.FeatureToggles.Add(featureToggle);
            _context.FeatureToggleStatuses.AddRange(firstFeatureStatus, secondFeatureStatus, thirdFeatureStatus);
            _context.Applications.Add(app);
            _context.DeployEnvironments.Add(environment);
            _context.SaveChanges();

            var environmentToRemove = new DeleteEnvironmentModel
            {
                ApplicationId = environment.ApplicationId,
                EnvName       = environment.EnvName
            };
            //act
            var result = controller.RemoveEnvironment(environmentToRemove);

            //assert
            result.Should().BeOfType <OkResult>();
            _context.DeployEnvironments.Count().Should().Be(0);
            _context.FeatureToggleStatuses.Count().Should().Be(0);
            _context.FeatureToggles.Count().Should().Be(1);
            _context.FeatureToggles.FirstOrDefault(x => x.Id == 1).FeatureToggleStatuses.Count().Should().Be(0);
        }
        public async Task EnvironmentIsDeleted_FeatureToggleStatusForThatEnvironmentIsDeletedForAllToggles()
        {
            //arrange
            var app = Application.Create("TestApp", "TestEnv", false);

            app.AddFeatureToggle("t1", "", "workItemId1");
            app.AddFeatureToggle("t2", "", "workItemId2");
            app.AddFeatureToggle("t3", "", "workItemId3");
            await _appRepository.AddAsync(app);


            var environmentToRemove = new DeleteEnvironmentModel
            {
                ApplicationId = app.Id,
                EnvName       = "TestEnv"
            };

            //act
            var result = await _featureToggleController.RemoveEnvironment(environmentToRemove);

            //assert
            result.Should().BeOfType <OkResult>();
            var savedApp = await _appRepository.FindByIdAsync(app.Id);

            savedApp.DeploymentEnvironments.Count.Should().Be(0);
            savedApp.FeatureToggles.Count(ft => ft.FeatureToggleStatuses.Count > 0).Should().Be(0);
        }