瀏覽代碼

Add comment and Assert.DoesNotThrow to RequiredFieldsNoThrow

Sydney Acksman 5 年之前
父節點
當前提交
1a0ff9551a
共有 1 個文件被更改,包括 5 次插入2 次删除
  1. 5 2
      csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs

+ 5 - 2
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]