From 71f4d7e682140748f52713949d43b5e2fe66be96 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Tue, 2 Aug 2022 09:41:29 +0100 Subject: [PATCH] Tests for new MapField behavior in generated messages Before the change, one test passed (merging from a stream) and one failed (merging from another message object) --- .../GeneratedMessageTest.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs index 8387291956..17c5249140 100644 --- a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs +++ b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs @@ -36,6 +36,7 @@ using Google.Protobuf.TestProtos; using NUnit.Framework; using System.Linq; using Google.Protobuf.WellKnownTypes; +using Google.Protobuf.Collections; namespace Google.Protobuf { @@ -795,5 +796,44 @@ namespace Google.Protobuf EqualityTester.AssertInequality(message1, message2); EqualityTester.AssertEquality(message1, message3); } + + [Test] + [TestCase(false)] + [TestCase(true)] + public void MapFieldMerging(bool direct) + { + var message1 = new TestMap + { + MapStringString = + { + { "x1", "y1" }, + { "common", "message1" } + } + }; + var message2 = new TestMap + { + MapStringString = + { + { "x2", "y2" }, + { "common", "message2" } + } + }; + if (direct) + { + message1.MergeFrom(message2); + } + else + { + message1.MergeFrom(message2.ToByteArray()); + } + + var expected = new MapField + { + { "x1", "y1" }, + { "x2", "y2" }, + { "common", "message2" } + }; + Assert.AreEqual(expected, message1.MapStringString); + } } } \ No newline at end of file