Beispiel #1
0
        public async Task E_Possivel_Invocar_a_Controller_GetAll()
        {
            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.GetAll()).ReturnsAsync(
                new List <MunicipioDto>
            {
                new MunicipioDto
                {
                    Id      = Guid.NewGuid(),
                    Nome    = Nome,
                    CodIBGE = codIBGE,
                    UfId    = UfId
                },
                new MunicipioDto
                {
                    Id      = Guid.NewGuid(),
                    Nome    = Nome,
                    CodIBGE = codIBGE,
                    UfId    = UfId
                }
            }
                );

            _controller = new MunicipiosController(serviceMock.Object);

            var result = await _controller.GetAll();

            Assert.True(result is OkObjectResult);
        }
        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_GetAll()
        {
            var serviceMock = new Mock <IMunicipioService>();

            serviceMock.Setup(m => m.GetAll()).ReturnsAsync(
                new List <MunicipioDto>
            {
                new MunicipioDto
                {
                    Id     = Guid.NewGuid(),
                    Cidade = "Rio de Janeiro",
                },
                new MunicipioDto
                {
                    Id     = Guid.NewGuid(),
                    Cidade = "Rio de Janeiro",
                }
            }
                );

            _controller = new MunicipiosController(serviceMock.Object);
            _controller.ModelState.AddModelError("Id", "Formato Invalido");

            var result = await _controller.GetAll();

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

            serviceMock.Setup(m => m.GetAll()).ReturnsAsync(
                new List <MunicipioDto>
            {
                new MunicipioDto
                {
                    Id   = Guid.NewGuid(),
                    Nome = "São Paulo",
                },
                new MunicipioDto
                {
                    Id   = Guid.NewGuid(),
                    Nome = "Limeira",
                }
            }
                );

            _controller = new MunicipiosController(serviceMock.Object);
            var result = await _controller.GetAll();

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

            serviceMock.Setup(m => m.GetAll())
            .ReturnsAsync(
                new List <MunicipioDto>
            {
                new MunicipioDto
                {
                    Id   = Guid.NewGuid(),
                    Nome = "São Paulo",
                },
                new MunicipioDto
                {
                    Id   = Guid.NewGuid(),
                    Nome = "Limeira,"
                }
            }
                );

            _controller = new MunicipiosController(serviceMock.Object);
            _controller.ModelState.AddModelError("Id", "Formato invalido");

            var result = await _controller.GetAll();

            Assert.True(result is BadRequestObjectResult);
        }
Beispiel #6
0
        public static Result getListaMunicipios(string valorBuscado, int registroPartida, int totalAExtraer, int usuarioId)
        {
            Result r = ValidateSession.validarSession(usuarioId, HttpContext.Current.Session["usuarioId"]);

            if (r.error != "")
            {
                return(r);
            }
            int totalRegistros             = 0;
            List <MunicipiosViewModel> lst = new List <MunicipiosViewModel>();

            try
            {
                MunicipiosController mc = new MunicipiosController();
                lst            = mc.getListaMunicipios(valorBuscado);
                totalRegistros = lst.Count();
                totalAExtraer  = (lst.Count() - registroPartida) < totalAExtraer ? (lst.Count() - registroPartida) : totalAExtraer;
            }
            catch (Exception e)
            {
                return(new Result()
                {
                    error = e.Message, id = 0, tipoAlerta = "warning"
                });
            }
            return(new Result()
            {
                error = "", getCadena = new JavaScriptSerializer().Serialize(lst.GetRange(registroPartida, totalAExtraer)), totalRegistros = totalRegistros
            });
        }
Beispiel #7
0
        public async Task RetornoBadRequestTest()
        {
            var serviceMock = new Mock <IMunicipioService>();

            serviceMock.Setup(m => m.Put(It.IsAny <MunicipioDtoUpdate>())).ReturnsAsync(
                new MunicipioDtoUpdateResult
            {
                Id       = Guid.NewGuid(),
                Nome     = "São Paulo",
                UpdateAt = DateTime.UtcNow
            }
                );

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

            var municipioDtoUpdate = new MunicipioDtoUpdate
            {
                Nome    = "São Paulo",
                CodIbge = 1
            };

            var result = await _controller.Put(municipioDtoUpdate);

            Assert.True(result is BadRequestObjectResult);
        }
Beispiel #8
0
        public static Result guardar(int id, int departamentoId, int usuarioId, string nombre, string codigoDane)
        {
            Result r = ValidateSession.validarSession(usuarioId, HttpContext.Current.Session["usuarioId"]);

            if (r.error != "")
            {
                return(r);
            }
            Municipios objEntity = new Municipios();

            objEntity.id             = id;
            objEntity.departamentoId = departamentoId;
            objEntity.usuarioId      = usuarioId;
            objEntity.nombre         = nombre;
            objEntity.codigoDane     = codigoDane;
            try
            {
                MunicipiosController mc = new MunicipiosController();
                return(mc.guardarMunicipios(objEntity));
            }
            catch (Exception ex)
            {
                return(new Result()
                {
                    error = ex.Message, id = 0, tipoAlerta = "warning"
                });
            }
        }
Beispiel #9
0
        public async Task E_Possivel_Invocar_a_Controller_Update()
        {
            var serviceMock = new Mock <IMunicipioService>();

            serviceMock.Setup(m => m.Put(It.IsAny <MunicipioDtoUpdate>())).ReturnsAsync(
                new MunicipioDtoUpdateResult
            {
                Id       = Guid.NewGuid(),
                Cidade   = "Rio de Janeiro",
                UpdateAt = DateTime.UtcNow
            }
                );

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

            var municipioDtoUpdate = new MunicipioDtoUpdate
            {
                Cidade = "Rio de Janeiro"
            };

            var result = await _controller.Put(municipioDtoUpdate);

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

            serviceMock.Setup(m => m.Put(It.IsAny <MunicipioDtoUpdate>())).ReturnsAsync(
                new MunicipioDtoUpdateResult
            {
                Id       = Guid.NewGuid(),
                Nome     = "São Paulo",
                UpdateAt = DateTime.UtcNow
            }
                );

            _controller = new MunicipiosController(serviceMock.Object);

            var municipioDtoUpdate = new MunicipioDtoUpdate
            {
                Nome    = "São Paulo",
                CodIBGE = 1
            };

            var result = await _controller.Put(municipioDtoUpdate);

            Assert.True(result is OkObjectResult);
        }
Beispiel #11
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);
        }
Beispiel #12
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 #13
0
        public async Task E_Possivel_Invocar_a_Controller_GetCompleteByIBGE()
        {
            var serviceMock = new Mock <IMunicipioService>();

            serviceMock.Setup(m => m.GetCompleteByIBGE(It.IsAny <int>())).Returns(Task.FromResult((MunicipioDtoCompleto)null));

            _controller = new MunicipiosController(serviceMock.Object);
            var result = await _controller.GetCompleteByIBGE(1);

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

            serviceMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(Task.FromResult((MunicipioDto)null));

            _controller = new MunicipiosController(serviceMock.Object);
            var result = await _controller.Get(Guid.NewGuid());

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

            serviceMock.Setup(m => m.Delete(It.IsAny <Guid>())).ReturnsAsync(true);

            _controller = new MunicipiosController(serviceMock.Object);

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

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

            serviceMock.Setup(m => m.Delete(It.IsAny <Guid>())).ReturnsAsync(true);

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

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

            Assert.True(result is BadRequestObjectResult);
        }
Beispiel #17
0
        public async Task E_Possivel_Invocar_a_Controller_Get_Complete_By_IBGE()
        {
            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.GetCompleteByIBGE(It.IsAny <int>())).Returns(Task.FromResult((MunicipioDtoCompleto)null));

            _controller = new MunicipiosController(serviceMock.Object);

            var result = await _controller.GetCompleteByIBGE(1);

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

            serviceMock.Setup(m => m.GetCompleteById(It.IsAny <Guid>())).ReturnsAsync(
                new MunicipioDtoCompleto {
                Id   = Guid.NewGuid(),
                Nome = "São Paulo"
            }
                );

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

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

            serviceMock.Setup(m => m.GetCompleteByIBGE(It.IsAny <int>())).ReturnsAsync(
                new MunicipioDtoCompleto {
                Id   = Guid.NewGuid(),
                Nome = "São Paulo"
            }
                );

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

            var result = await _controller.GetCompleteByIBGE(1);

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

            serviceMock.Setup(m => m.Get(It.IsAny <Guid>())).ReturnsAsync(
                new MunicipioDto
            {
                Id   = Guid.NewGuid(),
                Nome = "São Paulo",
            }
                );

            _controller = new MunicipiosController(serviceMock.Object);

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

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

            serviceMock.Setup(m => m.Get(It.IsAny <Guid>())).ReturnsAsync(
                new MunicipioDto
            {
                Id     = Guid.NewGuid(),
                Cidade = "Rio de Janeiro",
            }
                );

            _controller = new MunicipiosController(serviceMock.Object);

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

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

            serviceMock.Setup(m => m.Get(It.IsAny <Guid>())).ReturnsAsync(
                new MunicipioDto
            {
                Id   = Guid.NewGuid(),
                Nome = "São Paulo",
            }
                );

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

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

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

            serviceMock.Setup(m => m.GetCompleteByIBGE(It.IsAny <int>()))
            .ReturnsAsync(
                new MunicipioDtoCompleto
            {
                Id   = Guid.NewGuid(),
                Nome = "São Paulo",
            }
                );

            _controller = new MunicipiosController(serviceMock.Object);

            var result = await _controller.GetCompleteByIBGE(1);

            Assert.True(result is OkObjectResult);
        }
Beispiel #24
0
        public static Result eliminar(int id, int usuarioId)
        {
            Result r = ValidateSession.validarSession(usuarioId, HttpContext.Current.Session["usuarioId"]);

            if (r.error != "")
            {
                return(r);
            }

            try
            {
                MunicipiosController mc = new MunicipiosController();
                return(mc.eliminarMunicipios(id, usuarioId));
            }
            catch (Exception ex)
            {
                return(new Result()
                {
                    error = ex.Message, id = 0, tipoAlerta = "warning"
                });
            }
        }
        public async Task E_Possivel_Invocar_a_Controller_Update()
        {
            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.Put(It.IsAny <MunicipioDtoUpdate>())).ReturnsAsync(
                new MunicipioDtoUpdateResult
            {
                Id       = Guid.NewGuid(),
                Nome     = Nome,
                CodIBGE  = CodIBGE,
                UfId     = UfId,
                UpdateAt = 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 municipioDtoUpdate = new MunicipioDtoUpdate
            {
                Nome    = Nome,
                CodIBGE = CodIBGE,
                UfId    = UfId
            };

            var result = await _controller.Put(municipioDtoUpdate);

            Assert.True(result is OkObjectResult);
        }
        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);
        }
        public XmlElement ListarMunicipio()
        {
            XmlDocument xdoc = null;

            try
            {
                MunicipiosController controle = new MunicipiosController();
                xdoc = controle.ListarMunicipiosXML();
            }
            catch (Exception ex)
            {
                xdoc = new XmlDocument();
                {
                    XmlElement raiz = xdoc.CreateElement("Erro");
                    {
                        XmlElement erro = xdoc.CreateElement("Mensagem");
                        erro.InnerText = ex.Message;
                        raiz.AppendChild(erro);
                    }
                    xdoc.AppendChild(raiz);
                }
            }
            return(xdoc.DocumentElement);
        }
Beispiel #28
0
        public async Task E_Possivel_Invocar_a_Controller_Get_Complete_By_IBGE()
        {
            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.GetCompleteByIBGE(It.IsAny <int>())).ReturnsAsync(
                new MunicipioDtoCompleto
            {
                Id      = Guid.NewGuid(),
                Nome    = Nome,
                CodIBGE = codIBGE,
                UfId    = UfId
            }
                );

            _controller = new MunicipiosController(serviceMock.Object);
            _controller.ModelState.AddModelError("Id", "Formato invalido");

            var result = await _controller.GetCompleteByIBGE(1);

            Assert.True(result is BadRequestObjectResult);
        }