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

Commit

Permalink
Testes unitarios
Browse files Browse the repository at this point in the history
  • Loading branch information
CristianoRC committed Jan 9, 2017
1 parent 686d884 commit 0f2245e
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 1 deletion.
4 changes: 4 additions & 0 deletions DotCep/DotCEP.Test/DotCEP.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.3.5.0\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Spartacus">
<HintPath>..\packages\Spartacus.0.42.0\lib\net40\Spartacus.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand All @@ -46,6 +49,7 @@
<Compile Include="TestUF.cs" />
<Compile Include="Localidades\TestEstado.cs" />
<Compile Include="Localidades\TestMunicipio.cs" />
<Compile Include="TestConsultas.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Localidades\" />
Expand Down
63 changes: 63 additions & 0 deletions DotCep/DotCEP.Test/TestConsultas.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using NUnit.Framework;

namespace DotCEP.Test
{
[TestFixture]
public class TestConsultas
{
[Test]
public void TestConsultaEnderecoCompletoValido()
{
DotCEP.Endereco enderecoBase = DotCEP.Consultas.ObterEnderecoCompleto("96085000");

Assert.AreEqual("Pelotas", enderecoBase.localidade);
Assert.AreEqual("Areal", enderecoBase.bairro);
Assert.AreEqual("Avenida Ferreira Viana", enderecoBase.logradouro);
}

[Test]
public void TestConsultaEnderecoCompletoInvalido()
{
DotCEP.Endereco enderecoBase = DotCEP.Consultas.ObterEnderecoCompleto("960850000");

Assert.AreEqual(null, enderecoBase.localidade);
Assert.AreEqual(null, enderecoBase.bairro);
Assert.AreEqual(null, enderecoBase.logradouro);
}

[Test]
public void TestConsultaListaEnderecos()
{
System.Collections.Generic.List<Endereco> ListaEnderecos = DotCEP.Consultas.ObterListaDeEnderecos(UF.RS, "Pelotas", "Ferreira");

Assert.AreEqual(11, ListaEnderecos.Count);
Assert.AreEqual("Três Vendas", ListaEnderecos[6].bairro);
}

[TearDown]
public void ApagarCache()
{
Spartacus.Database.Generic database = new Spartacus.Database.Sqlite(ObterCaminhoBancoCache());
Spartacus.Database.Command cmd = new Spartacus.Database.Command();

cmd.v_text = "Delete from Cache";
database.Execute(cmd.GetUpdatedText());

cmd.v_text = "Delete from ConsultaEndereco";
database.Execute(cmd.GetUpdatedText());
}

private static string ObterCaminhoBancoCache()
{
if (((int)Environment.OSVersion.Platform) < 4)
{
return string.Format(@"{0}\\Cache\\Cache.db", System.AppDomain.CurrentDomain.BaseDirectory); // Windows
}
else
{
return String.Format(@"{0}/Cache/Cache.db", System.AppDomain.CurrentDomain.BaseDirectory); // Linux e MacOSX
}
}
}
}
22 changes: 22 additions & 0 deletions DotCep/DotCEP.Test/TestValidacao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,27 @@ public void TestVerificacaoDeCEPInexistente()
bool resultadoDaExistencia = DotCEP.Validacoes.VerificarExistenciaDoCEP("960850000");
Assert.AreEqual(false, resultadoDaExistencia);
}

[TearDown]
public void ApagarCache()
{
Spartacus.Database.Generic database = new Spartacus.Database.Sqlite(ObterCaminhoBancoCache());
Spartacus.Database.Command cmd = new Spartacus.Database.Command();

cmd.v_text = "Delete from Cache";
database.Execute(cmd.GetUpdatedText());
}

private static string ObterCaminhoBancoCache()
{
if (((int)Environment.OSVersion.Platform) < 4)
{
return string.Format(@"{0}\\Cache\\Cache.db", System.AppDomain.CurrentDomain.BaseDirectory); // Windows
}
else
{
return String.Format(@"{0}/Cache/Cache.db", System.AppDomain.CurrentDomain.BaseDirectory); // Linux e MacOSX
}
}
}
}
1 change: 1 addition & 0 deletions DotCep/DotCEP.Test/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.5.0" targetFramework="net45" />
<package id="Spartacus" version="0.42.0" targetFramework="net45" />
</packages>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img src = http://i.imgur.com/12X632a.png>

<br>
[![Versão](https://img.shields.io/badge/Vers%C3%A3o-1.2.0-blue.svg?style=flat-square)](https://www.nuget.org/packages/DotCEP/) [![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square)](https://github.com/CristianoRC/SoftwareOrdemDeServico/blob/master/LICENSE.txt) ![TestesUnitarios](https://img.shields.io/badge/TestesUnitários-38%25-blue.svg?style=flat-square) [![Wiki](https://img.shields.io/badge/Wiki-Ajuda-blue.svg?style=flat-square)](https://github.com/CristianoRC/DotCEP/wiki)
[![Versão](https://img.shields.io/badge/Vers%C3%A3o-1.2.0-blue.svg?style=flat-square)](https://www.nuget.org/packages/DotCEP/) [![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square)](https://github.com/CristianoRC/SoftwareOrdemDeServico/blob/master/LICENSE.txt) ![TestesUnitarios](https://img.shields.io/badge/TestesUnitários-100%25-blue.svg?style=flat-square) [![Wiki](https://img.shields.io/badge/Wiki-Ajuda-blue.svg?style=flat-square)](https://github.com/CristianoRC/DotCEP/wiki)

<br>

Expand Down

0 comments on commit 0f2245e

Please sign in to comment.