Beispiel #1
0
        public void TestWithDeathCause()
        {
            var sut = new MatchBuilder();
            var m   = sut.WithDeathCause("Player").WithKills(0).WithRank(1).WithScore(1).Build();

            Assert.AreEqual("Player", m.DeathCause);
        }
        public void Match_Invoice_Test()
        {
            var fortKnox = FortKnox.Instance();

            var invoices = fortKnox.ExportInvoices();

            Assert.Empty(invoices);

            var memberFactory = new MemberFactory(400);
            var member1       = memberFactory.CreateMember("Test1", "1", true);
            var member2       = memberFactory.CreateMember("Test2", "2", true);

            var matchDirector = new MatchDirector();
            var matchBuilder  = new MatchBuilder(100);

            matchDirector.Construct(matchBuilder, member1, member2);

            var expectedInvoice1 = "Name: " + member1.Name + " Address: " + member1.Address + " Amount: " + 100;
            var expectedInvoice2 = "Name: " + member2.Name + " Address: " + member2.Address + " Amount: " + 100;

            invoices = fortKnox.ExportInvoices();

            Assert.Contains(expectedInvoice1, invoices);
            Assert.Contains(expectedInvoice2, invoices);
        }
        private static void Main()
        {
            Console.SetWindowSize(120, 40);
            Console.SetBufferSize(120, 1000);

            var match = new MatchBuilder {
                Games = 10
            };

            match.Teams.Add(
                RobotBuilder.FromFile(@"C:\Program Files (x86)\Robot Battle\fire.prg"),
                RobotBuilder.FromFile(@"C:\Program Files (x86)\Robot Battle\fire.prg"),
                RobotBuilder.FromFile(@"C:\Program Files (x86)\Robot Battle\fire.prg")
                );
            match.Teams.Add(
                RobotBuilder.FromFile(@"C:\Program Files (x86)\Robot Battle\fire.prg"),
                RobotBuilder.FromFile(@"C:\Program Files (x86)\Robot Battle\fire.prg")
                );
            using (var writer = XmlWriter.Create(Console.Out, new XmlWriterSettings {
                Indent = true
            })) {
                match.ToXml().WriteTo(writer);
            }
            Console.WriteLine();
            var runner = new MatchRunner(match);
            var result = runner.Run();

            using (var writer = XmlWriter.Create(Console.Out, new XmlWriterSettings {
                Indent = true
            })) {
                result.ToXml().WriteTo(writer);
            }
            Console.ReadKey();
        }
Beispiel #4
0
        public IActionResult SetStartTime()
        {
            var matches = MatchBuilder.SetStartTimeForAllMatches(_matchService);

            _matchService.UpdateRange(matches);
            _matchService.SaveChanges();

            return(Ok());
        }
        public void Given_A_Match_object_handler_has_been_added_When_adding_handler_Then_it_fails()
        {
            var builder = new MatchBuilder(new DummyCompiler <object>());

            builder.Match <object>(_ => { });

            //As we have added a handler that matches everything, adding another handler is pointless, so
            //the builder should throw an exception.
            Assert.Throws <InvalidOperationException>(() => ((Action)(() => builder.Match <object>(_ => { })))());
        }
        public void Given_A_Match_object_with_predicate_handler_has_been_added_When_adding_handler_Then_it_succeeds()
        {
            var builder = new MatchBuilder(new DummyCompiler <object>());

            builder.Match <object>(_ => { }, _ => true);

            //Although we have added a handler that matches objects, the predicate makes it uncertain if all objects matches
            //so adding a handler is ok.
            builder.Match <object>(_ => { });
        }
        public void OneWordForTeamAnOneDigitForResultShouldGiveCorrectMatch()
        {
            MatchBuilder matchBuilder = new MatchBuilder();
            FootballMatch matchResult = matchBuilder.ConstructMatch("Poland - Germany 2:0");

            Assert.AreEqual(matchResult.HostTeam, "Poland");
            Assert.AreEqual(matchResult.GuestTeam, "Germany");
            Assert.AreEqual(matchResult.NumberOfGoalsScoredByHosts, 2);
            Assert.AreEqual(matchResult.NumberOfGoalsScoredByGuests, 0);
        }
Beispiel #8
0
            public virtual string CreateMatching
            (
                string sourceTable,
                ColumnInfo column,
                IQueryInfo queryInfo,
                IList <string> matchValues
            )
            {
                if ((null != matchValues) && (matchValues.Count != 0))
                {
                    MatchBuilder matchBuilder = new MatchBuilder( );

                    if (column.IsDateTime && matchValues.Count >= 2)
                    {
                        matchBuilder.Column(column).GreaterThanOrEqual( ).Value(matchValues [0]).And( ).
                        Column(column).LessThanOrEqual( ).Value(matchValues [1]);
                    }
                    else
                    {
                        for (int valueIndex = 0; valueIndex < matchValues.Count; valueIndex++)
                        {
                            string stringValue = matchValues[valueIndex];

                            if (string.IsNullOrWhiteSpace(stringValue))
                            {
                                continue;
                            }

                            matchBuilder.Column(column);

                            //TODO:??
                            //if ( queryInfo.)
                            if (queryInfo.ExactMatch)
                            {
                                matchBuilder.Equals( );
                            }
                            else
                            {
                                matchBuilder.Like( );
                            }

                            matchBuilder.Value(stringValue);

                            if (valueIndex != matchValues.Count - 1)
                            {
                                matchBuilder.Or( );
                            }
                        }
                    }

                    return(matchBuilder.Match.ToString( ));
                }

                return("");
            }
        public void Given_builder_has_built_When_adding_handler_Then_it_fails()
        {
            var builder = new MatchBuilder(new DummyCompiler <object>());

            builder.Match <object>(_ => { });
            builder.Build();

            //As we have built, no more handlers should be accepted
            Assert.Throws <InvalidOperationException>(() => ((Action)(() => builder.Match <string>(_ => { })))());
            Assert.Throws <InvalidOperationException>(() => ((Action)(() => builder.MatchAny(_ => { })))());
        }
Beispiel #10
0
        public void TestWithMinimalInput()
        {
            var sut = new MatchBuilder();
            var m   = sut.WithKills(1).WithRank(47).WithScore(128).Build();

            Assert.AreEqual(GameMode.Solo, m.Mode);
            Assert.AreEqual(GamePerspective.FPP, m.Perspective);
            Assert.AreEqual(1, m.Kills);
            Assert.AreEqual(47, m.Rank);
            Assert.AreEqual(128, m.Score);
        }
Beispiel #11
0
        private BsonDocument GetMatchDocument(ActionsChartConfiguration chartConfiguration)
        {
            var matchBuilder = new MatchBuilder();

            matchBuilder.BuildClause("ActionStart", chartConfiguration.SelectedActionStart, MatchType.DateRange);
            matchBuilder.BuildClause("ActionType", chartConfiguration.SelectedActionTypes, MatchType.Integer);
            matchBuilder.BuildClause("UserId", chartConfiguration.SelectedUserIDs, MatchType.Integer);
            matchBuilder.BuildClause("EarnType", chartConfiguration.SelectedEarnTypes, MatchType.Integer);
            matchBuilder.BuildClause("IP", chartConfiguration.SelectedIPS, MatchType.String);
            matchBuilder.BuildClause("StartDate", chartConfiguration.SelectedStartDate, MatchType.DateRange);

            return(matchBuilder.Document);
        }
Beispiel #12
0
        private IAggregateFluent <BsonDocument> GetDefaultReportColumnQuery(string matchClauseName, int[] matchValues, string resultValue)
        {
            var matchBuilder = new MatchBuilder();
            var groupBuilder = new GroupBuilder();

            matchBuilder.BuildClause(matchClauseName, matchValues, MatchType.Integer);
            groupBuilder.BuildIdClause("'_id'", "'$UserId'");
            groupBuilder.BuildResultClause("$sum", resultValue);

            return(GetCollection().Aggregate()
                   .Match(matchBuilder.Document)
                   .Group(groupBuilder.Document));
        }
Beispiel #13
0
        public IActionResult GenerateCups([FromRoute] int level)
        {
            var tournaments = TournamentsBuilder.GetCups(level, _clubService);

            foreach (var tournament in tournaments)
            {
                tournament.Matches = MatchBuilder.GetCupMatches(tournament).ToList();
            }

            _tournamentService.InsertRange(tournaments);
            _tournamentService.SaveChanges();

            return(Ok());
        }
Beispiel #14
0
        public void  Match_Draw_Test()
        {
            var memberFactory = new MemberFactory(400);
            var member1       = memberFactory.CreateMember("Test", "Test street 1", true);
            var member2       = memberFactory.CreateMember("tester", "tester street 55", true);
            var matchDirector = new MatchDirector();
            var matchBuilder  = new MatchBuilder(100);

            matchDirector.Construct(matchBuilder, member1, member2);
            var testMatch = matchBuilder.GetResult();

            testMatch.SetPlayerOneScore(100, 100, 100);
            testMatch.SetPlayerTwoScore(100, 100, 100);

            Assert.Null(testMatch.GetWinner());
            Assert.Null(testMatch.GetLoser());
        }
        public void Year_Champion_Not_Enough_Matches_Test()
        {
            var resultManager = ResultManager.Instance();
            var memberFactory = new MemberFactory(400);
            var member1       = memberFactory.CreateMember("Test", "Test street 1", true);
            var member2       = memberFactory.CreateMember("tester", "tester street 55", true);
            var matchDirector = new MatchDirector();
            var matchBuilder  = new MatchBuilder(100);

            for (var i = 0; i < 9; i++)
            {
                matchDirector.Construct(matchBuilder, member1, member2);
                matchBuilder.GetResult().SetPlayerOneScore(50, 50, 50);
                matchBuilder.GetResult().SetPlayerTwoScore(100, 100, 100);
            }

            Assert.Null(resultManager.GetYearChampion(DateTime.Now));
        }
Beispiel #16
0
        public IMatch Import(string input)
        {
            TextReader      r = new StringReader(input);
            TextFieldParser p = new TextFieldParser(r);

            p.Delimiters = new[] { "," };
            p.HasFieldsEnclosedInQuotes = true;
            string[] fields = p.ReadFields();
            if (fields == null || fields.Length != _propertyMap.Length)
            {
                throw new ArgumentException(string.Format("CSV line contains incorrect number of expected fields: Expected {0} but contains {1}", _propertyMap.Length, fields != null ? fields.Length : 0));
            }
            IMatchBuilder builder = new MatchBuilder().WithSeason(_season).WithMode(_mode).WithPerspective(_perspective);

            for (int i = 0; i < fields.Length; i++)
            {
                builder = _propertyMap[i](builder, fields[i]);
            }
            return(builder.Build());
        }
        private void TestSignature <T>(Action <MatchBuilder <T> > build1, Action <MatchBuilder <T> > build2, bool signaturesShouldMatch)
        {
            var compiler1 = new DummyCompiler <T>();
            var compiler2 = new DummyCompiler <T>();
            var builder1  = new MatchBuilder <T>(compiler1);
            var builder2  = new MatchBuilder <T>(compiler2);

            build1(builder1);
            build2(builder2);
            builder1.Build();
            builder2.Build();
            var signature1 = compiler1.Signature;
            var signature2 = compiler2.Signature;

            if (signaturesShouldMatch)
            {
                Assert.Equal(signature1, signature2);
            }
            else
            {
                Assert.NotEqual(signature1, signature2);
            }
        }
Beispiel #18
0
 /// <summary>
 /// Update/submit the score(s) for a match.
 /// </summary>
 /// <remarks>
 /// If you're updating <see cref="Match.WinnerId"/>, <see cref="Match.ScoresCsv"/> must also be
 /// provided. You may, however, update <see cref="Match.ScoresCsv"/> without providing
 /// <see cref="Match.WinnerId"/> for live score updates.
 /// If you change the outcome of a completed match, all matches in the bracket that
 /// branch from the updated match will be reset.
 /// </remarks>
 /// <param name="tournament">Tournament ID (e.g. 10230) or URL (e.g. 'single_elim' for
 /// challonge.com/single_elim). If assigned to a subdomain, URL format must be
 /// subdomain-tournamentUrl (e.g. 'test-mytourney' for test.challonge.com/mytourney) </param>
 /// <param name="matchId">The match's unique id</param>
 /// <param name="builder">The updated version of the match</param>
 /// <returns></returns>
 public async Task <Match> UpdateMatchAsync(string tournament, int matchId, MatchBuilder builder)
 {
     return(await UpdateMatchAsync(tournament, matchId, builder.ScoresCsv, builder.WinnerId,
                                   builder.Player1Votes, builder.Player2Votes));
 }
Beispiel #19
0
        private static void Fight(Dictionary <string, ISignal> players)
        {
            string output = new MatchBuilder().Build(players);

            Console.WriteLine(output);
        }
Beispiel #20
0
 private PartialAction <object> BuildNewReceiveHandler(MatchBuilder matchBuilder)
 {
     return(matchBuilder.Build());
 }
        public void Given_an_IEnumerable_MatchBuilder_When_trying_to_match_a_type_that_is_an_IEnumerable_Then_it_succeeds()
        {
            var builder = new MatchBuilder <IEnumerable>(new DummyCompiler <IEnumerable>());

            builder.Match(typeof(List <string>), _ => { });
        }
        public void Given_an_IEnumerable_MatchBuilder_When_trying_to_match_a_type_that_is_not_an_IEnumerable_Then_it_fails()
        {
            var builder = new MatchBuilder <IEnumerable>(new DummyCompiler <IEnumerable>());

            Assert.Throws <ArgumentException>(() => ((Action)(() => builder.Match(typeof(int), _ => { })))());
        }
Beispiel #23
0
        static void Main(string[] args)
        {
            var memberFactory = new MemberFactory(400);

            for (var i = 0; i < 11; i++)
            {
                memberFactory.CreateMember("TestMember" + i, "Test Street" + i, true);
            }

            var competitionFactory = new CompetitionFactory();
            var testCompetition    = competitionFactory.CreateCompetition("Test Competition", DateTime.Now, DateTime.Now.AddDays(7), 150);


            var matchDirector           = new MatchDirector();
            var testCupGameMatchBuilder = new CompetitionMatchBuilder(testCompetition, 100);

            Console.WriteLine("Competition games");
            for (var j = 0; j < 11; j++)
            {
                for (var i = j + 1; i < 11; i++)
                {
                    var player   = ResultManager.Instance().Members[j];
                    var opponent = ResultManager.Instance().Members[i];

                    matchDirector.Construct(testCupGameMatchBuilder, player, opponent);
                    testCupGameMatchBuilder.GetResult().GeneratePlayerScores();
                }
            }


            Console.WriteLine();
            Console.WriteLine("Champion playing games...");
            var champ = memberFactory.CreateMember("Winner", "Winner Street", true);
            var loser = memberFactory.CreateMember("Loser", "Loser Street", true);

            var standaloneMatchBuilder = new MatchBuilder(100);

            for (var i = 0; i < 12; i++)
            {
                matchDirector.Construct(standaloneMatchBuilder, champ, loser);
                var testMatch = standaloneMatchBuilder.GetResult();
                testMatch.SetPlayerOneScore(100, 100, 100);
                testMatch.SetPlayerTwoScore(50, 50, 50);
            }


            var resultManager = ResultManager.Instance();

            resultManager.GetCompetitionResults(testCompetition);
            resultManager.GetYearChampion(DateTime.Now);


            Console.WriteLine();
            Console.WriteLine("----------");
            var fortKnox = FortKnox.Instance();

            fortKnox.ExportInvoices();

            Console.WriteLine("Press any key...");
            Console.ReadLine();
        }