private static void AssertDecode(int expectedInnerNumber, Action <EmberReader> assertEqual, params byte[] input) { using (var stream = new MemoryStream(input)) using (var reader = new EmberReader(stream, 1)) { AssertThrow <InvalidOperationException>(() => reader.InnerNumber.GetHashCode().Ignore()); AssertThrow <InvalidOperationException>(() => reader.OuterId.Ignore()); AssertThrow <InvalidOperationException>(() => reader.ReadContentsAsObject()); Assert.IsFalse(reader.CanReadContents); Assert.IsTrue(reader.Read()); Assert.AreEqual(EmberId.CreateApplication(0), reader.OuterId); Assert.AreEqual(expectedInnerNumber, reader.InnerNumber); assertEqual(reader); AssertThrow <InvalidOperationException>(() => reader.ReadContentsAsObject()); Assert.IsFalse(reader.Read()); reader.Dispose(); Assert.IsFalse(reader.CanReadContents); AssertThrow <ObjectDisposedException>(() => reader.InnerNumber.Ignore()); AssertThrow <ObjectDisposedException>(() => reader.OuterId.Ignore()); AssertThrow <ObjectDisposedException>(() => reader.ReadContentsAsObject()); } using (var writer = XmlWriter.Create(Console.Out, new XmlWriterSettings() { Indent = true })) { new EmberConverter(GlowTypes.Instance).ToXml(input, writer); Console.WriteLine(); Console.WriteLine(); } }
private static void ReadAll(params byte[] input) { using (var stream = new MemoryStream(input)) using (var reader = new EmberReader(stream, 1)) { while (reader.Read()) { switch (reader.InnerNumber) { case InnerNumber.EndContainer: AssertThrow <InvalidOperationException>(() => reader.OuterId.Ignore()); Assert.IsFalse(reader.CanReadContents); AssertThrow <InvalidOperationException>(() => reader.ReadContentsAsObject()); break; case InnerNumber.Sequence: case InnerNumber.Set: reader.OuterId.Ignore(); Assert.IsFalse(reader.CanReadContents); AssertThrow <InvalidOperationException>(() => reader.ReadContentsAsObject()); break; case InnerNumber.Boolean: case InnerNumber.Integer: case InnerNumber.Octetstring: case InnerNumber.Real: case InnerNumber.Utf8String: case InnerNumber.RelativeObjectIdentifier: reader.OuterId.Ignore(); Assert.IsTrue(reader.CanReadContents); reader.ReadContentsAsObject(); break; default: Assert.IsTrue(reader.InnerNumber >= InnerNumber.FirstApplication); reader.OuterId.Ignore(); Assert.IsFalse(reader.CanReadContents); AssertThrow <InvalidOperationException>(() => reader.ReadContentsAsObject()); break; } } } }