Inheritance: ITagWriter
Beispiel #1
0
        public static TagWriter CreateWriter(NbtFormat format, Stream stream)
        {
            TagWriter writer;

            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            switch (format)
            {
            case NbtFormat.Binary:
                writer = new BinaryTagWriter(stream);
                break;

            case NbtFormat.Xml:
                writer = new XmlTagWriter(stream);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(format), format, "Invalid format.");
            }

            return(writer);
        }
    public void Constructor_allows_external_writer()
    {
      // arrange
      ITagWriter target;
      ITag expected;
      ITag actual;
      XmlWriter writer;
      TextWriter textWriter;

      expected = this.CreateComplexData();

      textWriter = new StringWriter();
      writer = XmlWriter.Create(textWriter, new XmlWriterSettings
                                            {
                                              Indent = true
                                            });

      target = new XmlTagWriter(writer);

      // act
      target.WriteTag(expected);
      writer.Flush();

      using (TextReader textReader = new StringReader(textWriter.ToString()))
      {
        using (XmlReader reader = XmlReader.Create(textReader))
        {
          actual = new XmlTagReader(reader).ReadTag();
        }
      }

      // assert
      this.CompareTags(expected, actual);
    }