Esempio n. 1
0
        public async Task Select_NoProyectoSeleccionados()
        {
            using (context)
            {
                // ARRANGE: Set the test case will use the inMemoty database created in the constructor
                var controller = new InversionsController(context);
                controller.ControllerContext.HttpContext = inversionContext;

                //Proyectos
                var expectedProyectos = new Proyecto[2] {
                    new Proyecto {
                        ProyectoId = 1, FechaExpiracion = new DateTime(2019, 01, 23), Importe = 30000, Interes = (float)5.90, MinInversion = 50, Nombre = "E-MEDICA", NumInversores = 0, Plazo = 12, Progreso = 0, RatingId = 3
                    },
                    new Proyecto {
                        ProyectoId = 2, FechaExpiracion = new DateTime(2019, 01, 14), Importe = 70000, Interes = (float)7.25, MinInversion = 0, Nombre = "PROTOS", NumInversores = 0, Plazo = 48, Progreso = 0, RatingId = 2
                    }
                };

                //Areas
                var expectedAreas = new Areas[1] {
                    new Areas {
                        Nombre = "Sanidad"
                    }
                };

                //Tipos de Inversiones
                var expectedTiposInversiones = new TiposInversiones[1] {
                    new TiposInversiones {
                        Nombre = "Crowdfunding"
                    }
                };

                //Rating
                var expectedRating = new Rating[1] {
                    new Rating {
                        Nombre = "A"
                    }
                };

                SelectedProyectosForInversionViewModel Proyectos = new SelectedProyectosForInversionViewModel {
                    IdsToAdd = null
                };

                // ACT
                var result = controller.SelectProyectosForInversion(Proyectos);

                //ASSERT
                var viewResult = Assert.IsType <ViewResult>(result);
                SelectProyectosForInversionViewModel model = viewResult.Model as SelectProyectosForInversionViewModel;

                Assert.Equal(expectedProyectos, 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));

                Assert.Equal(expectedTiposInversiones, model.TiposInversiones, Comparer.Get <TiposInversiones>((p1, p2) => p1.Nombre == p2.Nombre));
                Assert.Equal(expectedAreas, model.Areas, Comparer.Get <Areas>((a1, b2) => a1.Nombre == a1.Nombre));
                Assert.Equal(expectedRating, model.Rating, Comparer.Get <Rating>((r1, r2) => r1.Nombre == r2.Nombre));
                // Check that both collections (expected and result returned) have the same elements with the same name
            }
        }
Esempio n. 2
0
        //SELECT
        //GET : Inversions
        public IActionResult SelectProyectosForInversion(string[] ids_tiposInversiones, string[] ids_areas, string[] ids_rating, int?invMin, float?interes, int?plazo)
        {
            SelectProyectosForInversionViewModel selectProyectos = new SelectProyectosForInversionViewModel();

            selectProyectos.TiposInversiones = _context.TiposInversiones;
            selectProyectos.Areas            = _context.Areas;
            selectProyectos.Rating           = _context.Rating;

            selectProyectos.Proyectos = _context.Proyecto.Include(p => p.Rating).Include(p => p.ProyectoAreas).
                                        ThenInclude <Proyecto, ProyectoAreas, Areas>(p => p.Areas).Include(p => p.ProyectoTiposInversiones).
                                        ThenInclude <Proyecto, ProyectoTiposInversiones, TiposInversiones>(p => p.TiposInversiones).Where(p => p.Plazo != null).Where(p => p.RatingId != null);

            if (ids_tiposInversiones.Length != 0)
            {
                selectProyectos.Proyectos = selectProyectos.Proyectos.Where(p => p.ProyectoTiposInversiones.Any(t1 => ids_tiposInversiones.Contains(t1.TiposInversiones.Nombre)));
            }

            if (ids_areas.Length != 0)
            {
                selectProyectos.Proyectos = selectProyectos.Proyectos.Where(p => p.ProyectoAreas.Any(t1 => ids_areas.Contains(t1.Areas.Nombre)));
            }

            if (ids_rating.Length != 0)
            {
                selectProyectos.Proyectos = selectProyectos.Proyectos.Where(p => ids_rating.Contains(p.Rating.Nombre));
            }

            if (invMin != null)
            {
                selectProyectos.Proyectos = selectProyectos.Proyectos.Where(p => p.MinInversion.CompareTo((float)invMin) >= 0);
            }

            if (interes != null)
            {
                selectProyectos.Proyectos = selectProyectos.Proyectos.Where(p => ((float)p.Interes).CompareTo(interes) >= 0);
            }

            if (plazo != null)
            {
                selectProyectos.Proyectos = selectProyectos.Proyectos.Where(p => ((int)p.Plazo).CompareTo((int)plazo) >= 0);
            }

            selectProyectos.Proyectos.ToList();
            return(View(selectProyectos));
        }
Esempio n. 3
0
        public IActionResult SelectProyectosForInversion(SelectedProyectosForInversionViewModel selectedProyectos)
        {
            if (selectedProyectos.IdsToAdd != null)
            {
                return(RedirectToAction("Create", selectedProyectos));
            }

            //Se mostrará un mensaje de error al usuario para indicar que seleccione algún proyecto
            ModelState.AddModelError(string.Empty, "Debes seleccionar al menos un proyecto para invertir");

            //Se recreará otra vez el View Model
            SelectProyectosForInversionViewModel selectProyectos = new SelectProyectosForInversionViewModel();

            selectProyectos.TiposInversiones = _context.TiposInversiones;
            selectProyectos.Areas            = _context.Areas;
            selectProyectos.Rating           = _context.Rating;

            selectProyectos.Proyectos = _context.Proyecto.Include(p => p.Rating).Include(p => p.ProyectoAreas).
                                        ThenInclude <Proyecto, ProyectoAreas, Areas>(p => p.Areas).Include(p => p.ProyectoTiposInversiones).
                                        ThenInclude <Proyecto, ProyectoTiposInversiones, TiposInversiones>(p => p.TiposInversiones).Where(p => p.Plazo != null).Where(p => p.RatingId != null);

            return(View(selectProyectos));
        }