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()); }
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); }
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); }
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()); }
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()); }
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); }); }
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); }); }
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); }); }
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(); }