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

            serviceMock.Setup(m => m.Post(It.IsAny <MunicipioDtoCreate>())).ReturnsAsync(
                new MunicipioDtoCreateResult {
                Id       = Guid.NewGuid(),
                Nome     = "São Paulo",
                CreateAt = DateTime.UtcNow
            }
                );

            _controller = new MunicipiosController(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 municipioDtoCreate = new MunicipioDtoCreate {
                Nome    = "São Paulo",
                CodIBGE = 1
            };

            var result = await _controller.Post(municipioDtoCreate);

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

            serviceMock.Setup(m => m.Post(It.IsAny <MunicipioDtoCreate>())).ReturnsAsync(
                new MunicipioDtoCreateResult
            {
                Id       = Guid.NewGuid(),
                Cidade   = "Rio de Janeiro",
                CreateAt = DateTime.UtcNow
            }
                );

            _controller = new MunicipiosController(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 MunicipioDtoCreate
            {
                Cidade = "Rio de Janeiro"
            };

            var result = await _controller.Post(municipioDtoCreate);

            Assert.True(result is CreatedResult);
        }
        public async Task RetornoCreatedTest()
        {
            var serviceMock = new Mock <IMunicipioService>();

            serviceMock.Setup(m => m.Post(It.IsAny <MunicipioDtoCreate>())).ReturnsAsync(
                new MunicipioDtoCreateResult
            {
                Id       = Guid.NewGuid(),
                Nome     = "São Paulo",
                CreateAt = DateTime.UtcNow
            }
                );

            _controller = new MunicipiosController(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 MunicipioDtoCreate
            {
                Nome    = "São Paulo",
                CodIbge = 1
            };

            var result = await _controller.Post(municipioDtoCreate);

            Assert.True(result is CreatedResult);
        }
        public async Task E_Possivel_Invocar_a_Controller_Create()
        {
            var serviceMock = new Mock <IMunicipioService>();
            var Nome        = Faker.Address.City();
            var CodIBGE     = Faker.RandomNumber.Next(1000000, 9999999);
            var UfId        = Guid.NewGuid();

            serviceMock.Setup(c => c.Post(It.IsAny <MunicipioDtoCreate>())).ReturnsAsync(
                new MunicipioDtoCreateResult
            {
                Id       = Guid.NewGuid(),
                Nome     = Nome,
                CodIBGE  = CodIBGE,
                UfId     = UfId,
                CreateAt = DateTime.UtcNow
            }
                );

            _controller = new MunicipiosController(serviceMock.Object);
            _controller.ModelState.AddModelError("Name", "É 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 userDTOCreate = new MunicipioDtoCreate
            {
                Nome    = Nome,
                CodIBGE = CodIBGE,
                UfId    = UfId
            };

            var result = await _controller.Post(userDTOCreate);

            Assert.True(result is BadRequestObjectResult);
        }