コード例 #1
0
        public void GenerateSettlement_InvalidCode_Throws()
        {
            var mockRng               = RandomizationHelper.CreateMockRandomNumberGenerator();
            var mockRepo              = new Mock <ISettlementRepository>();
            var generator             = new SettlementGenerator(mockRepo.Object, mockRng.Object);
            var mockBuildingGenerator = new Mock <IBuildingNameGenerator>();

            Assert.ThrowsAsync <ArgumentException>(() => generator.GenerateSettlement(_fixture.Create <string>(), mockBuildingGenerator.Object));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: joemspalding/chrisApp1
        static void Main(string[] args)
        {
            UserGenerator       dbGenerator      = new UserGenerator();
            RandomizationHelper stringRandomizer = new RandomizationHelper();

            Console.WriteLine(dbGenerator.GetString());
            Console.WriteLine(stringRandomizer.GetRandomString(5));
            Console.WriteLine(stringRandomizer.GetRandomInt(5));
            Console.WriteLine(stringRandomizer.GetKEYSMASH(25));
        }
コード例 #3
0
        public async Task GenerateSettlement_ValidCode_GeneratesSettlement()
        {
            var mockRng = RandomizationHelper.CreateMockRandomNumberGenerator();

            var mockRepo   = new Mock <ISettlementRepository>();
            var settlement = _fixture.Create <SettlementTypeDetails>();

            mockRepo.Setup(x => x.GetSettlement(settlement.Code)).ReturnsAsync(settlement);

            var buildingTypes = _fixture.CreateMany <BuildingTypeModel>(settlement.Buildings.Count()).ToArray();

            for (int i = 0; i < settlement.Buildings.Count(); i++)
            {
                settlement.Buildings[i].BuildingTypeId = i + 10;
                buildingTypes[i].Id = i + 10;
            }

            var mockBuildingGenerator = new Mock <IBuildingNameGenerator>();

            mockBuildingGenerator.Setup(x => x.ListBuildingTypes()).ReturnsAsync(buildingTypes);

            mockBuildingGenerator.Setup(x => x.GenerateBuildingName(It.IsAny <string>()))
            .Returns <string>((code) => Task.Run(() =>
                                                 _fixture.Build <BuildingNameResultModel>()
                                                 .With(x => x.BuildingTypeCode, code)
                                                 .Create()));

            var generator = new SettlementGenerator(mockRepo.Object, mockRng.Object);
            var result    = await generator.GenerateSettlement(settlement.Code, mockBuildingGenerator.Object);

            // Assert general result
            Assert.NotNull(result);
            Assert.AreEqual(settlement.Code, result.Code);
            Assert.AreEqual(settlement.Id, result.Id);
            Assert.AreEqual(settlement.Name, result.Name);
            mockRng.Verify(x => x.GetRandomInteger(settlement.MinSize, settlement.MaxSize), Times.AtLeastOnce);
            Assert.GreaterOrEqual(result.Population, Math.Min(settlement.MinSize, settlement.MaxSize));
            Assert.LessOrEqual(result.Population, Math.Max(settlement.MinSize, settlement.MaxSize));
            Assert.AreEqual(settlement.Buildings.Count(), result.Buildings.Count());

            // Assert buildings created
            foreach (var settlmentBuilding in settlement.Buildings)
            {
                var resultBuilding = result.Buildings.First(x => x.Key.Id == settlmentBuilding.BuildingTypeId);
                Assert.AreEqual(settlmentBuilding.MinBuildings, resultBuilding.Value.Count());

                var expectedBuildingType = buildingTypes.First(x => x.Id == settlmentBuilding.BuildingTypeId);
                Assert.AreEqual(expectedBuildingType.Code, resultBuilding.Key.Code);

                mockRng.Verify(x => x.GetRandomInteger(settlmentBuilding.MinBuildings, settlmentBuilding.MaxBuildings), Times.AtLeastOnce);
                Assert.GreaterOrEqual(resultBuilding.Value.Count, Math.Min(settlmentBuilding.MinBuildings, settlmentBuilding.MaxBuildings));
                Assert.LessOrEqual(resultBuilding.Value.Count, Math.Max(settlmentBuilding.MinBuildings, settlmentBuilding.MaxBuildings));
            }
        }
コード例 #4
0
        public async Task ListSettlementTypes_EmptyList_ReturnsEmptyArray()
        {
            var mockRng  = RandomizationHelper.CreateMockRandomNumberGenerator();
            var mockRepo = new Mock <ISettlementRepository>();

            var generator = new SettlementGenerator(mockRepo.Object, mockRng.Object);
            var result    = await generator.ListSettlementTypes();

            mockRepo.Verify(x => x.ListSettlementTypes(), Times.Once);
            mockRepo.VerifyNoOtherCalls();
            Assert.NotNull(result);
            Assert.AreEqual(0, result.Count());
        }
コード例 #5
0
        public async Task PlayerList()
        {
            List <Player> participants = await RandomizationHelper.GetPlayersInTourney((await DatabaseHelper.GetLatestTourneyAsync()).ID);

            string participantString = "Discord Username - Showdown Username\n\n";

            foreach (Player player in participants)
            {
                participantString += $"{player.DiscordName} - {player.ShowdownName}\n";
            }

            await Context.Channel.SendMessageAsync($"**Full Player List:**\n```{participantString}```");
        }
コード例 #6
0
        public async Task ListSettlementTypes_GivenData_ReturnsArray()
        {
            var mockRng = RandomizationHelper.CreateMockRandomNumberGenerator();

            var mockRepo        = new Mock <ISettlementRepository>();
            var testSettlements = _fixture.CreateMany <SettlementTypeModel>().ToArray();

            mockRepo.Setup(x => x.ListSettlementTypes()).ReturnsAsync(testSettlements);

            var generator = new SettlementGenerator(mockRepo.Object, mockRng.Object);
            var result    = await generator.ListSettlementTypes();

            mockRepo.Verify(x => x.ListSettlementTypes(), Times.Once);
            mockRepo.VerifyNoOtherCalls();
            Assert.NotNull(result);
            Assert.Greater(result.Count(), 0);
            Assert.AreEqual(testSettlements, result);
        }
コード例 #7
0
        public async Task StartTourney(int tid)
        {
            await Context.Channel.SendMessageAsync("", false, new EmbedBuilder()
            {
                Title = "Starting Tourney...", Color = Color.LightOrange, Description = $"Starting tourney with id {tid} please wait a moment."
            });

            if (await(await RandomizationHelper.GetPlayersInTourney(tid)).GenerateRandomBrackets(tid))
            {
                await Context.Channel.SendMessageAsync("", false, new EmbedBuilder()
                {
                    Title = "Tourney Started", Color = Color.Green, Description = $"The tourney has begun. Posting brackets..."
                });
            }
            else
            {
                await Context.Channel.SendMessageAsync("", false, new EmbedBuilder()
                {
                    Title = "Tourney Failed to Start", Color = Color.DarkRed, Description = $"Error. Please contact an admin."
                });
            }
        }