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 TestPopulationInSectors()
        {
            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 <Planet> planets = new List <Planet>()
            {
                new Planet()
                {
                    PlanetID = "#1", StarID = "#1", Population = 10
                },
                new Planet()
                {
                    PlanetID = "#2", StarID = "#1", Population = 20
                },
                new Planet()
                {
                    PlanetID = "#3", StarID = "#2", Population = 30
                },
                new Planet()
                {
                    PlanetID = "#4", StarID = "#3", Population = 40
                },
                new Planet()
                {
                    PlanetID = "#5", StarID = "#4", Population = 50
                },
            };

            List <Star> stars = new List <Star>()
            {
                new Star()
                {
                    StarID = "#1", SystemID = "#1", Planets = new Planet[] { planets[0], planets[1] }
                },
                new Star()
                {
                    StarID = "#2", SystemID = "#2", Planets = new Planet[] { planets[2] }
                },
                new Star()
                {
                    StarID = "#3", SystemID = "#2", Planets = new Planet[] { planets[3] }
                },
                new Star()
                {
                    StarID = "#4", SystemID = "#3", Planets = new Planet[] { planets[4] }
                },
            };

            List <Models.System> systems = new List <Models.System>()
            {
                new Models.System()
                {
                    SystemID = "#1", SectorName = "A",
                    Stars    = new Star[] { stars[0] }
                },
                new Models.System()
                {
                    SystemID = "#2", SectorName = "A",
                    Stars    = new Star[] { stars[1], stars[2] }
                },
                new Models.System()
                {
                    SystemID = "#3", SectorName = "B",
                    Stars    = new Star[] { stars[3] }
                }
            };

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

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

            var result = logic.PopulationInSectors();

            Assert.That(result.Single(x => x.SectorType == "A").Population, Is.EqualTo(100));
            Assert.That(result.Single(x => x.SectorType == "B").Population, Is.EqualTo(50));
            systemRepo.Verify(r => r.Read(), Times.Once);
            starRepo.Verify(r => r.Read(), Times.Once);
            planetRepo.Verify(r => r.Read(), Times.Once);
        }