当前位置: 首页>>代码示例>>C#>>正文


C# BsonReader.Read方法代码示例

本文整理汇总了C#中Raven.Imports.Newtonsoft.Json.Bson.BsonReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# BsonReader.Read方法的具体用法?C# BsonReader.Read怎么用?C# BsonReader.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Raven.Imports.Newtonsoft.Json.Bson.BsonReader的用法示例。


在下文中一共展示了BsonReader.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadSingleObject

    public void ReadSingleObject()
    {
      byte[] data = MiscellaneousUtils.HexToBytes("0F-00-00-00-10-42-6C-61-68-00-01-00-00-00-00");
      MemoryStream ms = new MemoryStream(data);
      BsonReader reader = new BsonReader(ms);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartObject, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
      Assert.AreEqual("Blah", reader.Value);
      Assert.AreEqual(typeof(string), reader.ValueType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Integer, reader.TokenType);
      Assert.AreEqual(1L, reader.Value);
      Assert.AreEqual(typeof(long), reader.ValueType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndObject, reader.TokenType);

      Assert.IsFalse(reader.Read());
      Assert.AreEqual(JsonToken.None, reader.TokenType);
    }
开发者ID:nberardi,项目名称:ravendb,代码行数:25,代码来源:BsonReaderTests.cs

示例2: ReadRegexWithOptions

        public void ReadRegexWithOptions()
        {
            string hexdoc = "1A-00-00-00-0B-72-65-67-65-78-00-61-62-63-00-69-00-0B-74-65-73-74-00-00-00-00";

            byte[] data = HexToBytes(hexdoc);

            MemoryStream ms = new MemoryStream(data);
            BsonReader reader = new BsonReader(ms);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.StartObject, reader.TokenType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.String, reader.TokenType);
            Assert.AreEqual("/abc/i", reader.Value);
            Assert.AreEqual(typeof(string), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.String, reader.TokenType);
            Assert.AreEqual("//", reader.Value);
            Assert.AreEqual(typeof(string), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.EndObject, reader.TokenType);

            Assert.IsFalse(reader.Read());
            Assert.AreEqual(JsonToken.None, reader.TokenType);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:34,代码来源:BsonReaderTests.cs

示例3: WriteReadEmptyAndNullStrings

    public void WriteReadEmptyAndNullStrings()
    {
      MemoryStream ms = new MemoryStream();
      BsonWriter writer = new BsonWriter(ms);

      writer.WriteStartArray();
      writer.WriteValue("Content!");
      writer.WriteValue("");
      writer.WriteValue((string)null);
      writer.WriteEndArray();

      ms.Seek(0, SeekOrigin.Begin);

      BsonReader reader = new BsonReader(ms);
      reader.ReadRootValueAsArray = true;

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartArray, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);
      Assert.AreEqual("Content!", reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);
      Assert.AreEqual("", reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Null, reader.TokenType);
      Assert.AreEqual(null, reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndArray, reader.TokenType);

      Assert.IsFalse(reader.Read());
    }
开发者ID:nberardi,项目名称:ravendb,代码行数:36,代码来源:BsonWriterTests.cs

示例4: WriteBytes

    public void WriteBytes()
    {
      byte[] data = Encoding.UTF8.GetBytes("Hello world!");

      MemoryStream ms = new MemoryStream();
      BsonWriter writer = new BsonWriter(ms);
      writer.WriteStartArray();
      writer.WriteValue("a");
      writer.WriteValue("b");
      writer.WriteValue(data);
      writer.WriteEndArray();

      writer.Flush();

      ms.Seek(0, SeekOrigin.Begin);

      string expected = "2B-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-05-32-00-0C-00-00-00-00-48-65-6C-6C-6F-20-77-6F-72-6C-64-21-00";
      string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());

      Assert.AreEqual(expected, bson);

      BsonReader reader = new BsonReader(new MemoryStream(ms.ToArray()));
      reader.ReadRootValueAsArray = true;
      reader.Read();
      reader.Read();
      reader.Read();
      reader.Read();
      Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
      CollectionAssert.AreEquivalent(data, (byte[])reader.Value);
    }
开发者ID:nberardi,项目名称:ravendb,代码行数:30,代码来源:BsonWriterTests.cs

示例5: ReadEmptyStrings

        public void ReadEmptyStrings()
        {
            string bson = "0C-00-00-00-02-00-01-00-00-00-00-00";

            BsonReader reader = new BsonReader(new MemoryStream(HexToBytes(bson)));

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.StartObject, reader.TokenType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
            Assert.AreEqual("", reader.Value);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.String, reader.TokenType);
            Assert.AreEqual("", reader.Value);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.EndObject, reader.TokenType);

            Assert.IsFalse(reader.Read());
            Assert.AreEqual(JsonToken.None, reader.TokenType);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:23,代码来源:BsonReaderTests.cs

示例6: ReadEndOfStream

 public void ReadEndOfStream()
 {
     BsonReader reader = new BsonReader(new MemoryStream());
     Assert.IsFalse(reader.Read());
 }
开发者ID:j2jensen,项目名称:ravendb,代码行数:5,代码来源:BsonReaderTests.cs

示例7: Bson_SupportMultipleContent

        public void Bson_SupportMultipleContent()
        {
            MemoryStream myStream = new MemoryStream();
            BsonWriter writer = new BsonWriter(myStream);
            JsonSerializer serializer = new JsonSerializer();
            MyTest tst1 = new MyTest
            {
                TimeStamp = new DateTime(2000, 12, 20, 12, 59, 59, DateTimeKind.Utc),
                UserName = "Joe Doe"
            };
            MyTest tst2 = new MyTest
            {
                TimeStamp = new DateTime(2010, 12, 20, 12, 59, 59, DateTimeKind.Utc),
                UserName = "Bob"
            };
            serializer.Serialize(writer, tst1);
            serializer.Serialize(writer, tst2);

            myStream.Seek(0, SeekOrigin.Begin);

            BsonReader reader = new BsonReader(myStream)
            {
                SupportMultipleContent = true,
                DateTimeKindHandling = DateTimeKind.Utc
            };

            MyTest tst1A = serializer.Deserialize<MyTest>(reader);

            reader.Read();

            MyTest tst2A = serializer.Deserialize<MyTest>(reader);

            Assert.AreEqual(tst1.UserName, tst1A.UserName);
            Assert.AreEqual(tst1.TimeStamp, tst1A.TimeStamp);

            Assert.AreEqual(tst2.UserName, tst2A.UserName);
            Assert.AreEqual(tst2.TimeStamp, tst2A.TimeStamp);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:38,代码来源:BsonReaderTests.cs

示例8: ReadLong

        public void ReadLong()
        {
            string hexdoc = "13-00-00-00-12-6C-6F-6E-67-00-FF-FF-FF-FF-FF-FF-FF-7F-00";

            byte[] data = HexToBytes(hexdoc);

            MemoryStream ms = new MemoryStream(data);
            BsonReader reader = new BsonReader(ms);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.StartObject, reader.TokenType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
            Assert.AreEqual("long", reader.Value);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.Integer, reader.TokenType);
            Assert.AreEqual(long.MaxValue, reader.Value);
            Assert.AreEqual(typeof(long), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.EndObject, reader.TokenType);

            Assert.IsFalse(reader.Read());
            Assert.AreEqual(JsonToken.None, reader.TokenType);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:27,代码来源:BsonReaderTests.cs

示例9: ReadValues

        public void ReadValues()
        {
            byte[] data = HexToBytes("8C-00-00-00-12-30-00-FF-FF-FF-FF-FF-FF-FF-7F-12-31-00-FF-FF-FF-FF-FF-FF-FF-7F-10-32-00-FF-FF-FF-7F-10-33-00-FF-FF-FF-7F-10-34-00-FF-00-00-00-10-35-00-7F-00-00-00-02-36-00-02-00-00-00-61-00-01-37-00-00-00-00-00-00-00-F0-45-01-38-00-FF-FF-FF-FF-FF-FF-EF-7F-01-39-00-00-00-00-E0-FF-FF-EF-47-08-31-30-00-01-05-31-31-00-05-00-00-00-02-00-01-02-03-04-09-31-32-00-40-C5-E2-BA-E3-00-00-00-09-31-33-00-40-C5-E2-BA-E3-00-00-00-00");
            MemoryStream ms = new MemoryStream(data);
            BsonReader reader = new BsonReader(ms);
#pragma warning disable 612,618
            reader.JsonNet35BinaryCompatibility = true;
#pragma warning restore 612,618
            reader.ReadRootValueAsArray = true;
            reader.DateTimeKindHandling = DateTimeKind.Utc;

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.StartArray, reader.TokenType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.Integer, reader.TokenType);
            Assert.AreEqual(long.MaxValue, reader.Value);
            Assert.AreEqual(typeof(long), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.Integer, reader.TokenType);
            Assert.AreEqual(long.MaxValue, reader.Value);
            Assert.AreEqual(typeof(long), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.Integer, reader.TokenType);
            Assert.AreEqual((long)int.MaxValue, reader.Value);
            Assert.AreEqual(typeof(long), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.Integer, reader.TokenType);
            Assert.AreEqual((long)int.MaxValue, reader.Value);
            Assert.AreEqual(typeof(long), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.Integer, reader.TokenType);
            Assert.AreEqual((long)byte.MaxValue, reader.Value);
            Assert.AreEqual(typeof(long), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.Integer, reader.TokenType);
            Assert.AreEqual((long)sbyte.MaxValue, reader.Value);
            Assert.AreEqual(typeof(long), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.String, reader.TokenType);
            Assert.AreEqual("a", reader.Value);
            Assert.AreEqual(typeof(string), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.Float, reader.TokenType);
            Assert.AreEqual((double)decimal.MaxValue, reader.Value);
            Assert.AreEqual(typeof(double), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.Float, reader.TokenType);
            Assert.AreEqual((double)double.MaxValue, reader.Value);
            Assert.AreEqual(typeof(double), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.Float, reader.TokenType);
            Assert.AreEqual((double)float.MaxValue, reader.Value);
            Assert.AreEqual(typeof(double), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.Boolean, reader.TokenType);
            Assert.AreEqual(true, reader.Value);
            Assert.AreEqual(typeof(bool), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
            CollectionAssert.AreEquivalent(new byte[] { 0, 1, 2, 3, 4 }, (byte[])reader.Value);
            Assert.AreEqual(typeof(byte[]), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.Date, reader.TokenType);
            Assert.AreEqual(new DateTime(2000, 12, 29, 12, 30, 0, DateTimeKind.Utc), reader.Value);
            Assert.AreEqual(typeof(DateTime), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.Date, reader.TokenType);
            Assert.AreEqual(new DateTime(2000, 12, 29, 12, 30, 0, DateTimeKind.Utc), reader.Value);
            Assert.AreEqual(typeof(DateTime), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.EndArray, reader.TokenType);

            Assert.IsFalse(reader.Read());
            Assert.AreEqual(JsonToken.None, reader.TokenType);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:90,代码来源:BsonReaderTests.cs

示例10: ReadDouble_Decimal

        public void ReadDouble_Decimal()
        {
            byte[] data = HexToBytes("10-00-00-00-01-30-00-8F-C2-F5-28-5C-FF-58-40-00");

            MemoryStream ms = new MemoryStream(data);
            BsonReader reader = new BsonReader(ms);
            reader.FloatParseHandling = FloatParseHandling.Decimal;
            reader.ReadRootValueAsArray = true;

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.StartArray, reader.TokenType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.Float, reader.TokenType);
            Assert.AreEqual(99.99m, reader.Value);
            Assert.AreEqual(typeof(decimal), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.EndArray, reader.TokenType);

            Assert.IsFalse(reader.Read());
            Assert.AreEqual(JsonToken.None, reader.TokenType);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:23,代码来源:BsonReaderTests.cs

示例11: ReadGuid_Bytes

        public void ReadGuid_Bytes()
        {
            byte[] data = HexToBytes("1D-00-00-00-05-30-00-10-00-00-00-04-D7-EE-21-D8-5C-4B-C9-43-8A-C2-69-28-E5-79-B7-05-00");

            MemoryStream ms = new MemoryStream(data);
            BsonReader reader = new BsonReader(ms);
            reader.ReadRootValueAsArray = true;

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.StartArray, reader.TokenType);

            Guid g = new Guid("D821EED7-4B5C-43C9-8AC2-6928E579B705");

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
            Assert.AreEqual(g, reader.Value);
            Assert.AreEqual(typeof(Guid), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.EndArray, reader.TokenType);

            Assert.IsFalse(reader.Read());
            Assert.AreEqual(JsonToken.None, reader.TokenType);

            ms = new MemoryStream(data);
            reader = new BsonReader(ms);
            reader.ReadRootValueAsArray = true;

            JsonSerializer serializer = new JsonSerializer();
            IList<Guid> l = serializer.Deserialize<IList<Guid>>(reader);

            Assert.AreEqual(1, l.Count);
            Assert.AreEqual(g, l[0]);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:34,代码来源:BsonReaderTests.cs

示例12: GuidsShouldBeProperlyDeserialised_AsBytes_ReadAhead

        public void GuidsShouldBeProperlyDeserialised_AsBytes_ReadAhead()
        {
            Guid g = new Guid("822C0CE6-CC42-4753-A3C3-26F0684A4B88");

            MemoryStream ms = new MemoryStream();
            BsonWriter writer = new BsonWriter(ms);
            writer.WriteStartObject();
            writer.WritePropertyName("TheGuid");
            writer.WriteValue(g);
            writer.WriteEndObject();
            writer.Flush();

            byte[] bytes = ms.ToArray();

            BsonReader reader = new BsonReader(new MemoryStream(bytes));
            Assert.IsTrue(reader.Read());
            Assert.IsTrue(reader.Read());

            CollectionAssert.AreEquivalent(g.ToByteArray(), reader.ReadAsBytes());
            Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
            Assert.AreEqual(typeof(byte[]), reader.ValueType);
            CollectionAssert.AreEquivalent(g.ToByteArray(), (byte[])reader.Value);

            Assert.IsTrue(reader.Read());
            Assert.IsFalse(reader.Read());

            JsonSerializer serializer = new JsonSerializer();
            serializer.MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead;
            BytesTestClass b = serializer.Deserialize<BytesTestClass>(new BsonReader(new MemoryStream(bytes)));
            CollectionAssert.AreEquivalent(g.ToByteArray(), b.TheGuid);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:31,代码来源:BsonReaderTests.cs

示例13: ReadGuid_Text

        public void ReadGuid_Text()
        {
            byte[] data = HexToBytes("31-00-00-00-02-30-00-25-00-00-00-64-38-32-31-65-65-64-37-2D-34-62-35-63-2D-34-33-63-39-2D-38-61-63-32-2D-36-39-32-38-65-35-37-39-62-37-30-35-00-00");

            MemoryStream ms = new MemoryStream(data);
            BsonReader reader = new BsonReader(ms);
            reader.ReadRootValueAsArray = true;

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.StartArray, reader.TokenType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.String, reader.TokenType);
            Assert.AreEqual("d821eed7-4b5c-43c9-8ac2-6928e579b705", reader.Value);
            Assert.AreEqual(typeof(string), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.EndArray, reader.TokenType);

            Assert.IsFalse(reader.Read());
            Assert.AreEqual(JsonToken.None, reader.TokenType);

            ms = new MemoryStream(data);
            reader = new BsonReader(ms);
            reader.ReadRootValueAsArray = true;

            JsonSerializer serializer = new JsonSerializer();
            IList<Guid> l = serializer.Deserialize<IList<Guid>>(reader);

            Assert.AreEqual(1, l.Count);
            Assert.AreEqual(new Guid("D821EED7-4B5C-43C9-8AC2-6928E579B705"), l[0]);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:32,代码来源:BsonReaderTests.cs

示例14: MultibyteCharacterPropertyNamesAndStrings

        public void MultibyteCharacterPropertyNamesAndStrings()
        {
            string json = @"{
  ""?????? ??? ????????? ?? ??O??SF???S????? ??? ??? ????? ???????? ?? ?? S???????? ????T???S S???S ??????S"": ""?????? ??? ????????? ?? ??O??SF???S????? ??? ??? ????? ???????? ?? ?? S???????? ????T???S S???S ??????S""
}";
            JObject parsed = JObject.Parse(json);
            var memoryStream = new MemoryStream();
            var bsonWriter = new BsonWriter(memoryStream);
            parsed.WriteTo(bsonWriter);
            bsonWriter.Flush();
            memoryStream.Position = 0;

            BsonReader reader = new BsonReader(memoryStream);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.StartObject, reader.TokenType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
            Assert.AreEqual("?????? ??? ????????? ?? ??O??SF???S????? ??? ??? ????? ???????? ?? ?? S???????? ????T???S S???S ??????S", reader.Value);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.String, reader.TokenType);
            Assert.AreEqual("?????? ??? ????????? ?? ??O??SF???S????? ??? ??? ????? ???????? ?? ?? S???????? ????T???S S???S ??????S", reader.Value);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:28,代码来源:BsonReaderTests.cs

示例15: CanRoundTripStackOverflowData

        public void CanRoundTripStackOverflowData()
        {
            var doc =
                @"{
""AboutMe"": ""<p>I'm the Director for Research and Development for <a href=\""http://www.prophoenix.com\"" rel=\""nofollow\"">ProPhoenix</a>, a public safety software company.  This position allows me to investigate new and existing technologies and incorporate them into our product line, with the end goal being to help public safety agencies to do their jobs more effeciently and safely.</p>\r\n\r\n<p>I'm an advocate for PowerShell, as I believe it encourages administrative best practices and allows developers to provide additional access to their applications, without needing to explicity write code for each administrative feature.  Part of my advocacy for PowerShell includes <a href=\""http://blog.usepowershell.com\"" rel=\""nofollow\"">my blog</a>, appearances on various podcasts, and acting as a Community Director for <a href=\""http://powershellcommunity.org\"" rel=\""nofollow\"">PowerShellCommunity.Org</a></p>\r\n\r\n<p>I’m also a co-host of Mind of Root (a weekly audio podcast about systems administration, tech news, and topics).</p>\r\n"",
""WebsiteUrl"": ""http://blog.usepowershell.com""
}";
            JObject parsed = JObject.Parse(doc);
            var memoryStream = new MemoryStream();
            var bsonWriter = new BsonWriter(memoryStream);
            parsed.WriteTo(bsonWriter);
            bsonWriter.Flush();
            memoryStream.Position = 0;

            BsonReader reader = new BsonReader(memoryStream);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.StartObject, reader.TokenType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
            Assert.AreEqual("AboutMe", reader.Value);
            Assert.AreEqual(typeof(string), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.String, reader.TokenType);
            Assert.AreEqual("<p>I'm the Director for Research and Development for <a href=\"http://www.prophoenix.com\" rel=\"nofollow\">ProPhoenix</a>, a public safety software company.  This position allows me to investigate new and existing technologies and incorporate them into our product line, with the end goal being to help public safety agencies to do their jobs more effeciently and safely.</p>\r\n\r\n<p>I'm an advocate for PowerShell, as I believe it encourages administrative best practices and allows developers to provide additional access to their applications, without needing to explicity write code for each administrative feature.  Part of my advocacy for PowerShell includes <a href=\"http://blog.usepowershell.com\" rel=\"nofollow\">my blog</a>, appearances on various podcasts, and acting as a Community Director for <a href=\"http://powershellcommunity.org\" rel=\"nofollow\">PowerShellCommunity.Org</a></p>\r\n\r\n<p>I’m also a co-host of Mind of Root (a weekly audio podcast about systems administration, tech news, and topics).</p>\r\n", reader.Value);
            Assert.AreEqual(typeof(string), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
            Assert.AreEqual("WebsiteUrl", reader.Value);
            Assert.AreEqual(typeof(string), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.String, reader.TokenType);
            Assert.AreEqual("http://blog.usepowershell.com", reader.Value);
            Assert.AreEqual(typeof(string), reader.ValueType);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(JsonToken.EndObject, reader.TokenType);

            Assert.IsFalse(reader.Read());
            Assert.AreEqual(JsonToken.None, reader.TokenType);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:45,代码来源:BsonReaderTests.cs


注:本文中的Raven.Imports.Newtonsoft.Json.Bson.BsonReader.Read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。