Beispiel #1
0
        private void ValidateMatch(Match match)
        {
            Console.WriteLine("What is the result of the Match? (Example: 2 3)");
            string input;

            do
            {
                input = Console.ReadLine();
            } while (!CheckInputOfMatch(input));

            string[] splitInput   = input.Split(" ");
            int      firstNumber  = int.Parse(splitInput[0]);
            int      secondNumber = int.Parse(splitInput[1]);

            if (firstNumber > secondNumber)
            {
                match.PlayerOne.Wins++;
            }
            else if (secondNumber > firstNumber)
            {
                match.PlayerTwo.Wins++;
            }
            else
            {
                match.PlayerOne.Ties++;
                match.PlayerTwo.Ties++;
            }

            // add/ subtract goals to GoalDifference
            match.PlayerOne.GoalDifference += firstNumber;
            match.PlayerOne.GoalDifference -= secondNumber;
            match.PlayerTwo.GoalDifference -= firstNumber;
            match.PlayerTwo.GoalDifference += secondNumber;

            // Add as match for the Log Engine
            TournamentGroupLog.AddMatch(TournamentGroupLogMatch.Create(match.PlayerOne.PlayerName.Title, match.PlayerTwo.PlayerName.Title, firstNumber, secondNumber));
        }
Beispiel #2
0
        public void GroupExportTest()
        {
            // Alle Gruppenspiele hinzufügen
            TournamentGroupLog.AddMatch(TournamentGroupLogMatch.Create(PLAYER_THREE, PLAYER_FOUR, 1, 1));
            TournamentGroupLog.AddMatch(TournamentGroupLogMatch.Create(PLAYER_FIVE, PLAYER_FOUR, 1, 1));
            TournamentGroupLog.AddMatch(TournamentGroupLogMatch.Create(PLAYER_THREE, PLAYER_SEVEN, 1, 1));
            TournamentGroupLog.AddMatch(TournamentGroupLogMatch.Create(PLAYER_SIX, PLAYER_ONE, 1, 1));
            TournamentGroupLog.AddMatch(TournamentGroupLogMatch.Create(PLAYER_FIVE, PLAYER_SEVEN, 1, 1));
            TournamentGroupLog.AddMatch(TournamentGroupLogMatch.Create(PLAYER_FOUR, PLAYER_SEVEN, 1, 1));
            TournamentGroupLog.AddMatch(TournamentGroupLogMatch.Create(PLAYER_ONE, PLAYER_TWO, 1, 1));
            TournamentGroupLog.AddMatch(TournamentGroupLogMatch.Create(PLAYER_SIX, PLAYER_EIGHT, 1, 1));
            TournamentGroupLog.AddMatch(TournamentGroupLogMatch.Create(PLAYER_SIX, PLAYER_TWO, 1, 1));
            TournamentGroupLog.AddMatch(TournamentGroupLogMatch.Create(PLAYER_ONE, PLAYER_EIGHT, 1, 1));
            TournamentGroupLog.AddMatch(TournamentGroupLogMatch.Create(PLAYER_FIVE, PLAYER_THREE, 1, 1));
            TournamentGroupLog.AddMatch(TournamentGroupLogMatch.Create(PLAYER_EIGHT, PLAYER_TWO, 1, 1));

            // Gruppen erzeugen
            var groupA = new List <Player>();

            groupA.Add(new Player(new Name(PLAYER_FIVE), new Identification(5)));
            groupA.Add(new Player(new Name(PLAYER_THREE), new Identification(3)));
            groupA.Add(new Player(new Name(PLAYER_FOUR), new Identification(4)));
            groupA.Add(new Player(new Name(PLAYER_SEVEN), new Identification(7)));

            var groupB = new List <Player>();

            groupB.Add(new Player(new Name(PLAYER_SIX), new Identification(6)));
            groupB.Add(new Player(new Name(PLAYER_ONE), new Identification(1)));
            groupB.Add(new Player(new Name(PLAYER_EIGHT), new Identification(8)));
            groupB.Add(new Player(new Name(PLAYER_TWO), new Identification(2)));

            // Gruppen hinzufügen
            TournamentGroupLog.Groups.Add(1, groupA);
            TournamentGroupLog.Groups.Add(2, groupB);

            // Dinge erzeugen, die wichtig für den Export sind
            var fileName = "KnockOutStageGroupExportTest.xlsx";

            using (SpreadsheetDocument document = SpreadsheetDocument.Create(fileName, SpreadsheetDocumentType.Workbook))
            {
                WorkbookPart workbookPart = document.AddWorkbookPart();
                workbookPart.Workbook = new Workbook();
                Sheets sheets = document.WorkbookPart.Workbook.AppendChild <Sheets>(new Sheets());

                // Groups
                WorksheetPart worksheetPart = workbookPart.AddNewPart <WorksheetPart>();
                SheetData     sheetdata     = new SheetData();
                if (TournamentGroupLog.Groups.Count > 0)
                {
                    Worksheet worksheet = new Worksheet();
                    worksheet.AppendChild(sheetdata);
                    worksheetPart.Worksheet = worksheet;
                    Sheet sheet1 = new Sheet()
                    {
                        Id      = document.WorkbookPart.GetIdOfPart(worksheetPart),
                        SheetId = 1,
                        Name    = "Groups"
                    };
                    sheets.Append(sheet1);
                }

                // Den eigentlichen Export durchführen
                var excelExportFactory = new ExcelExportFactory();
                var groupLog           = excelExportFactory.CreateExcelExport(ExcelExportFactory.ExcelExportType.Groups);
                groupLog.Export(document, sheetdata, worksheetPart);

                // Daten, die aus der Datei benötigt werden, sodass die Tests durchgeführt werden können
                var playerCell          = CellFinder.GetCell(worksheetPart.Worksheet, 10, 2);
                var firstValueCell      = CellFinder.GetCell(worksheetPart.Worksheet, 2, 2);
                var secondValueCell     = CellFinder.GetCell(worksheetPart.Worksheet, 2, 3);
                var firstGroupNameCell  = CellFinder.GetCell(worksheetPart.Worksheet, 1, 14);
                var groupWinnerCell     = CellFinder.GetCell(worksheetPart.Worksheet, 1, 15);
                var groupDifferenceCell = CellFinder.GetCell(worksheetPart.Worksheet, 2, 21);
                var groupPointsCell     = CellFinder.GetCell(worksheetPart.Worksheet, 3, 24);

                int firstValue, secondValue;
                firstValueCell.CellValue.TryGetInt(out firstValue);
                secondValueCell.CellValue.TryGetInt(out secondValue);

                // Tests, um zu überprüfen, ob der Export funktioniert hat.
                Assert.IsTrue(playerCell != null && playerCell.DataType == CellValues.String);
                Assert.IsTrue(firstValueCell != null && firstValueCell.DataType == CellValues.Number);
                Assert.AreEqual(firstValue, 1);
                Assert.AreEqual(secondValue, 1);
                Assert.AreEqual(firstGroupNameCell.CellValue.Text, "Group 1");
                Assert.IsTrue(groupWinnerCell != null && groupWinnerCell.DataType == CellValues.String);
                Assert.IsTrue(groupDifferenceCell != null && groupDifferenceCell.DataType == CellValues.Number);
                Assert.IsTrue(groupPointsCell != null && groupPointsCell.DataType == CellValues.Number);
            }
        }