/// <summary> /// Writes the specified pgn database. /// </summary> /// <param name="pgnDatabase">The pgn database.</param> public void Write(Database pgnDatabase) { var formatter = new Formatter(); TextWriter writer = new StreamWriter(_stream); foreach (var game in pgnDatabase.Games) { formatter.Format(game, writer); } writer.Close(); }
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 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()); }