Exemple #1
0
        /// <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();
        }
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 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());
        }