Example #1
0
        //non crud
        public IActionResult Stats()
        {
            Stats s = new Stats();


            s.StarsWithLife       = statsLogic.StarsWithLife();
            s.PopulationInSectors = statsLogic.PopulationInSectors();
            s.PlanetTypeGrouped   = statsLogic.PlanetTypeGrouped();
            return(View(s));
        }
Example #2
0
        public void TestStarsWithLife()
        {
            Mock <IRepository <Planet> >        planetRepo = new Mock <IRepository <Planet> >();
            Mock <IRepository <Star> >          starRepo   = new Mock <IRepository <Star> >();
            Mock <IRepository <Models.System> > systemRepo = new Mock <IRepository <Models.System> >();

            List <Star> stars = new List <Star>()
            {
                new Star()
                {
                    StarID = "#1"
                },
                new Star()
                {
                    StarID = "#2"
                },
                new Star()
                {
                    StarID = "#3"
                },
            };

            List <Star> expected = new List <Star>()
            {
                new Star()
                {
                    StarID = "#1"
                },
                new Star()
                {
                    StarID = "#2"
                },
            };


            List <Planet> planets = new List <Planet>()
            {
                new Planet()
                {
                    PlanetID = "#1", Habitable = true, StarID = "#1"
                },
                new Planet()
                {
                    PlanetID = "#2", Habitable = false, StarID = "#1"
                },
                new Planet()
                {
                    PlanetID = "#3", Habitable = false, StarID = "#2"
                },
                new Planet()
                {
                    PlanetID = "#4", Habitable = false, StarID = "#2"
                },
                new Planet()
                {
                    PlanetID = "#5", Habitable = true, StarID = "#2"
                },
            };

            planetRepo.Setup(r => r.Read()).Returns(planets.AsQueryable());
            starRepo.Setup(r => r.Read()).Returns(stars.AsQueryable());

            StatsLogic logic = new StatsLogic(planetRepo.Object, starRepo.Object, systemRepo.Object);

            var result = logic.StarsWithLife();

            Assert.That(result, Is.EquivalentTo(expected));
            starRepo.Verify(r => r.Read(), Times.Once);
            planetRepo.Verify(r => r.Read(), Times.Once);
        }