コード例 #1
0
        public async Task Delete_DeleteResident_DeleteResidentAndReturnsOKResult()
        {
            // Arrange
            var fakeResident = new Resident
            {
                Name      = "John Cena",
                Email     = "*****@*****.**",
                Block     = "B",
                Apartment = "301",
                Cpf       = "3243141431"
            };

            _mockResidentRepository.Setup(repo => repo.GetAsync(It.IsAny <int>())).ReturnsAsync(fakeResident);;

            var controller = new ResidentsController(_mockResidentRepository.Object,
                                                     _mockUoW.Object, _mapper);

            // Act
            var residentViewModel = new ResidentViewModel {
                Name = "John Cena"
            };
            var deleteResidentResult = await controller.Delete(2);

            // assert
            Assert.IsInstanceOf <OkObjectResult>(deleteResidentResult);
            var okResult = deleteResidentResult as OkObjectResult;

            Assert.IsInstanceOf <ResidentViewModel>(okResult.Value);
            Assert.AreEqual(true, fakeResident.Deleted);
        }
コード例 #2
0
        public async Task Delete_DeleteNullResident_ReturnsBadRequest()
        {
            // Arrange
            _mockResidentRepository.Setup(repo => repo.GetAsync(It.IsAny <int>())).ReturnsAsync((Resident)null);;

            var controller = new ResidentsController(_mockResidentRepository.Object,
                                                     _mockUoW.Object, _mapper);

            // Act
            var residentViewModel = new ResidentViewModel {
                Name = "John Cena"
            };
            var deleteResidentResult = await controller.Delete(2);

            // assert
            Assert.IsInstanceOf <BadRequestObjectResult>(deleteResidentResult);
        }