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

            var controller = new EnvironmentsController(mockedRepo.Object);

            var newEnv = new Environment()
            {
                Id = Guid.Parse("00000000-0000-0000-0000-000000000003")
            };

            mockedRepo.Setup(repo => repo.GetEnvironment(Guid.Parse("00000000-0000-0000-0000-000000000002"))).ReturnsAsync((Environment)null);

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

            var contentResult = result as NotFoundResult;

            Assert.NotNull(contentResult);
        }
Example #2
0
        public async Task Delete_WhenCalled_DeleteFailed_ReturnsServerError()
        {
            var mockedRepo = new Mock <IHomeRepository>();

            var controller = new EnvironmentsController(mockedRepo.Object);

            var newEnv = new Environment()
            {
                Id = Guid.Parse("00000000-0000-0000-0000-000000000003")
            };

            mockedRepo.Setup(repo => repo.GetEnvironment(Guid.Parse("00000000-0000-0000-0000-000000000003"))).ReturnsAsync(newEnv);
            mockedRepo.Setup(repo => repo.DeleteEnvironment(Guid.Parse("00000000-0000-0000-0000-000000000003"))).ReturnsAsync(false);

            var result = await controller.Delete("00000000-0000-0000-0000-000000000003");

            var contentResult = result as StatusCodeResult;

            Assert.NotNull(contentResult);
            Assert.Equal(StatusCodes.Status500InternalServerError, contentResult.StatusCode);
        }
Example #3
0
        public async Task Delete_WhenCalled_ReturnsOk()
        {
            var mockedRepo = new Mock <IHomeRepository>();

            var controller = new EnvironmentsController(mockedRepo.Object);

            var newEnv = new Environment()
            {
                Id = Guid.Parse("00000000-0000-0000-0000-000000000003")
            };

            mockedRepo.Setup(repo => repo.GetEnvironment(Guid.Parse("00000000-0000-0000-0000-000000000003"))).ReturnsAsync(newEnv);
            mockedRepo.Setup(repo => repo.DeleteEnvironment(Guid.Parse("00000000-0000-0000-0000-000000000003"))).ReturnsAsync(true);

            var result = await controller.Delete("00000000-0000-0000-0000-000000000003");

            var contentResult = (result as OkObjectResult).Value;

            Assert.NotNull(contentResult);
            Assert.Equal(newEnv, contentResult);
        }