Esempio n. 1
0
        public async Task It_Is_Possible_To_Invoke_The_Controller_GetCompleteById()
        {
            var serviceMock = new Mock <ICityService>();

            serviceMock.Setup(s => s.GetCompleteById(It.IsAny <Guid>())).Returns(Task.FromResult((CityDtoComplete)null));

            _controller = new CitiesController(serviceMock.Object);
            var result = await _controller.GetCompleteById(Guid.NewGuid());

            Assert.True(result is NotFoundResult);
        }
Esempio n. 2
0
        public async Task It_Is_Possible_To_Invoke_The_Controller_GetCompleteById()
        {
            var serviceMock = new Mock <ICityService>();

            serviceMock.Setup(s => s.GetCompleteById(It.IsAny <Guid>())).ReturnsAsync(
                new CityDtoComplete
            {
                Id   = Guid.NewGuid(),
                Name = "Passo Fundo"
            });

            _controller = new CitiesController(serviceMock.Object);
            _controller.ModelState.AddModelError("Id", "Formato inválido.");

            var result = await _controller.GetCompleteById(Guid.NewGuid());

            Assert.True(result is BadRequestObjectResult);
        }
        public async Task It_Is_Possible_To_Invoke_The_Controller_GetCompleteById()
        {
            var serviceMock = new Mock<ICityService>();

            serviceMock.Setup(s => s.GetCompleteById(It.IsAny<Guid>())).ReturnsAsync(
                new CityDtoComplete
                {
                    Id = Guid.NewGuid(),
                    Name = "Passo Fundo"
                });

            _controller = new CitiesController(serviceMock.Object);

            var result = await _controller.GetCompleteById(Guid.NewGuid());
            Assert.True(result is OkObjectResult);

            var resultValue = ((OkObjectResult)result).Value as CityDtoComplete;
            Assert.NotNull(resultValue);
            Assert.Equal("Passo Fundo", resultValue.Name);
        }