Exemplo n.º 1
0
        public void WriteObjectWithAnnotations(int annotationCount)
        {
            using (var writer = new ManagedBinaryWriter(_memoryStream, Symbols.EmptySymbolTablesArray))
            {
                writer.StepIn(IonType.Struct);

                writer.SetFieldName("FieldName");
                for (var i = 0; i < annotationCount; i++)
                {
                    writer.AddTypeAnnotation($"annot_{i}");
                }

                writer.WriteString("FieldValue");

                writer.StepOut();
                writer.Flush();
            }

            var reader = new UserBinaryReader(new MemoryStream(_memoryStream.GetWrittenBuffer()));

            reader.MoveNext();
            reader.StepIn();
            reader.MoveNext();

            // Load the value.
            reader.StringValue();

            var annotations = reader.GetTypeAnnotationSymbols().ToList();

            Assert.AreEqual(annotations.Count, annotationCount);

            for (var i = 0; i < annotationCount; i++)
            {
                Assert.IsTrue(annotations.Any(s => s.Text == $"annot_{i}"));
            }
        }