本文整理汇总了C#中TestClass.ToBson方法的典型用法代码示例。如果您正苦于以下问题:C# TestClass.ToBson方法的具体用法?C# TestClass.ToBson怎么用?C# TestClass.ToBson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestClass
的用法示例。
在下文中一共展示了TestClass.ToBson方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestNull
public void TestNull()
{
var obj = new TestClass { Addresses = null };
var json = obj.ToJson();
var expected = "{ 'Addresses' : null }".Replace("'", "\"");
Assert.AreEqual(expected, json);
var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
}
示例2: TestNotEmpty
public void TestNotEmpty()
{
var obj = new TestClass(new BsonArray { 1, 2 });
var json = obj.ToJson();
var expected = "{ 'B' : #, 'V' : # }".Replace("#", "[1, 2]").Replace("'", "\"");
Assert.Equal(expected, json);
var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
}
示例3: TestNull
public void TestNull()
{
var obj = new TestClass(null);
var json = obj.ToJson();
var expected = "{ 'B' : #, 'V' : # }".Replace("#", "{ '_csharpnull' : true }").Replace("'", "\"");
Assert.Equal(expected, json);
var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
Assert.Equal(null, rehydrated.B);
Assert.Equal(null, rehydrated.V);
Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
}
示例4: TestTrue
public void TestTrue()
{
var obj = new TestClass
{
N = true, B = true, D128 = true, D = true, I = true, L = true, S = true
};
var json = obj.ToJson();
var expected = "{ 'N' : true, 'B' : true, 'D128' : NumberDecimal('1'), 'D' : 1.0, 'I' : 1, 'L' : NumberLong(1), 'S' : 'true' }".Replace("'", "\"");
Assert.Equal(expected, json);
var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
}
示例5: TestFalse
public void TestFalse()
{
var obj = new TestClass
{
N = false, B = false, D128 = false, D = false, I = false, L = false, S = false
};
var json = obj.ToJson();
var expected = "{ 'N' : false, 'B' : false, 'D128' : NumberDecimal('0'), 'D' : 0.0, 'I' : 0, 'L' : NumberLong(0), 'S' : 'false' }".Replace("'", "\"");
Assert.Equal(expected, json);
var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
}
示例6: TestLength0
public void TestLength0()
{
var obj = new TestClass
{
B = new BitArray(new bool[0]),
S = new BitArray(new bool[0])
};
var json = obj.ToJson();
var expected = "{ 'B' : new BinData(0, ''), 'S' : '' }".Replace("'", "\"");
Assert.Equal(expected, json);
var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
}
示例7: TestLength1
public void TestLength1()
{
var obj = new TestClass
{
B = new BitArray(new[] { true }),
S = new BitArray(new[] { true })
};
var json = obj.ToJson();
var expected = "{ 'B' : { 'Length' : 1, 'Bytes' : new BinData(0, 'AQ==') }, 'S' : '1' }".Replace("'", "\"");
Assert.Equal(expected, json);
var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
Assert.True(rehydrated.B[0]);
Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
}
示例8: TestSerialization
public void TestSerialization()
{
var obj = new TestClass
{
Addresses = new HashSet<Address>
{
new Address { Street = "123 Main", City = "Smithtown", State = "PA", Zip = 12345 },
new Address { Street = "456 First", City = "Johnstown", State = "MD", Zip = 45678 }
}
};
var json = obj.ToJson();
var expected = "{ 'Addresses' : [#A1, #A2] }";
expected = expected.Replace("#A1", "{ 'Street' : '123 Main', 'City' : 'Smithtown', 'State' : 'PA', 'Zip' : 12345 }");
expected = expected.Replace("#A2", "{ 'Street' : '456 First', 'City' : 'Johnstown', 'State' : 'MD', 'Zip' : 45678 }");
expected = expected.Replace("'", "\"");
Assert.AreEqual(expected, json);
var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
Assert.IsInstanceOf<HashSet<Address>>(rehydrated.Addresses);
Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
}
示例9: TestIPv4
public void TestIPv4()
{
var obj = new TestClass
{
EndPoint = new IPEndPoint(new IPAddress(new byte[] { 1, 2, 3, 4 }), 1234)
};
var json = obj.ToJson();
var expected = "{ 'EndPoint' : '1.2.3.4:1234' }".Replace("'", "\"");
Assert.Equal(expected, json);
var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
}
示例10: TestOne
public void TestOne()
{
var obj = new TestClass
{
D = 1,
I = 1,
L = 1,
S = 1
};
var json = obj.ToJson();
var expected = ("{ 'D' : 1.0, 'I' : 1, 'L' : NumberLong(1), 'S' : '1' }").Replace("'", "\"");
Assert.Equal(expected, json);
var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
}
示例11: TestMax
public void TestMax()
{
var obj = new TestClass
{
D = short.MaxValue,
I = short.MaxValue,
L = short.MaxValue,
S = short.MaxValue
};
var json = obj.ToJson();
var expected = ("{ 'D' : 32767.0, 'I' : 32767, 'L' : NumberLong(32767), 'S' : '32767' }").Replace("'", "\"");
Assert.Equal(expected, json);
var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
}
示例12: TestZero
public void TestZero()
{
var obj = new TestClass
{
D = 0,
I = 0,
L = 0,
S = 0
};
var json = obj.ToJson();
var expected = ("{ 'D' : 0.0, 'I' : 0, 'L' : NumberLong(0), 'S' : '0' }").Replace("'", "\"");
Assert.Equal(expected, json);
var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
}
示例13: TestEmpty
public void TestEmpty()
{
var obj = new TestClass
{
Addresses = new List<Address>()
};
var json = obj.ToJson();
var expected = "{ 'Addresses' : [] }".Replace("'", "\"");
Assert.AreEqual(expected, json);
var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
Assert.IsInstanceOf<List<Address>>(rehydrated.Addresses);
Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
}
示例14: TestHttp
public void TestHttp()
{
var obj = new TestClass
{
V = new Uri("http://www.cnn.com")
};
var json = obj.ToJson();
var expected = "{ 'V' : 'http://www.cnn.com' }".Replace("'", "\"");
Assert.Equal(expected, json);
var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
}
示例15: TestMongoDB
public void TestMongoDB()
{
var obj = new TestClass
{
V = new Uri("mongodb://localhost/?w=1")
};
var json = obj.ToJson();
var expected = "{ 'V' : 'mongodb://localhost/?w=1' }".Replace("'", "\"");
Assert.Equal(expected, json);
var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
}