Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

Commit

Permalink
Correção na busca de municipio por estado
Browse files Browse the repository at this point in the history
  • Loading branch information
CristianoRC committed Feb 11, 2017
1 parent f409b64 commit 0efb523
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 11 deletions.
6 changes: 3 additions & 3 deletions DotCep/DotCEP.Test/Localidades/TestEstado.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public void TestListaDeEstados()
int NumeroDeResultados = DotCEP.Localidades.Estado.ObterListaDeEstados().Count;
DotCEP.Localidades.Estado EstadoNumeroZero = DotCEP.Localidades.Estado.ObterListaDeEstados()[0];

Assert.AreEqual(11, EstadoNumeroZero.Codigo);
Assert.AreEqual("RO", EstadoNumeroZero.Sigla);
Assert.AreEqual("Rondonia", EstadoNumeroZero.Nome);
Assert.AreEqual(12, EstadoNumeroZero.Codigo);
Assert.AreEqual("AC", EstadoNumeroZero.Sigla);
Assert.AreEqual("Acre", EstadoNumeroZero.Nome);
Assert.AreEqual(27,NumeroDeResultados);
}
}
Expand Down
8 changes: 8 additions & 0 deletions DotCep/DotCEP.Test/Localidades/TestMunicipio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ public void TestListaDeTodosMunicipios()
Assert.AreEqual(5570, numeroDeTodosRegistros);
}


[Test]
public void TestListaDeMunicipiosPorEstado()
{
int numeroDeTodosRegistrosDoRS = Localidades.Municipio.ObterListaDeMunicipio(UF.RS).Count;
Assert.AreEqual(497, numeroDeTodosRegistrosDoRS);
}

[Test]
public void TestListaDeMunicipiosPorEstadoString()
{
int numeroDeTodosRegistrosDoRS = Localidades.Municipio.ObterListaDeMunicipio("SP").Count;
Assert.AreEqual(645, numeroDeTodosRegistrosDoRS);
}
}
}
2 changes: 1 addition & 1 deletion DotCep/DotCep/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.2.1.*")]
[assembly: AssemblyVersion("1.2.2.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
Expand Down
4 changes: 2 additions & 2 deletions DotCep/DotCep/Consultas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static Endereco ObterEnderecoCompleto(string CEP)
}
else
{
StrJSON = ControleRequisicoes.ObterStringJSONS(ControleDeUrl.GerarURLDaPesquisa(CEP));
StrJSON = ControleRequisicoes.ObterJSON(ControleDeUrl.GerarURLDaPesquisa(CEP));

enderecoBase = JsonConvert.DeserializeObject<Endereco>(StrJSON);

Expand All @@ -50,7 +50,7 @@ public static List<Endereco> ObterListaDeEnderecos(UF UF, String Cidade, String
else
{
String url = ControleDeUrl.GerarURLDaPesquisa(UF, Cidade, Logradouro);
String StrJSON = ControleRequisicoes.ObterStringJSONS(url);
String StrJSON = ControleRequisicoes.ObterJSON(url);

enderecosDeRetorno = JsonConvert.DeserializeObject<List<Endereco>>(StrJSON);

Expand Down
4 changes: 2 additions & 2 deletions DotCep/DotCep/ControleRequisicoes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace DotCEP
{
internal static class ControleRequisicoes
public static class ControleRequisicoes
{
internal static string ObterStringJSONS(string url)
internal static string ObterJSON(string url)
{
try
{
Expand Down
1 change: 1 addition & 0 deletions DotCep/DotCep/DotCEP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<Reference Include="Spartacus">
<HintPath>..\packages\Spartacus.0.44.1\lib\net40\Spartacus.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http" />
</ItemGroup>
<ItemGroup>
<Compile Include="ControleRequisicoes.cs" />
Expand Down
2 changes: 1 addition & 1 deletion DotCep/DotCep/Localidades/Estado.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static List<Estado> ObterListaDeEstados()
List<Estado> listaDeEstados = new List<Estado>();
Spartacus.Database.Command cmd = new Spartacus.Database.Command();

cmd.v_text = "select t.* from ESTADOS t";
cmd.v_text = "select t.* from ESTADOS t order by t.Nome";

try
{
Expand Down
22 changes: 21 additions & 1 deletion DotCep/DotCep/Localidades/Municipio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,27 @@ public static List<Municipio> ObterListaDeMunicipio(UF SiglaEstado)

cmd.v_text = "select t.* from Municipios t where t.CodigoEstado = #codigo#";
cmd.AddParameter("codigo", Spartacus.Database.Type.INTEGER);
cmd.SetValue("codigo", Convert.ToInt16(DotCEP.UF.RS).ToString());
cmd.SetValue("codigo", Convert.ToInt16(SiglaEstado).ToString());

listaDeMunicipios = ObterListaDoBanco(cmd.GetUpdatedText());

return listaDeMunicipios;
}

public static List<Municipio> ObterListaDeMunicipio(string SiglaEstado)
{
List<Municipio> listaDeMunicipios = new List<Municipio>();
Spartacus.Database.Command cmd = new Spartacus.Database.Command();

cmd.v_text = "select m.* from Municipios m " +
"inner join Estados e " +
"on e.codigo = m.codigoestado" +
" where e.sigla = #sigla#";


cmd.AddParameter("sigla", Spartacus.Database.Type.STRING);

cmd.SetValue("sigla", SiglaEstado);

listaDeMunicipios = ObterListaDoBanco(cmd.GetUpdatedText());

Expand Down
2 changes: 1 addition & 1 deletion DotCep/DotCep/Validacoes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static bool VerificarExistenciaDoCEP(string CEP)

if (StrJSON == string.Empty)
{
StrJSON = ControleRequisicoes.ObterStringJSONS(ControleDeUrl.GerarURLDaPesquisa(CEP));
StrJSON = ControleRequisicoes.ObterJSON(ControleDeUrl.GerarURLDaPesquisa(CEP));

Cache.Criar(CEP, StrJSON);
}
Expand Down

0 comments on commit 0efb523

Please sign in to comment.