Exemplo n.º 1
0
        public async Task Post_WhenCalled_AddFaild_ReturnsServerError()
        {
            var mockedRepo = new Mock <IHomeRepository>();

            var controller = new HomesController(mockedRepo.Object);

            var newHome = new Home()
            {
                Name = "test_home_1",
                Id   = Guid.Parse("00000000-0000-0000-0000-000000000003")
            };

            mockedRepo.Setup(repo => repo.AddHome(newHome)).ReturnsAsync((Home)null);

            var result = await controller.Post(newHome);

            var contentResult = (result as StatusCodeResult).StatusCode;

            Assert.Equal(StatusCodes.Status500InternalServerError, contentResult);
        }
Exemplo n.º 2
0
        public async Task Post_WhenCalled_ReturnsOk()
        {
            var mockedRepo = new Mock <IHomeRepository>();

            var controller = new HomesController(mockedRepo.Object);

            var newHome = new Home()
            {
                Name = "test_home_1",
                Id   = Guid.Parse("00000000-0000-0000-0000-000000000003")
            };

            mockedRepo.Setup(repo => repo.AddHome(newHome)).ReturnsAsync(newHome);

            var result = await controller.Post(newHome);

            var contentResult = (result as OkObjectResult).Value;

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