Esempio n. 1
0
        public async void RewardForNotCompletedContractNotCollected()
        {
            var contractMetaId = "Test_RewardForNotCompletedContractNotCollected";
            var contractReward = new Reward()
            {
                Resources = new List <int> {
                    0, 0, 111
                }
            };
            var contractProductionTime = TimeSpan.FromMinutes(10);
            var buildingMetaId         = "Test_RewardForNotCompletedContractNotCollected";
            var playerId = "Test_RewardForNotCompletedContractNotCollected";

            // Create test contract meta if it doesn't exist.
            var contractMeta = await new ContractMeta(contractMetaId).LoadAsync();

            if (contractMeta == null)
            {
                contractMeta = new ContractMeta(contractMetaId);
                contractMeta.Rewards.Add(contractReward);
                contractMeta.ProductionTime = contractProductionTime;
                await contractMeta.InsertAsync();
            }

            // Create test building meta if it doesn't exist.
            var buildingMeta = await new BuildingMeta(buildingMetaId).LoadAsync();

            if (buildingMeta == null)
            {
                buildingMeta = new BuildingMeta(buildingMetaId);
                buildingMeta.StorageLimit = 1000;
                await buildingMeta.InsertAsync();
            }

            // Create test player and building.
            var building = new Building(buildingMetaId);

            building.IsConstructed  = true;
            building.ProductionTask = new ProductionTask(contractMeta);
            var player = await Helpers.CreateTestPlayer(playerId, building : building);

            // Auth player.
            var sessionToken = Helpers.GetSessionToken(playerId);

            // Mock data.
            var data = JToken.Parse($@"{{
                'PlayerId':'{playerId}',
                'SessionToken':'{sessionToken}',
                'BuildingId':'{building.Id}'
            }}");

            // Execute controller.
            var controller    = new CheckProductionController();
            var responseToken = await controller.HandleHttpRequestAsync(data);

            // Assert controller response status is ContractNotReady.
            Assert.Equal(responseToken["Status"], JStatus.NotReady.JToken["Status"]);

            // Make sure reward is not collected.
            var collectController = new CollectProductionRewardsController();

            responseToken = await collectController.HandleHttpRequestAsync(data);

            player = await player.LoadAsync();

            Assert.True(player.Resources.Count == 0);
        }
Esempio n. 2
0
        public async void CitizenAbilityModifiedProduction()
        {
            var testId         = "Test_CitizenAbilityModifiedProduction";
            var contractReward = new Reward()
            {
                Resources = new List <int> {
                    0, 0, 111
                }
            };
            var contractProductionTime = TimeSpan.FromSeconds(10);

            // Create test contract meta if it doesn't exist.
            var contractMeta = await new ContractMeta(testId).LoadAsync();

            if (contractMeta == null)
            {
                contractMeta = new ContractMeta(testId);
                contractMeta.Rewards.Add(contractReward);
                contractMeta.ProductionTime = contractProductionTime;
                await contractMeta.InsertAsync();
            }

            // Create test building meta if it doesn't exist.
            var buildingMeta = await new BuildingMeta(testId).LoadAsync();

            if (buildingMeta == null)
            {
                buildingMeta = new BuildingMeta(testId);
                buildingMeta.StorageLimit = 1000;
                await buildingMeta.InsertAsync();
            }

            // Create test citizen ability meta if it doesn't exist.
            var abilityMeta = await new CitizenAbilityMeta(testId).LoadAsync();

            if (abilityMeta == null)
            {
                abilityMeta = new CitizenAbilityMeta(testId);
                abilityMeta.ReduceTaskDuration = new List <TimeSpan> {
                    TimeSpan.FromSeconds(9)
                };
                await abilityMeta.InsertAsync();
            }

            // Create test player, building and citizen.
            var building = new Building(testId);

            building.IsConstructed  = true;
            building.ProductionTask = new ProductionTask(contractMeta);
            var player = await Helpers.CreateTestPlayer(testId, building : building);

            var citizen = new Citizen();

            citizen.Abilities.Add(new CitizenAbility(testId));
            player.Citizens.Add(citizen);
            building.AssignedCitizenIds.Add(citizen.Id);
            await player.ReplaceAsync();

            // Wait for contract to complete (contractProductionTime - ReduceTaskDuration + .5f).
            Thread.Sleep(TimeSpan.FromSeconds(1.5f));

            // Auth player.
            var sessionToken = Helpers.GetSessionToken(testId);

            // Mock data.
            var data = JToken.Parse($@"{{
                'PlayerId':'{testId}',
                'SessionToken':'{sessionToken}',
                'BuildingId':'{building.Id}'
            }}");

            // Execute controller.
            var controller    = new CheckProductionController();
            var responseToken = await controller.HandleHttpRequestAsync(data);

            // Assert controller response status is OK.
            Assert.Equal(responseToken["Status"], JStatus.Ok.JToken["Status"]);

            // Test reward collection.
            var collectController    = new CollectProductionRewardsController();
            var collectResponseToken = await collectController.HandleHttpRequestAsync(data);

            Assert.Equal(collectResponseToken["Status"], JStatus.Ok.JToken["Status"]);

            // Make sure reward is added.
            player = await player.LoadAsync();

            Assert.True(player.Resources[2] > 0);
        }