public async Task Select_NoProyectoSeleccionados()
        {
            using (context)
            {
                //Arrange

                var controller = new SolicitudesController(context);
                controller.ControllerContext.HttpContext = solicitudContext;
                var proyectosesperados = new Proyecto[2]
                {
                    new Proyecto {
                        ProyectoId = 1, FechaExpiracion = new DateTime(2019, 01, 23), Importe = 70000, Interes = null, MinInversion = 50, Nombre = "POCHOLO RULES", NumInversores = 0, Plazo = null, Progreso = 0, RatingId = null
                    },
                    new Proyecto {
                        ProyectoId = 2, FechaExpiracion = new DateTime(2019, 01, 23), Importe = 30000, Interes = null, MinInversion = 50, Nombre = "GRE-GYM", NumInversores = 0, Plazo = null, Progreso = 0, RatingId = null
                    }
                };
                //Areas y Tipos que se espera que se retornen

                var tiposEsperados = new TiposInversiones[1] {
                    new TiposInversiones {
                        Nombre = "Crowdfunding"
                    }
                };
                var areasEsperadas = new Areas[1] {
                    new Areas {
                        Nombre = "TIC"
                    }
                };

                SelectedProyectosForSolicitudViewModel proyectos = new SelectedProyectosForSolicitudViewModel {
                    IdsToAdd = null
                };

                // Act

                var result = controller.SelectProyectosForSolicitud(proyectos);

                // Assert
                var viewResult = Assert.IsType <ViewResult>(result);
                SelectProyectosForSolicitudViewModel model = viewResult.Model as SelectProyectosForSolicitudViewModel;
                //Comprobamos los proyectos devueltos
                Assert.Equal(proyectosesperados, model.proyectos, Comparer.Get <Proyecto>((p1, p2) => p1.Nombre == p2.Nombre &&
                                                                                          p1.Importe == p2.Importe && p1.MinInversion == p2.MinInversion && p1.Progreso == p2.Progreso && p1.ProyectoId == p2.ProyectoId));
                //Comprobamos las areas y tipos devueltos
                Assert.Equal(tiposEsperados, model.Tipos, Comparer.Get <TiposInversiones>((p1, p2) => p1.Nombre == p2.Nombre));
                Assert.Equal(areasEsperadas, model.areas, Comparer.Get <Areas>((p1, p2) => p1.Nombre == p2.Nombre));
            }
        }
Example #2
0
        //GET: Select
        public IActionResult SelectProyectosForSolicitud(string nombreProyecto, string[] tipoSeleccionado, string[] areasSeleccionada, int?capital, DateTime?fecha
                                                         )
        {
            SelectProyectosForSolicitudViewModel selectProyecto = new SelectProyectosForSolicitudViewModel();

            selectProyecto.areas     = _context.Areas;
            selectProyecto.Tipos     = _context.TiposInversiones;
            selectProyecto.proyectos = _context.Proyecto.Include(m => m.Rating).Include(m => m.ProyectoAreas).
                                       ThenInclude <Proyecto, ProyectoAreas, Areas>(p => p.Areas).Include(p => p.ProyectoTiposInversiones).
                                       ThenInclude <Proyecto, ProyectoTiposInversiones, TiposInversiones>(p => p.TiposInversiones).Where(p => p.RatingId == null);

            if (nombreProyecto != null)
            {
                selectProyecto.proyectos = selectProyecto.proyectos.Where(p => p.Nombre.Contains(nombreProyecto));
            }

            if (capital != null)
            {
                selectProyecto.proyectos = selectProyecto.proyectos.Where(p => p.Importe.CompareTo((float)capital) >= 0);
            }

            if (tipoSeleccionado.Length != 0)
            {
                selectProyecto.proyectos = selectProyecto.proyectos.Where(p => p.ProyectoTiposInversiones.Any(ti => tipoSeleccionado.Contains(ti.TiposInversiones.Nombre)));
            }

            if (areasSeleccionada.Length != 0)

            {
                selectProyecto.proyectos = selectProyecto.proyectos.Where(p => p.ProyectoAreas.Any(ti => areasSeleccionada.Contains(ti.Areas.Nombre)));

                /*
                 * foreach (String i in areasSeleccionada)
                 * selectProyecto.proyectos = selectProyecto.proyectos.Where(p => p.ProyectoAreas.Any(a => a.Areas.Nombre.Contains(i)));
                 */
            }



            if (fecha != null)
            {
                selectProyecto.proyectos = selectProyecto.proyectos.Where(p => p.FechaExpiracion.Date.Equals(fecha));
            }
            selectProyecto.proyectos.ToList();

            return(View(selectProyecto));
        }
Example #3
0
        public IActionResult SelectProyectosForSolicitud(SelectedProyectosForSolicitudViewModel selectedproyectos)
        {
            if (selectedproyectos.IdsToAdd != null)
            {
                return(RedirectToAction("Create", selectedproyectos));
            }


            ModelState.AddModelError(string.Empty, "Debes seleccionar al menos 1 proyecto para publicar");

            SelectProyectosForSolicitudViewModel selectProyecto = new SelectProyectosForSolicitudViewModel();

            selectProyecto.areas     = _context.Areas;
            selectProyecto.Tipos     = _context.TiposInversiones;
            selectProyecto.proyectos = _context.Proyecto.Include(m => m.Rating).Include(m => m.ProyectoAreas).
                                       ThenInclude <Proyecto, ProyectoAreas, Areas>(p => p.Areas).Include(p => p.ProyectoTiposInversiones).
                                       ThenInclude <Proyecto, ProyectoTiposInversiones, TiposInversiones>(p => p.TiposInversiones).Where(m => m.RatingId == null);
            return(View(selectProyecto));
        }
        public async Task Select_FiltroDeCapital()
        {
            //Arrenge
            //Base SQL ya generada con datos incluidos
            using (context)
            {
                var proyectosesperados = new Proyecto[1] {
                    new Proyecto {
                        ProyectoId = 1, FechaExpiracion = new DateTime(2019, 01, 23), Importe = 70000, Interes = null, MinInversion = 50, Nombre = "POCHOLO RULES", NumInversores = 0, Plazo = null, Progreso = 0, RatingId = null
                    }
                };

                //Areas y Tipos que se espera que se retornen

                var tiposEsperados = new TiposInversiones[1] {
                    new TiposInversiones {
                        Nombre = "Crowdfunding"
                    }
                };
                var areasEsperadas = new Areas[1] {
                    new Areas {
                        Nombre = "TIC"
                    }
                };

                var controller = new SolicitudesController(context);
                controller.ControllerContext.HttpContext = solicitudContext;
                //Act
                string[] vacia  = new string[0];
                var      result = controller.SelectProyectosForSolicitud(null, vacia, vacia, 65000, null);

                //Assert
                var viewResult = Assert.IsType <ViewResult>(result);
                SelectProyectosForSolicitudViewModel model = viewResult.Model as SelectProyectosForSolicitudViewModel;
                //Comprobamos los proyectos devueltos
                Assert.Equal(proyectosesperados, model.proyectos, Comparer.Get <Proyecto>((p1, p2) => p1.Nombre == p2.Nombre &&
                                                                                          p1.Importe == p2.Importe && p1.MinInversion == p2.MinInversion && p1.Progreso == p2.Progreso && p1.ProyectoId == p2.ProyectoId));
                //Comprobamos las areas y tipos devueltos
                Assert.Equal(tiposEsperados, model.Tipos, Comparer.Get <TiposInversiones>((p1, p2) => p1.Nombre == p2.Nombre));
                Assert.Equal(areasEsperadas, model.areas, Comparer.Get <Areas>((p1, p2) => p1.Nombre == p2.Nombre));
            }
        }