예제 #1
0
        public void ValidarTamanhoStringTest()
        {
            string teste = "teste";

            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarTamanhoString(teste, 3, 10, "Não esta dentro do Tamanho Paramentrizado", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarTamanhoString(teste, 10, 20, "Não esta dentro do Tamanho Paramentrizado", this.GetType())));
        }
예제 #2
0
        public void ValidarRegexMatchTest()
        {
            var emailRegex = @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z";

            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarRegexMatch("www.mps.com.br", emailRegex, "E-mail não é valido", this.GetType())));
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarRegexMatch("*****@*****.**", emailRegex, "E-mail não é valido", this.GetType())));
        }
예제 #3
0
 public void ValidarStringVaziaOuNulaTest()
 {
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarStringVaziaOuNula(string.Empty, "String não pode ser empty", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarStringVaziaOuNula(null, "String não pode ser null", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarStringVaziaOuNula("", "String não pode ser vazia", this.GetType())));
     Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarStringVaziaOuNula("string", "String não pode ser vazia", this.GetType())));
 }
예제 #4
0
        public static string Decriptografar(string key, string texto)
        {
            byte[]       resultado;
            UTF8Encoding utf8 = new UTF8Encoding();

            using (TripleDESCryptoServiceProvider algoritmoTDES = RetornaTdes(key))
            {
                try
                {
                    byte[] dadoParaDecriptografar = Convert.FromBase64String(texto);
                    using (ICryptoTransform decriptacao = algoritmoTDES.CreateDecryptor())
                    {
                        resultado = decriptacao.TransformFinalBlock(dadoParaDecriptografar, 0, dadoParaDecriptografar.Length);
                    }
                }
                catch (FormatException e)
                {
                    ValidacoesDominio.IsValid(new NotificacoesDominio("CriptografiaDecriptografar", e.Message, e.GetType(), true));
                    return(texto);
                }
                catch (CryptographicException e)
                {
                    ValidacoesDominio.IsValid(new NotificacoesDominio("CriptografiaDecriptografar", e.Message, e.GetType(), true));
                    return(texto);
                }
            }

            return(utf8.GetString(resultado));
        }
예제 #5
0
        public void ValidarDataMinimaTest()
        {
            string data = "21/07/2017";

            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarDataMinima(data.ToDateTime(), "Validar Data", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarDataMinima(null, "Validar Data", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarDataMinima(DateTime.MinValue, "Validar Data", this.GetType())));
        }
예제 #6
0
        public void ValidarDataTest()
        {
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarData("2017-07-21", "Validar Data", this.GetType())));
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarData("21-07-2017", "Validar Data", this.GetType())));
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarData("21/07/2017", "Validar Data", this.GetType())));

            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarData("07/21/2017", "Validar Data", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarData("2017-21-07", "Validar Data", this.GetType())));
        }
예제 #7
0
        public void ValidarStringSomenteEspacoEspeciaisTest()
        {
            string Descricao = "Nomes";

            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarStringSemEspacoEspeciais(Descricao, "Validar String sem caracteres especiais", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarStringSemEspacoEspeciais("Nome Espaco", "Validar String sem caracteres especiais", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarStringSemEspacoEspeciais("Nome_Espaço", "Validar String sem caracteres especiais", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarStringSemEspacoEspeciais("Nomefunção", "Validar String sem caracteres especiais", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarStringSemEspacoEspeciais("Nome@", "Validar String sem caracteres especiais", this.GetType())));
        }
예제 #8
0
 public void ValidarCpfTest()
 {
     Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCpf("764.181.250-37", "Validar CPF", this.GetType())));
     Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCpf("76418125037", "Validar CPF", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCpf("764.181.250-38", "Validar CPF", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCpf("76418125038", "Validar CPF", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCpf("000.000.000-00", "Validar CPF", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCpf("111.111.111-11", "Validar CPF", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCpf("222.222.222-22", "Validar CPF", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCpf("333.333.333-33", "Validar CPF", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCpf("444.444.444-44", "Validar CPF", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCpf("555.555.555-55", "Validar CPF", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCpf("666.666.666-66", "Validar CPF", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCpf("777.777.777-77", "Validar CPF", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCpf("888.888.888-88", "Validar CPF", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCpf("999.999.999-99", "Validar CPF", this.GetType())));
 }
예제 #9
0
 public void ValidarCnpjTest()
 {
     Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCnpj("28.795.045/0001-19", "Validar CNPJ", this.GetType())));
     Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCnpj("28795045000119", "Validar CNPJ", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCnpj("28.795.045/0001-18", "Validar CNPJ", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCnpj("28795045000118", "Validar CNPJ", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCnpj("00.000.000/0000-00", "Validar CNPJ", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCnpj("11.111.111/1111-11", "Validar CNPJ", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCnpj("22.222.222/2222-22", "Validar CNPJ", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCnpj("33.333.333/3333-33", "Validar CNPJ", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCnpj("44.444.444/4444-44", "Validar CNPJ", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCnpj("55.555.555/5555-55", "Validar CNPJ", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCnpj("66.666.666/6666-66", "Validar CNPJ", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCnpj("77.777.777/7777-77", "Validar CNPJ", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCnpj("88.888.888/8888-88", "Validar CNPJ", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarCnpj("99.999.999/9999-99", "Validar CNPJ", this.GetType())));
 }
예제 #10
0
        public void ValidarDataInicioDataFimTest()
        {
            string dataInicio = "01-07-2017";
            string dataFim    = "21-07-2017";

            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarDataInicioDataFim(dataInicio.ToDateTime(), dataFim.ToDateTime().ToDateTimeDataFim(), "Validar Data", this.GetType())));
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarDataInicioDataFim(dataFim.ToDateTime(), dataFim.ToDateTime().ToDateTimeDataFim(), "Validar Data", this.GetType())));

            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarDataInicioDataFim(dataFim.ToDateTime(), dataFim.ToDateTime(), "Validar Data", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarDataInicioDataFim(DateTime.MinValue, DateTime.MaxValue, "Validar Data", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarDataInicioDataFim(DateTime.MaxValue, DateTime.MinValue, "Validar Data", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarDataInicioDataFim(null, null, "Validar Data", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarDataInicioDataFim(null, dataFim.ToDateTime(), "Validar Data", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarDataInicioDataFim(dataInicio.ToDateTime(), null, "Validar Data", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarDataInicioDataFim(DateTime.MinValue, dataFim.ToDateTime(), "Validar Data", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarDataInicioDataFim(dataInicio.ToDateTime(), DateTime.MinValue, "Validar Data", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarDataInicioDataFim(dataInicio.ToDateTime(), DateTime.MaxValue, "Validar Data", this.GetType())));
        }
예제 #11
0
        //Criar Metoso Async para salvar com o usuário
        public int Salvar(string usuario)
        {
            try
            {
                return(base.SaveChanges(usuario));
            }
            catch (DbUpdateException due)     ///<summary>Quando algum erro diferente foi apresentado e for possivel ser trantado incluir a tratativa</summary>
            {
                //armazena a mensagem de erro e as mensagens das duas exceptions interiores
                string mensagens = due.Message + " "
                                   + due.InnerException?.Message + " "
                                   + due.InnerException?.InnerException?.Message;

                ValidacoesDominio.IsValid(new NotificacoesDominio("BaseSalvar", "Erro de atualização: " + mensagens, null, true));
            }
            catch (DbEntityValidationException dve)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = dve.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(dve.Message, " Erros de Validação: ", fullErrorMessage);

                ValidacoesDominio.IsValid(new NotificacoesDominio("BaseSalvar", exceptionMessage, null, true));
            }
            catch (InvalidOperationException ioe)
            {
                ValidacoesDominio.IsValid(new NotificacoesDominio("BaseSalvar", "Ocorreu um erro devido a uma operação inválida: " + ioe.Message, null, true));
            }
            catch (Exception ex)
            {
                ValidacoesDominio.IsValid(new NotificacoesDominio("BaseSalvar", "Ocorreu um erro inesperado: " + ex.Message, null, true));

                //usar thorw para preservar a stack e gravar o log correto no elmah
                throw;
            }

            return(0);
        }
예제 #12
0
        public void ValidarUrlTest()
        {
            string url = @"https://stackoverflow.com/questions/7578857/how-to-check-whether-a-string-is-a-valid-http-url";

            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarUrl(url, "Validar URL", this.GetType())));

            url = @"http://stackoverflow.com/questions/7578857/how-to-check-whether-a-string-is-a-valid-http-url";
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarUrl(url, "Validar URL", this.GetType())));

            url = @"https://www.stackoverflow.com/questions/7578857/how-to-check-whether-a-string-is-a-valid-http-url";
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarUrl(url, "Validar URL", this.GetType())));

            url = @"http://www.stackoverflow.com/questions/7578857/how-to-check-whether-a-string-is-a-valid-http-url";
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarUrl(url, "Validar CPF", this.GetType())));

            url = @"HTTPS://DEV.TJSP.JUS.BR/RHF/MED/";
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarUrl(url, "Validar URL", this.GetType())));

            url = @"https://qa.tjsp.jus.br/RHF/MED/";
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarUrl(url, "Validar URL", this.GetType())));

            url = @"https://uat.tjsp.jus.br/RHF/MED/";
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarUrl(url, "Validar URL", this.GetType())));

            url = @"https://hom.tjsp.jus.br/RHF/MED/";
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarUrl(url, "Validar URL", this.GetType())));

            url = @"https://www.tjsp.jus.br/RHF/MED/";
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarUrl(url, "Validar URL", this.GetType())));

            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarUrl(url, "Validar URL", this.GetType())));
            url = @"https://www.google.com.br/search?q=validar+cnpj+000000000000000&rlz=1C1CHZL_pt-BRBR722BR722&oq=validar+cnpj+000000000000000&aqs=chrome..69i57.10055j0j7&sourceid=chrome&ie=UTF-8&safe=active#safe=active&q=validar+url+maior+que+2054+caracteres+regex+";
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarUrl(url, "Validar URL", this.GetType())));

            url = @"http:/www.stackoverflow.com/questions/7578857/how-to-check-whether-a-string-is-a-valid-http-url";
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarUrl(url, "Validar URL", this.GetType())));

            url = @"https://www.google.com.br/search?q=validar+cnpj+000000000000000&rlz=1C1CHZL_pt-BRBR722BR722&oq=validar+cnpj+000000000000000&aqs=chrome..69i57.10055j0j7&sourceid=chrome&ie=UTF-8&safe=active#safe=active&q=validar+url+c%23+Uri.TryCreatesearch?q=validar+cnpj+000000000000000&rlz=1C1CHZL_pt-BRBR722BR722&oq=validar+cnpj+000000000000000&aqs=chrome..69i57.10055j0j7&sourceid=chrome&ie=UTF-8&safe=active#safe=active&q=validar+url+c%23+Uri.TryCreatesearch?q=validar+cnpj+000000000000000&rlz=1C1CHZL_pt-BRBR722BR722&oq=validar+cnpj+000000000000000&aqs=chrome..69i57.10055j0j7&sourceid=chrome&ie=UTF-8&safe=active#safe=active&q=validar+url+c%23+Uri.TryCreatesearch?q=validar+cnpj+000000000000000&rlz=1C1CHZL_pt-BRBR722BR722&oq=validar+cnpj+000000000000000&aqs=chrome..69i57.10055j0j7&sourceid=chrome&ie=UTF-8&safe=active#safe=active&q=validar+url+c%23+Uri.TryCreatesearch?q=validar+cnpj+000000000000000&rlz=1C1CHZL_pt-BRBR722BR722&oq=validar+cnpj+000000000000000&aqs=chrome..69i57.10055j0j7&sourceid=chrome&ie=UTF-8&safe=active#safe=active&q=validar+url+c%23+Uri.TryCreatesearch?q=validar+cnpj+000000000000000&rlz=1C1CHZL_pt-BRBR722BR722&oq=validar+cnpj+000000000000000&aqs=chrome..69i57.10055j0j7&sourceid=chrome&ie=UTF-8&safe=active#safe=active&q=validar+url+c%23+Uri.TryCreatesearch?q=validar+cnpj+000000000000000&rlz=1C1CHZL_pt-BRBR722BR722&oq=validar+cnpj+000000000000000&aqs=chrome..69i57.10055j0j7&sourceid=chrome&ie=UTF-8&safe=active#safe=active&q=validar+url+c%23+Uri.TryCreatesearch?q=validar+cnpj+000000000000000&rlz=1C1CHZL_pt-BRBR722BR722&oq=validar+cnpj+000000000000000&aqs=chrome..69i57.10055j0j7&sourceid=chrome&ie=UTF-8&safe=active#safe=active&q=validar+url+c%23+Uri.TryCreatesearch?q=validar+cnpj+000000000000000&rlz=1C1CHZL_pt-BRBR722BR722&oq=validar+cnpj+000000000000000&aqs=chrome..69i57.10055j0j7&sourceid=chrome&ie=UTF-8&safe=active#safe=active&q=validar+url+c%23+Uri.TryCreatesearch?q=validar+cnpj+000000000000000&rlz=1C1CHZL_pt-BRBR722BR722&oq=validar+cnpj+000000000000000&aqs=chrome..69i57.10055j0j7&sourceid=chrome&ie=UTF-8&safe=active#srf";
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarUrl(url, "Validar URL", this.GetType())));

            url = @"www.stackoverflow.com/questions/7578857/how-to-check-whether-a-string-is-a-valid-http-url";
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarUrl(url, "Validar URL", this.GetType())));
        }
예제 #13
0
        public static long DescriptografarIdsParaUrl(long idCriptografado)
        {
            long   idInvertido  = idCriptografado - ChaveCriptografiaId;
            string valorBinario = Convert.ToString(idInvertido, 2);

            try
            {
                valorBinario = valorBinario.Insert(0, "000000000000000000000000000000".Substring(0, 30 - valorBinario.Length));
            }
            catch (ArgumentOutOfRangeException e)
            {
                ValidacoesDominio.IsValid(new NotificacoesDominio("CriptografiaDescriptografarIdsParaURL", e.Message, e.GetType(), true));
                return(idCriptografado);
            }

            valorBinario = InverterTexto(valorBinario);

            long id = Convert.ToInt64(valorBinario, 2);

            return(id);
        }
예제 #14
0
        public void ValidarEmailTest()
        {
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarEmail("*****@*****.**", "Validar E-mail", this.GetType())));
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarEmail("*****@*****.**", "Validar E-mail", this.GetType())));
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarEmail("*****@*****.**", "Validar E-mail", this.GetType())));
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarEmail("*****@*****.**", "Validar E-mail", this.GetType())));
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarEmail("*****@*****.**", "Validar E-mail", this.GetType())));
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarEmail("[email protected]", "Validar E-mail", this.GetType())));
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarEmail("js#[email protected]", "Validar E-mail", this.GetType())));
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarEmail("j_9@[129.126.118.1]", "Validar E-mail", this.GetType())));
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarEmail("[email protected]", "Validar E-mail", this.GetType())));
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarEmail("*****@*****.**", "Validar E-mail", this.GetType())));
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarEmail("\"j\\\"s\\\"\"@mps.com", "Validar E-mail", this.GetType())));

            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarEmail("*****@*****.**", "Validar E-mail", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarEmail("*****@*****.**", "Validar E-mail", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarEmail("js*@mps.com", "Validar E-mail", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarEmail("*****@*****.**", "Validar E-mail", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarEmail("*****@*****.**", "Validar E-mail", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarEmail("contatomps.com.br", "Validar E-mail", this.GetType())));
            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarEmail("@mps.com.br", "Validar E-mail", this.GetType())));
        }
예제 #15
0
        public void Salvar(string usuario)
        {
            try
            {
                _dbContext.SaveChanges(usuario);
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(ex.Message, " Erros de Validação: ", fullErrorMessage);

                // Throw a new DbEntityValidationException with the improved exception message.
                ValidacoesDominio.IsValid(new NotificacoesDominio("BaseSalvar", exceptionMessage, null, true));
                throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
            }
        }
예제 #16
0
 public static bool ValidarData(DateTime?data, Type type)
 {
     return(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarDataMinima(data, "Data do alteração invalida", type)));
 }
예제 #17
0
 public void ValidarTelefoneMascaraTest()
 {
     Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarTelefoneMascara("(11) 3458-7821", "String somente numero", this.GetType())));
     Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarTelefoneMascara("(11) 94862-7814", "String somente numero", this.GetType())));
 }
예제 #18
0
 public static bool ValidarUsuario(string usuario, Type type)
 {
     return(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarStringVaziaOuNula(usuario, "Usuário alteração não informado", type),
                                      ValidacoesDominio.ValidarTamanhoString(usuario, 6, 10, "Usuário informado não corresponde ao tamano da Matricula", type),
                                      ValidacoesDominio.ValidarStringSomenteNumero(usuario, "Usuário informado somente números na Matricula", type)));
 }
예제 #19
0
 public void ValidarTelefoneTest()
 {
     Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarTelefone("1134587821", "String somente numero", this.GetType())));
     Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarTelefone("11948627814", "String somente numero", this.GetType())));
 }
예제 #20
0
        public void ValidarObjetoIsNullTest()
        {
            Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarObjetoIsNull(null, "Validar ObjetoIsNull", this.GetType())));

            Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarObjetoIsNull(new Object(), "Validar ObjetoIsNull", this.GetType())));
        }
예제 #21
0
 public void ValidarStringSomenteNumeroTest()
 {
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarStringSomenteNumero("teste", "String somente numero", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarStringSomenteNumero("teste 123", "String somente numero", this.GetType())));
     Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarStringSomenteNumero("123", "String somente numero", this.GetType())));
 }
예제 #22
0
 public void ValidarStringSomenteLetrasTest()
 {
     Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarStringSomenteLetras("teste", "String somente letra", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarStringSomenteLetras("teste 123", "String somente letra", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarStringSomenteLetras("123", "String somente letra", this.GetType())));
 }
예제 #23
0
 public void ValidarIntMaiorQueEsperadoTest()
 {
     Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarIntMaiorQueEsperado(10, 5, "Validar int maior que o esperado", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarIntMaiorQueEsperado(10, 10, "Validar int maior que o esperado", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarIntMaiorQueEsperado(10, 15, "Validar int maior que o esperado", this.GetType())));
 }
예제 #24
0
 public void ValidarStringsIguaisTest()
 {
     Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarStringsIguais("Teste 1", "Teste 1", "Campos de Texto não São iguais", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarStringsIguais("Teste 1", "Teste 2", "Campos de Texto não São iguais", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarStringsIguais("TESTE", "Teste", "Campos de Texto não São iguais", this.GetType())));
 }
예제 #25
0
 public void ValidarIntMenorOuIgualQueEsperadoTest()
 {
     Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarIntMenorOuIgualQueEsperado(5, 10, "Validar int maior ou igual que o esperado", this.GetType())));
     Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarIntMenorOuIgualQueEsperado(10, 10, "Validar int maior ou igual que o esperado", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarIntMenorOuIgualQueEsperado(15, 10, "Validar int maior ou igual que o esperado", this.GetType())));
 }
예제 #26
0
 public void ValidarDecimalMaiorOuIgualQueEsperadoTest()
 {
     Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarDecimalMaiorOuIgualQueEsperado(10.1m, 5m, "Validar decimal maior que o esperado", this.GetType())));
     Assert.IsTrue(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarDecimalMaiorOuIgualQueEsperado(10.1m, 10.1m, "Validar decimal maior que o esperado", this.GetType())));
     Assert.IsFalse(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarDecimalMaiorOuIgualQueEsperado(10.2m, 15.5m, "Validar decimal maior que o esperado", this.GetType())));
 }
예제 #27
0
 public static bool ValidarStatusRegistro(byte statusRegistroId, Type type)
 {
     return(ValidacoesDominio.IsValid(ValidacoesDominio.ValidarIntMaiorOuIgualQueEsperado(statusRegistroId, 0, "Usuário alteração não informado", type),
                                      ValidacoesDominio.ValidarIntMenorOuIgualQueEsperado(statusRegistroId, 3, "Usuário informado não corresponde ao tamanho da Matricula", type)));
 }