|
| 1 | +/* Copyright 2010-2012 10gen Inc. |
| 2 | +* |
| 3 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +* you may not use this file except in compliance with the License. |
| 5 | +* You may obtain a copy of the License at |
| 6 | +* |
| 7 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +* |
| 9 | +* Unless required by applicable law or agreed to in writing, software |
| 10 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +* See the License for the specific language governing permissions and |
| 13 | +* limitations under the License. |
| 14 | +*/ |
| 15 | + |
| 16 | +using System; |
| 17 | +using System.Collections.Generic; |
| 18 | +using System.IO; |
| 19 | +using System.Linq; |
| 20 | +using System.Text; |
| 21 | +using NUnit.Framework; |
| 22 | + |
| 23 | +using MongoDB.Bson; |
| 24 | +using MongoDB.Bson.IO; |
| 25 | +using MongoDB.Bson.Serialization; |
| 26 | +using MongoDB.Bson.Serialization.Attributes; |
| 27 | + |
| 28 | +namespace MongoDB.BsonUnitTests.DefaultSerializer.Serializers |
| 29 | +{ |
| 30 | + [TestFixture] |
| 31 | + public class KeyValuePairSerializerTests |
| 32 | + { |
| 33 | + [Test] |
| 34 | + public void TestNullValue() |
| 35 | + { |
| 36 | + KeyValuePair<string, object> kvp = new KeyValuePair<string, object>("Value", null); |
| 37 | + var json = kvp.ToJson(); |
| 38 | + var expected = "{ 'k' : 'Value', 'v' : null }".Replace("'", "\""); |
| 39 | + Assert.AreEqual(expected, json); |
| 40 | + |
| 41 | + var bson = kvp.ToBson(); |
| 42 | + var rehydrated = BsonSerializer.Deserialize<KeyValuePair<string, object>>(bson); |
| 43 | + Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson())); |
| 44 | + } |
| 45 | + } |
| 46 | +} |
0 commit comments