Exemple #1
0
        public string SerializeToString(Game game)
        {
            using var writer = new PgnWriter(Options);
            tagSerializer.Serialize(writer, game.Tags);
            _moveSectionSerializer.Serialize(game.InitialNode.Node, writer);
            writer.WriteResult(game.Result);

            return(writer.ToString());
        }
Exemple #2
0
        public void Write_should_write_game_correctly()
        {
            var stream = new MemoryStream();
            var sut = new PgnWriter(stream);

            var db = new Database();
            db.Games.Add(_testGame);

            sut.Write(db);

            var actual = Encoding.UTF8.GetString(stream.ToArray());
            Assert.AreEqual(TestGameString, actual);
        }
Exemple #3
0
        public void Write_should_write_game_correctly()
        {
            var stream = new MemoryStream();
            var sut    = new PgnWriter(stream);

            var db = new Database();

            db.Games.Add(_testGame);

            sut.Write(db);

            var actual = Encoding.UTF8.GetString(stream.ToArray());

            Assert.Equal(TestGameString, actual);
        }
Exemple #4
0
        public void parser_should_read_written_game_correctly()
        {
            var stream = new MemoryStream();
            var sut = new PgnWriter(stream);

            var db = new Database();
            db.Games.Add(_testGame);

            sut.Write(db);
            var writtenResult = Encoding.UTF8.GetString(stream.ToArray());

            var reader = new PgnReader();
            var actualDb = reader.ReadFromString(writtenResult);

            Assert.AreEqual(db.Games[0].ToString(), actualDb.Games[0].ToString());
        }
Exemple #5
0
        public void parser_should_read_written_game_correctly()
        {
            var stream = new MemoryStream();
            var sut    = new PgnWriter(stream);

            var db = new Database();

            db.Games.Add(_testGame);

            sut.Write(db);
            var writtenResult = Encoding.UTF8.GetString(stream.ToArray());

            var reader   = new PgnReader();
            var actualDb = reader.ReadFromString(writtenResult);

            Assert.Equal(db.Games[0].ToString(), actualDb.Games[0].ToString());
        }
Exemple #6
0
        public void WrongResultNotationTest(IReadPgnFiles reader, IWritePgnFiles writer)
        {
            "GIVEN a single file with wrong result notation".x(() =>
            {
                reader = new PgnReader(TestFixture.FolderWithOneFileWrongNotation);
                writer = new PgnWriter(TestFixture.PathResultedPgn);
            });

            "WHEN the file is read".x(() =>
            {
                var manager = new PgnManager(reader, writer, TestFixture.FakeRepo, TestFixture.FakeLogger);
                manager.ExecuteCheckingForDuplicates(g => { });
            });

            "THEN the new file created contains two games".x(() =>
            {
                TestFixture.ContentOfResultedPgn.ShouldBe(TestFixture.ContentOfWrongResultGames);
            });
        }
Exemple #7
0
        public void OneGameTest(IReadPgnFiles reader, IWritePgnFiles writer)
        {
            "GIVEN a single file with one game".x(() =>
            {
                reader = new PgnReader(TestFixture.FolderWithOneFileOneGame);
                writer = new PgnWriter(TestFixture.PathResultedPgn);
            });

            "WHEN the file is read".x(() =>
            {
                var manager = new PgnManager(reader, writer, TestFixture.FakeRepo, TestFixture.FakeLogger);
                manager.ExecuteCheckingForDuplicates(g => { });
            });

            "THEN the new file created contains one game".x(() =>
            {
                TestFixture.ContentOfResultedPgn.ShouldBe(TestFixture.ContentOfExpectedOneGame);
            });
        }
Exemple #8
0
        public void TwoNestedFilesTest(IReadPgnFiles reader, IWritePgnFiles writer)
        {
            "GIVEN a folder with two nested files where each file contains one game".x(() =>
            {
                reader = new PgnReader(TestFixture.FolderWithNestedFiles);
                writer = new PgnWriter(TestFixture.PathResultedPgn);
            });

            "WHEN the files are read".x(() =>
            {
                var manager = new PgnManager(reader, writer, TestFixture.FakeRepo, TestFixture.FakeLogger);
                manager.ExecuteCheckingForDuplicates(g => { });
            });

            "THEN the new file created contains two games".x(() =>
            {
                TestFixture.ContentOfResultedPgn.ShouldBe(TestFixture.ContentOfExpectedTwoGames);
            });
        }
Exemple #9
0
        static void Main(string[] args)
        {
            _start = DateTime.UtcNow;

            var reader = new PgnReader(@"C:\Chess\PNGSources");
            var writer = new PgnWriter(@"C:\Chess\Databases\db2018.pgn");
            var repo   = new GameRepository(@"Data Source=LENOVO-PC;Initial Catalog=PlayGrandmasters;Integrated Security=True");
            var logger = new Logger(@"C:\Chess\Databases\logs");

            var manager = new PgnManager(reader, writer, repo, logger);

            int counter = 0;

            manager.ExecuteWithoutCheckingForDuplicates(game =>
            {
                counter++;

                string moves;

                if (game.Moves.Length >= 40)
                {
                    moves = game.Moves.Substring(game.Moves.Length - 40);
                }
                else
                {
                    moves = game.Moves;
                }

                Console.WriteLine($"{counter} = {game.Hash}: {moves}");
            });

            _end = DateTime.UtcNow;

            Console.WriteLine($"Duration: {_end - _start}");
            Console.Read();
        }