public void Given_ValidUserIdAndInvalidAnuncioId_When_EliminarAsync_Then_ReturnsBadRequestResult()
        {
            //Arrange
            _anuncioServiceMock.Setup(x => x.EliminarAsync(InvalidAnuncioId)).Returns(GetEliminarResponseAsync(false));
            _usuarioServiceMock.Setup(x => x.ConsultarUsuarioAsync(ValidOwnerUserId)).Returns(GetUsuarioResponseAsync(true));

            //Act
            var anuncioController = new AnuncioController(_anuncioServiceMock.Object, _usuarioServiceMock.Object);
            var response          = anuncioController.Eliminar(ValidOwnerUserId, InvalidAnuncioId);

            //Assert
            var result = response.Result as ObjectResult;

            Assert.IsTrue(result.StatusCode == StatusCodes.Status400BadRequest);
        }
        public void Given_InvalidUserIdAndValidEdicionAnuncioRequest_When_EditarAsync_Then_ReturnsForbidResult()
        {
            //Arrange
            _anuncioServiceMock.Setup(x => x.EditarAsync(InvalidOwnerUserId, ValidEdicionAnuncioRequest)).Returns(GetEditarResponseAsync(false));
            _usuarioServiceMock.Setup(x => x.ConsultarUsuarioAsync(InvalidOwnerUserId)).Returns(GetUsuarioResponseAsync(false));

            //Act
            var anuncioController = new AnuncioController(_anuncioServiceMock.Object, _usuarioServiceMock.Object);
            var response          = anuncioController.Editar(InvalidOwnerUserId, ValidEdicionAnuncioRequest);

            //Assert
            var result = response.Result as ObjectResult;

            Assert.IsTrue(result.StatusCode == StatusCodes.Status403Forbidden);
            Assert.IsNotNull(result.Value);
        }
        public void Given_ValidUserIdAndValidAnuncioId_When_EliminarAsync_Then_ReturnsBaseServiceResponseWithSuccess()
        {
            //Arrange
            _anuncioServiceMock.Setup(x => x.EliminarAsync(ValidAnuncioId)).Returns(GetEliminarResponseAsync(true));
            _usuarioServiceMock.Setup(x => x.ConsultarUsuarioAsync(ValidOwnerUserId)).Returns(GetUsuarioResponseAsync(true));

            //Act
            var anuncioController = new AnuncioController(_anuncioServiceMock.Object, _usuarioServiceMock.Object);
            var response          = anuncioController.Eliminar(ValidOwnerUserId, ValidAnuncioId);

            //Assert
            var result = response.Result as OkObjectResult;
            var baseServiceResponse = result.Value as BaseServiceResponse <bool>;

            Assert.IsTrue(baseServiceResponse.Success);
            Assert.IsTrue(baseServiceResponse.Data);
        }
        public void Given_ValidUserId_When_ConsultarPorUsuarioAsync_Then_ReturnsBaseServiceResponseWithSuccess()
        {
            //Arrange
            _anuncioServiceMock.Setup(x => x.ConsultarPorUsuarioAsync(ValidOwnerUserId)).Returns(GetAnuncioResponseAsync(true));
            _usuarioServiceMock.Setup(x => x.ConsultarUsuarioAsync(ValidOwnerUserId)).Returns(GetUsuarioResponseAsync(true));

            //Act
            var anuncioController = new AnuncioController(_anuncioServiceMock.Object, _usuarioServiceMock.Object);
            var response          = anuncioController.ConsultarAnunciosPorIdUsuario(ValidOwnerUserId);

            //Assert
            var result = response.Result as OkObjectResult;
            var baseServiceResponse = result.Value as BaseServiceResponse <IEnumerable <AnuncioResponse> >;

            Assert.IsTrue(baseServiceResponse.Success);
            Assert.IsNotNull(baseServiceResponse.Data);
        }
        public void Given_ValidUserIdAndValidCreacionAnuncioRequest_When_CrearAsync_Then_ReturnsBaseServiceResponseWithSuccess()
        {
            //Arrange
            _anuncioServiceMock.Setup(x => x.CrearAsync(ValidOwnerUserId, ValidCreacionAnuncioRequest)).Returns(GetCrearResponseAsync(true));
            _usuarioServiceMock.Setup(x => x.ConsultarUsuarioAsync(ValidOwnerUserId)).Returns(GetUsuarioResponseAsync(true));

            //Act
            var anuncioController = new AnuncioController(_anuncioServiceMock.Object, _usuarioServiceMock.Object);
            var response          = anuncioController.Crear(ValidOwnerUserId, ValidCreacionAnuncioRequest);

            //Assert
            var result = response.Result as CreatedResult;
            var baseServiceResponse = result.Value as BaseServiceResponse <int>;

            Assert.IsTrue(baseServiceResponse.Success);
            Assert.IsNotNull(baseServiceResponse.Data);
            Assert.IsTrue(result.StatusCode == StatusCodes.Status201Created);
        }
Beispiel #6
0
        public static void Initialize(TestContext testContext)
        {
            // Arrange
            var mockServiceIAnuncio = new Mock <IAnuncioService>();
            var mockServiceIImovel  = new Mock <IImovelService>();
            var mockServiceIPessoa  = new Mock <IPessoaService>();

            IMapper mapper = new MapperConfiguration(cfg =>
                                                     cfg.AddProfile(new AnuncioProfile())).CreateMapper();

            // mock para Anuncio service
            mockServiceIAnuncio.Setup(service => service.ObterTodos())
            .Returns(GetTestAnuncio());
            mockServiceIAnuncio.Setup(service => service.Buscar(1))
            .Returns(GetTargetAnuncio());
            mockServiceIAnuncio.Setup(service => service.Alterar(It.IsAny <Anuncio>()))
            .Verifiable();
            mockServiceIAnuncio.Setup(service => service.Inserir(It.IsAny <Anuncio>()))
            .Verifiable();

            // mock para Imovel Service
            mockServiceIImovel.Setup(service => service.ObterTodos())
            .Returns(GetTestImovel());
            mockServiceIImovel.Setup(service => service.Buscar(1))
            .Returns(GetTargetImovel());
            mockServiceIImovel.Setup(service => service.Alterar(It.IsAny <Imovel>()))
            .Verifiable();
            mockServiceIImovel.Setup(service => service.Inserir(It.IsAny <Imovel>()))
            .Verifiable();

            //mock para pessoa service
            mockServiceIPessoa.Setup(service => service.ObterTodos())
            .Returns(GetTestPessoa());
            mockServiceIPessoa.Setup(service => service.Buscar(1))
            .Returns(GetTargetPessoa());
            mockServiceIPessoa.Setup(service => service.Alterar(It.IsAny <Pessoa>()))
            .Verifiable();
            mockServiceIPessoa.Setup(service => service.Inserir(It.IsAny <Pessoa>()))
            .Verifiable();

            controller = new AnuncioController(mockServiceIAnuncio.Object, mockServiceIImovel.Object, mockServiceIPessoa.Object, mapper);
        }