Esempio n. 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));
        }
Esempio n. 2
0
        public void TestPlanetTypeGrouped()
        {
            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", PlanetType = PlanetType.Terran
                },
                new Planet()
                {
                    PlanetID = "#2", StarID = "#1", PlanetType = PlanetType.Terran
                },
                new Planet()
                {
                    PlanetID = "#3", StarID = "#2", PlanetType = PlanetType.Jovian
                },
                new Planet()
                {
                    PlanetID = "#4", StarID = "#3", PlanetType = PlanetType.Neptunian
                },
                new Planet()
                {
                    PlanetID = "#5", StarID = "#4", PlanetType = PlanetType.Subterran
                },
            };

            List <Star> stars = new List <Star>()
            {
                new Star()
                {
                    StarID = "#1", Age = 1500000
                },
                new Star()
                {
                    StarID = "#2", Age = 800000
                },
                new Star()
                {
                    StarID = "#3", Age = 1000001
                },
                new Star()
                {
                    StarID = "#4", Age = 999999
                },
            };


            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.PlanetTypeGrouped();

            Assert.That(result.Single(x => x.Type == PlanetType.Terran).NumberOfStars, Is.EqualTo(1));
            Assert.That(result.Single(x => x.Type == PlanetType.Neptunian).NumberOfStars, Is.EqualTo(1));
            starRepo.Verify(r => r.Read(), Times.Once);
            planetRepo.Verify(r => r.Read(), Times.Once);
        }