aboutsummaryrefslogtreecommitdiffhomepage
path: root/csharp/src/Google.Protobuf.Test/WellKnownTypes
diff options
context:
space:
mode:
authorGravatar Jon Skeet <jonskeet@google.com>2016-01-04 14:03:01 +0000
committerGravatar Jon Skeet <jonskeet@google.com>2016-01-11 09:34:43 +0000
commit9e4f354f14775061ed098c896170d3a2d01a3895 (patch)
treee7e6850910cbd00970c70c4514246c6b7ea93ac1 /csharp/src/Google.Protobuf.Test/WellKnownTypes
parent5700a1054b081f425964b0b0e1535438da4b2ea1 (diff)
Prohibit null values in map fields
On deserialization, missing values for message types are replaced with a "default" message.
Diffstat (limited to 'csharp/src/Google.Protobuf.Test/WellKnownTypes')
-rw-r--r--csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs11
1 files changed, 5 insertions, 6 deletions
diff --git a/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs b/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs
index c87ceb2f..b72ef982 100644
--- a/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs
+++ b/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs
@@ -151,6 +151,8 @@ namespace Google.Protobuf.WellKnownTypes
[Test]
public void MapWrappersSerializeDeserialize()
{
+ // Note: no null values here, as they are prohibited in map fields
+ // (despite being representable).
var message = new MapWellKnownTypes
{
BoolField = { { 10, false }, { 20, true } },
@@ -158,13 +160,12 @@ namespace Google.Protobuf.WellKnownTypes
{ -1, ByteString.CopyFrom(1, 2, 3) },
{ 10, ByteString.CopyFrom(4, 5, 6) },
{ 1000, ByteString.Empty },
- { 10000, null }
},
DoubleField = { { 1, 12.5 }, { 10, -1.5 }, { 20, 0d } },
FloatField = { { 2, 123.25f }, { 3, -20f }, { 4, 0f } },
Int32Field = { { 5, int.MaxValue }, { 6, int.MinValue }, { 7, 0 } },
Int64Field = { { 8, long.MaxValue }, { 9, long.MinValue }, { 10, 0L } },
- StringField = { { 11, "First" }, { 12, "Second" }, { 13, "" }, { 14, null } },
+ StringField = { { 11, "First" }, { 12, "Second" }, { 13, "" } },
Uint32Field = { { 15, uint.MaxValue }, { 16, uint.MinValue }, { 17, 0U } },
Uint64Field = { { 18, ulong.MaxValue }, { 19, ulong.MinValue }, { 20, 0UL } },
};
@@ -224,13 +225,11 @@ namespace Google.Protobuf.WellKnownTypes
[Test]
public void Reflection_MapFields()
{
- // Just a single example... note that we can't have a null value here
- var message = new MapWellKnownTypes { Int32Field = { { 1, 2 }, { 3, null } } };
+ // Just a single example... note that we can't have a null value here despite the value type being int?
+ var message = new MapWellKnownTypes { Int32Field = { { 1, 2 } } };
var fields = MapWellKnownTypes.Descriptor.Fields;
var dictionary = (IDictionary) fields[MapWellKnownTypes.Int32FieldFieldNumber].Accessor.GetValue(message);
Assert.AreEqual(2, dictionary[1]);
- Assert.IsNull(dictionary[3]);
- Assert.IsTrue(dictionary.Contains(3));
}
[Test]