Exemplo n.º 1
0
 public CotizacionServices()
 {
     Repository = new CotizacionRepository();
     CotizacionesRegistradas = ((CotizacionRepository)Repository).CotizacionesRegistradas;
     if (CotizacionesRegistradas == null)
     {
         CotizacionesRegistradas = new List <Cotizacion>();
     }
     ObtenerConteo();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Inicializa y construye el sistema.
        /// </summary>
        /// <returns></returns>
        public static Sistema BuildSistema()
        {
            DbContextOptions <ModelDbContext> options = new DbContextOptionsBuilder <ModelDbContext>()
                                                        .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                                                        .EnableSensitiveDataLogging()
                                                        .Options;

            DbContext dbContext = new ModelDbContext(options);

            IPersonaRepository    personas     = new PersonaRepository(dbContext);
            IRepository <Usuario> usuarios     = new ModelRepository <Usuario>(dbContext);
            ICotizacionRepository cotizaciones = new CotizacionRepository(dbContext);

            return(new Sistema(personas, usuarios, cotizaciones));
        }
Exemplo n.º 3
0
        public void SistemaConstructorTest()
        {
            DbContextOptions <ModelDbContext> options = new DbContextOptionsBuilder <ModelDbContext>()
                                                        .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                                                        .EnableSensitiveDataLogging()
                                                        .Options;
            DbContext             dbContext    = new ModelDbContext(options);
            IPersonaRepository    personas     = new PersonaRepository(dbContext);
            IRepository <Usuario> usuarios     = new ModelRepository <Usuario>(dbContext);
            ICotizacionRepository cotizaciones = new CotizacionRepository(dbContext);
            IRepository <Item>    items        = null;

            //Cuando faltan repositorios
            Assert.Throws <ArgumentNullException>(() => new Sistema(personas, usuarios, cotizaciones, items));
        }
Exemplo n.º 4
0
        public void InsercionBusquedaCotizacionTest()
        {
            DbContext            dbContext  = BuildTestModelContext();
            CotizacionRepository repository = new CotizacionRepository(dbContext);

            Persona persona = new Persona()
            {
                Nombre  = "Felipe",
                Email   = "*****@*****.**",
                Materno = "Varas",
                Paterno = "jara",
                Rut     = "194517319"
            };

            Servicio servicio = new Servicio()
            {
                Estado = EstadoServicio.PREPRODUCCION,
                Nombre = "video",
                Precio = 230000
            };
            Cotizacion cotizacion = new Cotizacion()
            {
                estado  = EstadoCotizacion.BORRADOR,
                Fecha   = DateTime.Now,
                Persona = persona,
            };

            //Agregar servicio
            {
                cotizacion.Add(servicio);
                Assert.NotEmpty(cotizacion.Servicios);
            }

            //Agregar cotizacion
            {
                repository.Add(cotizacion);
                Assert.NotEmpty(repository.GetAll());
            }

            //Busqueda por rut  (exitosa)
            {
                List <Cotizacion> busqueda = repository.GetByRut("194517319");
                Assert.NotEmpty(busqueda);
            }

            //Busqueda por rut (no exitosa)
            {
                List <Cotizacion> cotizaciones = repository.GetByRut("194441568");
                Assert.Empty(cotizaciones);
            }

            //Busqueda por rut (no exitosa - rut nulo)
            {
                List <Cotizacion> busqueda = repository.GetByRut(null);
                Assert.Empty(busqueda);
            }

            //Eliminar cotizacion  (exitosa)
            {
                repository.Remove(cotizacion);
            }

            //Eliminar cotizacion (no exitosa)
            { Assert.Throws <ArgumentNullException>(() => repository.Remove(null)); }
        }
Exemplo n.º 5
0
        public void InsercionBusquedaCotizacionTest()
        {
            // Contexto
            DbContext dbContext = BuildTestModelContext();

            // Repositorio de Cotizacions
            CotizacionRepository repo = new CotizacionRepository(dbContext);

            // Creacion
            {
                Cotizacion cotizacion = new Cotizacion();
                {
                    DateTime hoy    = DateTime.Now;
                    string   hoySTR = hoy.ToString();
                    cotizacion.Id                = 1;
                    cotizacion.FechaCreacion     = hoy;
                    cotizacion.RutCliente        = "174920524";
                    cotizacion.RutUsuarioCreador = "147112912";
                }


                // Insert into the backend
                repo.Add(cotizacion);
            }

            // Busqueda (exitosa)
            {
                Cotizacion cotizacion = repo.GetById(1);
                Assert.NotNull(cotizacion);
            }

            // Busqueda (no exitosa)
            {
                Cotizacion cotizacion = repo.GetById(-1);
                Assert.Null(cotizacion);
            }

            // Todos
            {
                IList <Cotizacion> cotizaciones = repo.GetAll();
                Assert.NotEmpty(cotizaciones);
            }

            // Busqueda por id (exito)
            {
                IList <Cotizacion> cotizaciones = repo.GetAll(c => c.Id.Equals(1));
                Assert.NotEmpty(cotizaciones);
            }

            // Busqueda por id (no exito)
            {
                IList <Cotizacion> cotizaciones = repo.GetAll(c => c.Id.Equals(2));
                Assert.Empty(cotizaciones);
            }

            // Busqueda por rutCliente
            {
                Assert.NotEmpty(repo.GetAll(c => c.RutCliente.Equals("174920524")));
            }

            // Busqueda por rutUsuarioCreador
            {
                Assert.NotNull(repo.GetAll(c => c.RutUsuarioCreador.Equals("174920524")));
            }

            //busqueda por fecha (exito)
            {
                DateTime d1 = DateTime.ParseExact("01/01/2017", "dd/mm/yyyy", null);
                DateTime d2 = DateTime.ParseExact("01/01/2019", "dd/mm/yyyy", null);
                Assert.NotNull(repo.GetbyDate(d1, d2));
                Assert.NotEmpty(repo.GetbyDate(d1, d2));
            }

            //busqueda_por_fecha (no exito)
            {
                DateTime d1 = DateTime.ParseExact("01/01/2017", "dd/mm/yyyy", null);
                DateTime d2 = DateTime.ParseExact("02/01/2017", "dd/mm/yyyy", null);
                Assert.Empty(repo.GetbyDate(d1, d2));
            }

            // Eliminacion
            {
                Cotizacion Cotizacion = repo.GetById(1);
                Assert.NotNull(Cotizacion);

                repo.Remove(Cotizacion);
            }
        }