Exemplo n.º 1
0
 public GetDefinitionSpecs()
 {
     _fixture         = new Fixture();
     _readModelFacade = Substitute.For <IReadModelFacade>();
     _controller      = new TogglesController(_readModelFacade);
     _projectId       = _fixture.Create <Guid>();
 }
Exemplo n.º 2
0
        public void TestGetAll()
        {
            var mockOfITogglesLoader = new MockOfITogglesLoader(new List <Toggle>());
            var togglesController    = new TogglesController(mockOfITogglesLoader.Object, null, null, null, null);

            IEnumerable <Toggle> result = togglesController.GetAll();

            Assert.IsNotNull(result);
        }
Exemplo n.º 3
0
        public void TestGetByApplication()
        {
            var mockOfIToggleValuesLoader = new MockOfIToggleValuesLoader(new List <ToggleValue>());
            var togglesController         = new TogglesController(null, mockOfIToggleValuesLoader.Object, null, null, null);

            IActionResult result = togglesController.GetByApplication("TestApp", "1.0");

            Assert.IsInstanceOf <OkObjectResult>(result);
        }
Exemplo n.º 4
0
 public CreateToggleTests()
 {
     _mediator   = Substitute.For <IMediator>();
     _controller = new TogglesController(_mediator);
     _response   = new CreateTogglesResponse
     {
         Toggle = Toggle.CreateNew(EditorID.Parse("123"), "one", "two").ToView()
     };
 }
Exemplo n.º 5
0
        public void TestPut_ReturnsBadRequestResultWhenIdsAreNotEqual()
        {
            var toggle = new Toggle();
            var mockOfIUpdateToggleCommand = new MockOfIUpdateToggleCommand();
            var togglesController          = new TogglesController(null, null, null, mockOfIUpdateToggleCommand.Object, null);

            IActionResult result = togglesController.Put(Guid.NewGuid(), toggle);

            Assert.IsInstanceOf <BadRequestObjectResult>(result);
        }
Exemplo n.º 6
0
        public void TestPost()
        {
            var toggle = new Toggle();
            var mockOfICreateToggleCommand = new MockOfICreateToggleCommand();
            var togglesController          = new TogglesController(null, null, mockOfICreateToggleCommand.Object, null, null);

            IActionResult result = togglesController.Post(toggle);

            Assert.IsInstanceOf <CreatedResult>(result);
        }
Exemplo n.º 7
0
 public GetSingleToggleTests()
 {
     _mediator   = Substitute.For <IMediator>();
     _controller = new TogglesController(_mediator);
     _mediator
     .Send(Arg.Any <GetToggleRequest>())
     .Returns(new GetToggleResponse {
         Toggle = new ToggleView()
     });
 }
Exemplo n.º 8
0
        public void TestDelete()
        {
            var toggle = new Toggle();
            var mockOfIDeleteToggleCommand = new MockOfIDeleteToggleCommand();
            var togglesController          = new TogglesController(null, null, null, null, mockOfIDeleteToggleCommand.Object);

            IActionResult result = togglesController.Delete(toggle.Id);

            Assert.IsInstanceOf <NoContentResult>(result);
        }
Exemplo n.º 9
0
        public void TestPut_ReturnsBadRequestResultWhenModelStateIsInvalid()
        {
            var toggle = new Toggle();
            var mockOfIUpdateToggleCommand = new MockOfIUpdateToggleCommand();
            var togglesController          = new TogglesController(null, null, null, mockOfIUpdateToggleCommand.Object, null);

            this.ChangeModelStateToBeInvalid(togglesController);

            IActionResult result = togglesController.Put(toggle.Id, toggle);

            Assert.IsInstanceOf <BadRequestObjectResult>(result);
        }
Exemplo n.º 10
0
        public CreateToggleTests()
        {
            _response = new CreateTogglesResponse
            {
                Toggle = Toggle.CreateNew(EditorID.Parse("123"), "one", "two").ToView()
            };

            _mediator       = Substitute.For <IMediator>();
            _controller     = new TogglesController(_mediator);
            _controller.Url = Substitute.For <IUrlHelper>();
            _controller.Url.Action(Arg.Any <UrlActionContext>()).Returns("/api/toggles/id/" + _response.Toggle.ID);
        }
Exemplo n.º 11
0
        public void TestDelete_ReturnsBadRequestResultWhenEntityValidationException()
        {
            var toggle = new Toggle();
            var mockOfIDeleteToggleCommand = new MockOfIDeleteToggleCommand();

            mockOfIDeleteToggleCommand.SetupToThrowException(
                new EntityValidationException(""));
            var togglesController = new TogglesController(null, null, null, null, mockOfIDeleteToggleCommand.Object);

            IActionResult result = togglesController.Delete(toggle.Id);

            Assert.IsInstanceOf <BadRequestObjectResult>(result);
        }
Exemplo n.º 12
0
        public void TestGetById_ReturnsBadRequestResultWhenEntityValidationException()
        {
            Guid toggleId             = Guid.NewGuid();
            var  mockOfITogglesLoader = new MockOfITogglesLoader(new List <Toggle>());

            mockOfITogglesLoader.SetupToThrowException(
                new EntityValidationException(""));
            var togglesController = new TogglesController(mockOfITogglesLoader.Object, null, null, null, null);

            IActionResult result = togglesController.GetById(toggleId);

            Assert.IsInstanceOf <BadRequestObjectResult>(result);
        }
Exemplo n.º 13
0
 public TogglesControllerTest()
 {
     _toggle.AddOrUpdateCustomValue(new Client("Id2", "*"), false);
     _toggle.AddToWhitelist(new[] { new Client("id1", "1.1.1.1") });
     _queryHandler   = new Mock <IQueryHandler>();
     _commandHandler = new Mock <ICommandHandler>();
     _logger         = new Mock <ILogger <TogglesController> >();
     _controller     = new TogglesController(
         new ToggleClientParser(),
         _queryHandler.Object,
         _commandHandler.Object,
         _logger.Object);
 }
Exemplo n.º 14
0
        public void TestPost_ReturnsNotFoundResultWhenEntityNotFoundException()
        {
            var toggle = new Toggle();
            var mockOfICreateToggleCommand = new MockOfICreateToggleCommand();

            mockOfICreateToggleCommand.SetupToThrowException(
                new EntityNotFoundException(typeof(Toggle), toggle.Id.ToString()));
            var togglesController = new TogglesController(null, null, mockOfICreateToggleCommand.Object, null, null);

            IActionResult result = togglesController.Post(toggle);

            Assert.IsInstanceOf <NotFoundObjectResult>(result);
        }
Exemplo n.º 15
0
        public void TestGetById_ReturnsNotFoundResultWhenEntityNotFoundException()
        {
            Guid toggleId             = Guid.NewGuid();
            var  mockOfITogglesLoader = new MockOfITogglesLoader(new List <Toggle>());

            mockOfITogglesLoader.SetupToThrowException(
                new EntityNotFoundException(typeof(Toggle), toggleId.ToString()));
            var togglesController = new TogglesController(mockOfITogglesLoader.Object, null, null, null, null);

            IActionResult result = togglesController.GetById(toggleId);

            Assert.IsInstanceOf <NotFoundObjectResult>(result);
        }
Exemplo n.º 16
0
        public void TestGetById()
        {
            var toggle = new Toggle();
            var mockOfITogglesLoader = new MockOfITogglesLoader(
                new List <Toggle>()
            {
                toggle
            });
            var togglesController = new TogglesController(mockOfITogglesLoader.Object, null, null, null, null);

            IActionResult result = togglesController.GetById(toggle.Id);

            Assert.IsInstanceOf <OkObjectResult>(result);
        }
Exemplo n.º 17
0
 public GetAllTogglesTests()
 {
     _mediator   = Substitute.For <IMediator>();
     _controller = new TogglesController(_mediator);
 }