Beispiel #1
0
        public async Task E_Possivel_Invocar_a_Controller_Create()
        {
            var serviceMock = new Mock <ICepService>();

            serviceMock.Setup(m => m.Post(It.IsAny <CepDtoCreate>())).ReturnsAsync(
                new CepDtoCreateResult {
                Id         = Guid.NewGuid(),
                Logradouro = "Teste de Rua",
                CreateAt   = DateTime.UtcNow
            }
                );

            _controller = new CepsController(serviceMock.Object);

            Mock <IUrlHelper> url = new Mock <IUrlHelper>();

            url.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns("http://localhost:5000");
            _controller.Url = url.Object;

            var municipioDtoCreate = new CepDtoCreate {
                Logradouro = "Teste de Rua",
                Numero     = ""
            };

            var result = await _controller.Post(municipioDtoCreate);

            Assert.True(result is CreatedResult);
        }
Beispiel #2
0
        public async Task ReturnBadRequestTest()
        {
            var serviceMock = new Mock <ICepService>();

            serviceMock.Setup(m => m.Post(It.IsAny <CepDtoCreate>())).ReturnsAsync(
                new CepDtoCreateResult
            {
                Id         = Guid.NewGuid(),
                Logradouro = "Teste de Rua",
                CreateAt   = DateTime.UtcNow
            }
                );

            _controller = new CepsController(serviceMock.Object);
            _controller.ModelState.AddModelError("Nome", "É um Campo Obrigatório");

            Mock <IUrlHelper> url = new Mock <IUrlHelper>();

            url.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns("http://localhost:5000");
            _controller.Url = url.Object;

            var cepDtoCreate = new CepDtoCreate
            {
                Logradouro = "Teste de Rua",
                Numero     = ""
            };

            var result = await _controller.Post(cepDtoCreate);

            Assert.True(result is BadRequestObjectResult);
        }
Beispiel #3
0
        public async Task E_Possivel_Invocar_a_Controller_Create()
        {
            var serviceMock = new Mock <ICepService>();
            var Cep         = Faker.RandomNumber.Next(1, 10000).ToString();
            var Logradouro  = Faker.Address.StreetName();
            var Numero      = Faker.RandomNumber.Next(1, 10000).ToString();
            var MunicipioId = Guid.NewGuid();

            serviceMock.Setup(c => c.Post(It.IsAny <CepDtoCreate>())).ReturnsAsync(
                new CepDtoCreateResult
            {
                Id          = Guid.NewGuid(),
                Cep         = Cep,
                Logradouro  = Logradouro,
                Numero      = Numero,
                MunicipioId = MunicipioId,
                CreateAt    = DateTime.UtcNow
            }
                );

            _controller = new CepsController(serviceMock.Object);


            Mock <IUrlHelper> url = new Mock <IUrlHelper>();

            url.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns("http://localhost:5000");
            _controller.Url = url.Object;

            var municipioDTOCreate = new CepDtoCreate
            {
                Cep         = Cep,
                Logradouro  = Logradouro,
                Numero      = Numero,
                MunicipioId = MunicipioId
            };

            var result = await _controller.Post(municipioDTOCreate);

            Assert.True(result is CreatedResult);
        }