Ejemplo n.º 1
0
        private GameContext GetTestContext(string testDb)
        {
            //Prep a context and controller
            GameContext gameContext = new GameContext(InMemoryContextFactory.GetContextOptions(testDb));

            //Add the civilization seed data
            gameContext.Civs.Add(new Civ {
                Id             = 1,
                Name           = "test",
                AstStone       = 4,
                AstEarlyBronze = 7,
                AstLateBronze  = 10,
                AstEarlyIron   = 13,
                AstLateIron    = 16
            });

            //Add a sample activeCiv
            gameContext.ActiveCivs.Add(new ActiveCiv {
                Id           = 1,
                CivId        = 1,
                GameName     = "controller unit test",
                CurrentPhase = (int)ActiveCiv.Phases.TaxToSupport
            });

            gameContext.SaveChanges();

            return(gameContext);
        }
Ejemplo n.º 2
0
        public void CanCheckForGameEnd(int astPosition, bool expectedResult, int expectedPhase)
        {
            //Prep the context
            DbContextOptions <GameContext> options = InMemoryContextFactory.GetContextOptions("game_end");
            GameContext context = new GameContext(options);

            //Create an active civ
            ActiveCiv activeCiv = context.ActiveCivs
                                  .Add(new ActiveCiv
            {
                CurrentPhase = (int)ActiveCiv.Phases.MoveAST,
                Civ          = new Civ {
                    AstLateIron = 16
                },
                AstPosition = astPosition,
            })
                                  .Entity;

            context.SaveChanges();

            //Make the game loop
            GameLoop testLoop = new GameLoop(context, activeCiv.Id);

            //Act
            bool actualResult = testLoop.CheckForGameEnd();

            //Assert
            Assert.Equal(expectedResult, actualResult);
            Assert.Equal(expectedPhase, testLoop.ActiveCiv.CurrentPhase);
        }
Ejemplo n.º 3
0
        public void CanResolveCalculateSpendLimit(int treasury, Commodity[] commodities, int expectedSpendLimit)
        {
            int expectedPhase = (int)ActiveCiv.Phases.BuyAdvances;

            //Prep the context
            DbContextOptions <GameContext> options = InMemoryContextFactory.GetContextOptions("calculate_spend_limit");
            GameContext context = new GameContext(options);

            //Create an active civ
            ActiveCiv activeCiv = context.ActiveCivs
                                  .Add(new ActiveCiv {
                OwnedAdvancements = new Collection <OwnedAdvancement> {
                }
            })
                                  .Entity;

            context.SaveChanges();

            //Make the game loop
            GameLoop testLoop = new GameLoop(context, activeCiv.Id);

            //Act
            testLoop.ResolveCalculateSpendLimit(treasury, commodities);

            //Assert
            Assert.Equal(expectedSpendLimit, testLoop.ActiveCiv.SpendLimit);
            Assert.Equal(expectedPhase, testLoop.ActiveCiv.CurrentPhase);
        }
Ejemplo n.º 4
0
        public void CanResolveMoveAst(int astPosition, int cities, int expectedResult)
        {
            //Prep the context
            DbContextOptions <GameContext> options = InMemoryContextFactory.GetContextOptions("move_ast");
            GameContext context = new GameContext(options);

            //Create an active civ
            ActiveCiv activeCiv = context.ActiveCivs
                                  .Add(new ActiveCiv {
                Civ = new Civ {
                    AstStone = 5, AstEarlyBronze = 8, AstLateBronze = 11, AstEarlyIron = 14, AstLateIron = 16
                },
                Cities            = cities,
                AstPosition       = astPosition,
                OwnedAdvancements = new Collection <OwnedAdvancement> {
                }
            })
                                  .Entity;

            context.SaveChanges();

            //Make the game loop
            GameLoop testLoop = new GameLoop(context, activeCiv.Id);

            //Act
            int actualResult = testLoop.ResolveMoveAst();

            //Assert
            Assert.Equal(expectedResult, actualResult);
        }
Ejemplo n.º 5
0
        public void CanCheckPlayerCanAffordAdvancements(string dbString, int spendLimit, int[] advancements, bool expectedResult)
        {
            //Prep the context
            DbContextOptions <GameContext> options = InMemoryContextFactory.GetContextOptions(dbString);
            GameContext context = new GameContext(options);

            //Add advancements
            foreach (int advancementId in advancements)
            {
                context.Advancements.Add(new Advancement {
                    Id = advancementId, BaseCost = 50
                });
            }

            //Create an active civ
            ActiveCiv activeCiv = context.ActiveCivs
                                  .Add(new ActiveCiv {
                SpendLimit = spendLimit, OwnedAdvancements = new Collection <OwnedAdvancement> {
                }
            })
                                  .Entity;

            context.SaveChanges();

            //Make the game loop
            GameLoop testLoop = new GameLoop(context, activeCiv.Id);

            //Act
            bool actualResult = testLoop.CheckPlayerCanAffordAdvancements(advancements);

            //Assert
            Assert.Equal(expectedResult, actualResult);
        }
Ejemplo n.º 6
0
        public void CanResolveTaxToSupport()
        {
            int expectedCities = 4;
            int expectedPhase  = (int)ActiveCiv.Phases.CalculateSpendLimit;

            //Prep the context
            DbContextOptions <GameContext> options = InMemoryContextFactory.GetContextOptions("Tax_to_support");
            GameContext context = new GameContext(options);

            //Create an active civ
            ActiveCiv activeCiv = context.ActiveCivs
                                  .Add(new ActiveCiv {
                OwnedAdvancements = new Collection <OwnedAdvancement> {
                }
            })
                                  .Entity;

            context.SaveChanges();

            //Make the game loop
            GameLoop testLoop = new GameLoop(context, activeCiv.Id);

            //Act
            testLoop.ResolveTaxToSupport(expectedCities);

            //Assert
            Assert.Equal(expectedCities, testLoop.ActiveCiv.Cities);
            Assert.Equal(expectedPhase, testLoop.ActiveCiv.CurrentPhase);
        }
        private GameContext GetTestContext(string testDb)
        {
            //Prep a context and controller
            GameContext gameContext = new GameContext(InMemoryContextFactory.GetContextOptions(testDb));

            foreach (Advancement advancement in Iteration1Seeder.GetSeedAdvancements())
            {
                gameContext.Advancements.Add(advancement);
            }
            gameContext.SaveChanges();

            return(gameContext);
        }
        private GameContext GetTestContext(string testDb)
        {
            //Prep a context and controller
            GameContext gameContext = new GameContext(InMemoryContextFactory.GetContextOptions(testDb));

            //Add the civilization seed data
            foreach (Civ civ in Iteration1Seeder.GetSeedCivilizations())
            {
                gameContext.Civs.Add(civ);
            }

            //Add a sample activeCiv
            gameContext.ActiveCivs.Add(new ActiveCiv {
                Id = 1, CivId = 4, GameName = "controller unit test"
            });

            gameContext.SaveChanges();

            return(gameContext);
        }
Ejemplo n.º 9
0
        public void CanResolveBuyAdvances(string dbString, int[] newAdvances, int[] existingAdvances, bool expectedAffordability)
        {
            int expectedPhase = (int)ActiveCiv.Phases.MoveAST;

            //Build the list of expected advancements after purchase
            List <int> expectedAdvancements = new List <int>(existingAdvances);

            if (expectedAffordability)
            {
                foreach (int newAdvance in newAdvances)
                {
                    expectedAdvancements.Add(newAdvance);
                }
            }

            //Prep the context
            DbContextOptions <GameContext> options = InMemoryContextFactory.GetContextOptions(dbString);
            GameContext context = new GameContext(options);

            //Add advancements
            foreach (int advancementId in newAdvances)
            {
                context.Advancements.Add(new Advancement {
                    Id = advancementId, BaseCost = 50
                });
            }
            foreach (int advancementId in existingAdvances)
            {
                context.Advancements.Add(new Advancement {
                    Id = advancementId, BaseCost = 50
                });
            }

            //Create an active civ
            ActiveCiv activeCiv = context.ActiveCivs
                                  .Add(new ActiveCiv {
                SpendLimit = 100, OwnedAdvancements = new Collection <OwnedAdvancement> {
                }
            })
                                  .Entity;

            //Add the existing advancements to the active civ and build the list of expected advancements after buying the new ones
            foreach (int existingAdvance in existingAdvances)
            {
                activeCiv.OwnedAdvancements.Add(new OwnedAdvancement {
                    AdvancementId = existingAdvance
                });
            }
            context.SaveChanges();

            //Make the game loop
            GameLoop testLoop = new GameLoop(context, activeCiv.Id);

            //Act
            bool result = testLoop.ResolveBuyAdvances(newAdvances);

            //Assert

            //Assert that the advances were bought (or not) as expected
            Assert.Equal(expectedAffordability, result);

            //Assert correct phase
            Assert.Equal(expectedPhase, testLoop.ActiveCiv.CurrentPhase);
            //Assert expected number of owned advancements
            Assert.Equal(expectedAdvancements.Count, testLoop.ActiveCiv.OwnedAdvancements.Count);

            /* Assert that all of the expected owned advancements are present
             * (and with the previous assertion, only those advancements)
             */
            foreach (int expectedAdvancementId in expectedAdvancements)
            {
                Assert.Equal(
                    expectedAdvancementId,
                    testLoop.ActiveCiv.OwnedAdvancements.Single(a => a.AdvancementId == expectedAdvancementId).AdvancementId
                    );
            }
        }