public async Task RemoveFeatureToggle_FeatureToggleIsDeleted()
        {
            //arrange
            var app = Application.Create("TestApp", "DEV", false);

            app.AddFeatureToggle("t1", "", "workItemId1");
            var theToggle = app.FeatureToggles.Single();
            await _appRepository.AddAsync(app);

            //act
            var result = await _featureToggleController.RemoveFeatureToggle(theToggle.Id, app.Id);

            //assert
            result.Should().BeOfType <OkResult>();
            (await _appRepository.FindByIdAsync(app.Id)).FeatureToggles.Count.Should().Be(0);
        }
Ejemplo n.º 2
0
        public void RemoveFeatureToggle_FeatureToggleIsDeleted()
        {
            //arrange
            var data = new List <FeatureToggle>
            {
                new FeatureToggle {
                    Id = 1, ToggleName = "Test1"
                },
                new FeatureToggle {
                    Id = 2, ToggleName = "Test2"
                }
            };

            var mockSet = new Mock <DbSet <FeatureToggle> >();

            mockSet.As <IQueryable <FeatureToggle> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var options = new DbContextOptionsBuilder <TogglesContext>()
                          .Options;

            var mockContext = new Mock <TogglesContext>(options);

            mockContext
            .Setup(m => m.FeatureToggles.Remove(It.IsAny <FeatureToggle>())).Callback <FeatureToggle>((entity) => data.Remove(entity));
            var controller = new FeatureTogglesController(mockContext.Object);

            //act
            var result = controller.RemoveFeatureToggle(1);

            //assert
            result.Should().BeOfType <OkResult>();
            mockContext.Verify(s => s.FeatureToggles.Remove(It.IsAny <FeatureToggle>()), Times.Once);
            mockContext.Verify(s => s.SaveChanges(), Times.Once);
        }