Example #1
0
        public async Task GetById_WhenCalled_ReturnsOkResult()
        {
            var mockedRepo = new Mock <IHomeRepository>();

            var envs = new List <Environment>
            {
                new Environment()
                {
                    Id = Guid.Parse("00000000-0000-0000-0000-000000000001")
                },
                new Environment()
                {
                    Id = Guid.Parse("00000000-0000-0000-0000-000000000002")
                }
            };

            mockedRepo.Setup(repo => repo.GetEnvironment(Guid.Parse("00000000-0000-0000-0000-000000000001"))).ReturnsAsync(envs[0]);
            mockedRepo.Setup(repo => repo.GetEnvironment(Guid.Parse("00000000-0000-0000-0000-000000000002"))).ReturnsAsync(envs[1]);

            var controller = new EnvironmentsController(mockedRepo.Object);
            var result     = await controller.Get("00000000-0000-0000-0000-000000000001");

            var contentResult = (result as OkObjectResult).Value as Environment;

            Assert.NotNull(contentResult);
            Assert.Equal(contentResult, envs[0]);

            result = await controller.Get("00000000-0000-0000-0000-000000000002");

            contentResult = (result as OkObjectResult).Value as Environment;

            Assert.NotNull(result);
            Assert.Equal(contentResult, envs[1]);
        }
Example #2
0
        public async Task GetById_WhenCalled_UnknownID_ReturnsNotFoundResult()
        {
            var mockedRepo = new Mock <IHomeRepository>();

            var envs = new List <Environment>
            {
                new Environment()
                {
                    Id = Guid.Parse("00000000-0000-0000-0000-000000000001")
                },
                new Environment()
                {
                    Id = Guid.Parse("00000000-0000-0000-0000-000000000002")
                }
            };

            mockedRepo.Setup(repo => repo.GetEnvironment(Guid.Parse("00000000-0000-0000-0000-000000000001"))).ReturnsAsync(envs[0]);
            mockedRepo.Setup(repo => repo.GetEnvironment(Guid.Parse("00000000-0000-0000-0000-000000000002"))).ReturnsAsync(envs[1]);
            mockedRepo.Setup(repo => repo.GetEnvironment(Guid.Parse("00000000-0000-0000-0000-000000000003"))).ReturnsAsync((Environment)null);

            var controller = new EnvironmentsController(mockedRepo.Object);
            var result     = await controller.Get("00000000-0000-0000-0000-000000000003");

            var contentResult = result as NotFoundResult;

            Assert.NotNull(contentResult);
        }
Example #3
0
            public void Returns_404_For_An_Invalid_Url()
            {
                var environmentsQuerySelector = Substitute.For <IIndex <ApiMode, IEnvironmentService> >();
                var environmentsQuery         = Substitute.For <IEnvironmentService>();

                environmentsQuery.Get(new Uri(TestUriString)).ReturnsForAnyArgs(new Environment());
                environmentsQuerySelector[ApiMode.Demo].ReturnsForAnyArgs(environmentsQuery);

                var controller = new EnvironmentsController(environmentsQuerySelector)
                {
                    ControllerContext = new HttpControllerContext
                    {
                        Request = new HttpRequestMessage()
                    }
                };

                controller.ControllerContext.Request.Properties.Add("x-api-mode", ApiMode.Demo);

                try
                {
                    controller.Get("Not a valid url");
                }
                catch (HttpResponseException ex)
                {
                    ex.Response.StatusCode.ShouldBe(HttpStatusCode.NotFound);
                }
            }
Example #4
0
            public void Returns_A_Valid_Demo_Response()
            {
                var environmentsQuerySelector = Substitute.For <IIndex <ApiMode, IEnvironmentService> >();

                environmentsQuerySelector[ApiMode.Demo].Returns(new EnvironmentServiceStub());

                var controller = new EnvironmentsController(environmentsQuerySelector)
                {
                    ControllerContext = new HttpControllerContext
                    {
                        Request = new HttpRequestMessage()
                    }
                };

                controller.ControllerContext.Request.Properties.Add("x-api-mode", ApiMode.Demo);
                var response = controller.Get();

                response.ShouldNotBeSameAs(null);
            }
Example #5
0
            public void Returns_An_Environment_For_A_Valid_Url()
            {
                var environmentsQuerySelector = Substitute.For <IIndex <ApiMode, IEnvironmentService> >();
                var environmentsQuery         = Substitute.For <IEnvironmentService>();

                environmentsQuery.Get(new Uri(TestUriString)).ReturnsForAnyArgs(new Environment());
                environmentsQuerySelector[ApiMode.Demo].ReturnsForAnyArgs(environmentsQuery);

                var controller = new EnvironmentsController(environmentsQuerySelector)
                {
                    ControllerContext = new HttpControllerContext
                    {
                        Request = new HttpRequestMessage()
                    }
                };

                controller.ControllerContext.Request.Properties.Add("x-api-mode", ApiMode.Demo);

                var response = controller.Get(TestUriString);

                Assert.IsNotNull(response);
            }