Exemple #1
0
        public void EqualsTrue()
        {
            var site1 = new Site("X");
            var site2 = new Site("X");

            var anuncio1 = new Anuncio(new Alvo(site1, 1));
            var anuncio2 = new Anuncio(new Alvo(site2, 1));

            Assert.IsTrue(anuncio1.Equals(anuncio2));
        }
Exemple #2
0
        public void ToCSV()
        {
            var alvo = new Alvo(new Site("adsf"), 1);
            var anuncio = new Anuncio(alvo);
            anuncio.Area = 123;
            anuncio.Preco = 456;
            anuncio.Bairro = "bairro";
            anuncio.NumeroQuartos = 4;

            string strCSV = anuncio.ToCSV();

            Assert.AreEqual("\"456\",\"123\",\"bairro\",\"adsf\",\"1\",\"NI\",\"NI\",\"4\"",
                strCSV);
        }
Exemple #3
0
        public void FromCSV_ToCSV_Roundtrip()
        {
            var alvoOrigem = new Alvo(new Site("asdf"), 1);

            var anuncioOrigem = new Anuncio(alvoOrigem);
            anuncioOrigem.Area = 111;
            anuncioOrigem.Preco = 222;
            anuncioOrigem.Bairro = "zzz";
            anuncioOrigem.TipoImovel = TipoImovel.AP;
            anuncioOrigem.TipoTransacao = TipoTransacao.AL;
            anuncioOrigem.NumeroQuartos = 4;

            var anuncioDestino = Anuncio.FromCSV(anuncioOrigem.ToCSV());

            Assert.AreEqual(anuncioOrigem.Area, anuncioDestino.Area);
            Assert.AreEqual(anuncioOrigem.Preco, anuncioDestino.Preco);
            Assert.AreEqual(anuncioOrigem.Bairro, anuncioDestino.Bairro);
            Assert.AreEqual(anuncioOrigem.TipoImovel, anuncioDestino.TipoImovel);
            Assert.AreEqual(anuncioOrigem.TipoTransacao, anuncioDestino.TipoTransacao);
            Assert.AreEqual(anuncioOrigem.NumeroQuartos, anuncioDestino.NumeroQuartos);

            Assert.IsTrue(anuncioOrigem.Equals(anuncioDestino));
        }
Exemple #4
0
        public Anuncio ExtrairAnuncio(Alvo alvo)
        {
            try
            {
                var novoAnuncio = new Anuncio(alvo);
                novoAnuncio.Bairro = this.ExtrairCampo(this.RegexBairro, alvo);
                novoAnuncio.Preco = ObterPreco(alvo);
                novoAnuncio.NumeroQuartos = this.ExtrairCampoInt(this.RegexNumeroQuartos, alvo);
                novoAnuncio.Area = ExtrairCampoDecimal(this.RegexArea, alvo);
                novoAnuncio.TipoImovel = ObterTipoImovel(alvo);
                novoAnuncio.TipoTransacao = ObterTipoTransacao(alvo);

                return novoAnuncio;
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format(
                    "Não foi possível extrair Anuncio do Alvo({0}).", alvo), ex);
            }
        }
Exemple #5
0
        public static Anuncio Parse(System.Data.DataRow anuncioRow)
        {
            var siteOrigem = Site.GetSitePorNome(anuncioRow["siteOrigem"].ToString());
            var id = Convert.ToInt32(anuncioRow["id"]);

            var ret = new Anuncio(new Alvo(siteOrigem, id));
            ret.Bairro = anuncioRow["bairro"].ToString();
            ret.Area = (decimal)anuncioRow["area"];
            ret.NumeroQuartos = Convert.ToInt32(anuncioRow["numeroQuartos"].ToString());
            ret.Preco = (decimal)anuncioRow["preco"];

            string ti = anuncioRow["tipoImovel"].ToString();
            ret.TipoImovel = (ti == "a") ? TipoImovel.AP : TipoImovel.CS;
            string tt = anuncioRow["tipoTransacao"].ToString();
            ret.TipoTransacao = (tt == "a") ? TipoTransacao.AL : TipoTransacao.VD;

            return ret;
        }
Exemple #6
0
        public static Anuncio FromCSV(string anuncioCSV)
        {
            if (string.IsNullOrEmpty(anuncioCSV))
                return null;

            var campos = Utils.FromCSV(anuncioCSV);

            string preco = campos[0];
            string area = campos[1];
            string bairro = campos[2];
            string alvoSite = campos[3];
            int alvoId = Convert.ToInt32(campos[4]);
            string imovel = campos[5];
            string transacao = campos[6];
            int numeroQuartos = Convert.ToInt32(campos[7]);

            var retorno = new Anuncio();
            retorno.Preco = Convert.ToDecimal(preco);
            retorno.Area = Convert.ToDecimal(area);
            retorno.Bairro = bairro;
            retorno.Alvo = new Alvo(new Site(alvoSite), alvoId);
            retorno.TipoImovel
                = (TipoImovel) Enum.Parse(typeof(TipoImovel), imovel);
            retorno.TipoTransacao
                = (TipoTransacao) Enum.Parse(typeof(TipoTransacao), transacao);
            retorno.NumeroQuartos = numeroQuartos;
            return retorno;
        }
Exemple #7
0
        public void Anuncio_SqliteSalvar_Insert_Roundtrip()
        {
            var alvo = new Alvo("Infonet", 3);
            var anuncioOrigem = new Anuncio(alvo);
            anuncioOrigem.NumeroQuartos = 4;
            anuncioOrigem.Area = 555.55m;
            anuncioOrigem.TipoImovel = TipoImovel.CS;
            anuncioOrigem.TipoTransacao = TipoTransacao.VD;
            anuncioOrigem.Preco = 9.99m;
            anuncioOrigem.Bairro = "Cirurgia";

            anuncioOrigem.SqliteSalvar();
            var anuncioDestino = Anuncio.SqliteFind("Infonet", 3);

            Assert.AreEqual(anuncioOrigem.NumeroQuartos, anuncioDestino.NumeroQuartos);
            Assert.AreEqual(anuncioOrigem.Area, anuncioDestino.Area);
            Assert.AreEqual(anuncioOrigem.TipoImovel, anuncioDestino.TipoImovel);
            Assert.AreEqual(anuncioOrigem.TipoTransacao, anuncioDestino.TipoTransacao);
            Assert.AreEqual(anuncioOrigem.Preco, anuncioDestino.Preco);
            Assert.AreEqual(anuncioOrigem.Bairro, anuncioDestino.Bairro);
        }