From 1a0ff9551a0720fef95a21946d9c8a1134ebda03 Mon Sep 17 00:00:00 2001 From: Sydney Acksman Date: Mon, 2 Dec 2019 13:50:51 -0600 Subject: [PATCH] Add comment and Assert.DoesNotThrow to RequiredFieldsNoThrow --- .../Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs index 704f2e5af3..1e22674c7c 100644 --- a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs +++ b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs @@ -261,11 +261,14 @@ namespace Google.Protobuf Assert.True(message.IsInitialized()); } + // Code was accidentally left in message parser that threw exceptions when missing required fields after parsing. + // We've decided to not throw exceptions on missing fields, instead leaving it up to the consumer how they + // want to check and handle missing fields. [Test] public void RequiredFieldsNoThrow() { - TestRequired.Parser.ParseFrom(new byte[0]); - (TestRequired.Parser as MessageParser).ParseFrom(new byte[0]); + Assert.DoesNotThrow(() => TestRequired.Parser.ParseFrom(new byte[0])); + Assert.DoesNotThrow(() => (TestRequired.Parser as MessageParser).ParseFrom(new byte[0])); } [Test]