示例#1
0
        public async void UnavailableContractNotSelected()
        {
            var requiredBuildingMetaId = "Test_UnavailableContractNotSelected_Required";
            var buildingMetaId         = "Test_UnavailableContractNotSelected";
            var contractMetaId         = "Test_UnavailableContractNotSelected";
            var playerId = "Test_UnavailableContractNotSelected";

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

            if (requiredBuildingMeta == null)
            {
                requiredBuildingMeta = new BuildingMeta(requiredBuildingMetaId);
                await requiredBuildingMeta.InsertAsync();
            }

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

            if (buildingMeta == null)
            {
                buildingMeta = new BuildingMeta(buildingMetaId);
                buildingMeta.AvailableContractMetaIds = new List <string> {
                    contractMetaId
                };
                await buildingMeta.InsertAsync();
            }

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

            if (contractMeta == null)
            {
                contractMeta             = new ContractMeta(contractMetaId);
                contractMeta.Requirement = new Requirement()
                {
                    BuildingMetaIds = new List <string> {
                        requiredBuildingMetaId
                    }
                };
                await contractMeta.InsertAsync();
            }

            // Create test player with 'wrong' building.
            var building = new Building(buildingMetaId);

            building.IsConstructed = true;
            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}',
                'ContractMetaId':'{contractMetaId}'
            }}");

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

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

            // Make sure contract is not selected.
            player = await player.LoadAsync();

            Assert.Null(player.GetBuildingById(building.Id).ProductionTask);
        }
示例#2
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);
        }