Ejemplo n.º 1
0
        public void Upgrade_UnlockUpgrade_UpgradeUnlocked(UpgradeTestData testData)
        {
            //Arrange
            var dispatcher = this.ServiceProvider.GetRequiredService <IDispatcher>();

            if (testData.InitialAppState != null)
            {
                dispatcher.Dispatch(new SetAppStateAction(testData.InitialAppState));
            }

            var initialAppState = this.ServiceProvider.GetRequiredService <IState <AppState> >().Value;

            //Act
            var upgrade = UpgradeStorage.Upgrades[testData.UpgradeId];

            dispatcher.Dispatch(new UnlockUpgradeAction(upgrade));

            //Assert
            var currentUpgradeState = this.ServiceProvider.GetRequiredService <IState <UpgradeState> >().Value;

            Assert.Contains(testData.UpgradeId, currentUpgradeState.PurchasedUpgradeIds);

            var currentAppState = this.ServiceProvider.GetRequiredService <IState <AppState> >().Value;

            Assert.Equal(initialAppState.Faith - upgrade.Cost, currentAppState.Faith);
        }
Ejemplo n.º 2
0
        public void Upgrade_UnlockUpgrade_UpgradeEffectApplied(UpgradeTestData testData)
        {
            //Arrange
            var dispatcher = this.ServiceProvider.GetRequiredService <IDispatcher>();

            if (testData.InitialAppState != null)
            {
                dispatcher.Dispatch(new SetAppStateAction(testData.InitialAppState));
            }

            var initialMoneyModifier         = this.ServiceProvider.GetRequiredService <UpgradeEffectsSelector>().SelectMoneyPerFollowerIncrease();
            var initialFaithModifier         = this.ServiceProvider.GetRequiredService <UpgradeEffectsSelector>().SelectFaithPerFollowerIncrease();
            var initialFaithPerClickModifier = this.ServiceProvider.GetRequiredService <UpgradeEffectsSelector>().SelectFaithPerClickIncrease();

            //Act
            var upgrade = UpgradeStorage.Upgrades[testData.UpgradeId];

            dispatcher.Dispatch(new UnlockUpgradeAction(upgrade));

            // Asserts
            var currentUpgradeState = this.ServiceProvider.GetRequiredService <IState <UpgradeState> >().Value;

            Assert.Contains(testData.UpgradeId, currentUpgradeState.PurchasedUpgradeIds);

            foreach (var upgradeEffect in upgrade.Effects)
            {
                switch (upgradeEffect)
                {
                case MoneyPerFollowerUpgradeEffect effect:
                    var currentMoneyModifier = this.ServiceProvider.GetRequiredService <UpgradeEffectsSelector>().SelectMoneyPerFollowerIncrease();
                    if (effect.MoneyPerFollowerIncrease != 0)
                    {
                        Assert.NotEqual(initialMoneyModifier, currentMoneyModifier);
                    }
                    Assert.Equal(initialMoneyModifier + effect.MoneyPerFollowerIncrease, currentMoneyModifier);
                    break;

                case FaithPerFollowerUpgradeEffect effect:
                    var currentFaithModifier = this.ServiceProvider.GetRequiredService <UpgradeEffectsSelector>().SelectMoneyPerFollowerIncrease();
                    if (effect.FaithPerFollowerIncrease != 0)
                    {
                        Assert.NotEqual(initialFaithModifier, currentFaithModifier);
                    }
                    Assert.Equal(initialFaithModifier + effect.FaithPerFollowerIncrease, currentFaithModifier);
                    break;

                case FaithPerClickUpgradeEffect effect:
                    var currentFaithPerClickModifier = this.ServiceProvider.GetRequiredService <UpgradeEffectsSelector>().SelectMoneyPerFollowerIncrease();
                    if (effect.FaithPerClickIncrease != 0)
                    {
                        Assert.NotEqual(initialFaithPerClickModifier, currentFaithPerClickModifier);
                    }
                    Assert.Equal(initialFaithPerClickModifier + effect.FaithPerClickIncrease, currentFaithPerClickModifier);
                    break;
                }
            }
        }