浏览代码

one more test, we are done.

csharptest 14 年之前
父节点
当前提交
7b6044f888
共有 1 个文件被更改,包括 21 次插入0 次删除
  1. 21 0
      src/ProtocolBuffers.Test/ReusableBuilderTest.cs

+ 21 - 0
src/ProtocolBuffers.Test/ReusableBuilderTest.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Text;
 using System.Text;
 using NUnit.Framework;
 using NUnit.Framework;
 using Google.ProtocolBuffers.TestProtos;
 using Google.ProtocolBuffers.TestProtos;
+using Google.ProtocolBuffers.Serialization;
 
 
 namespace Google.ProtocolBuffers
 namespace Google.ProtocolBuffers
 {
 {
@@ -50,6 +51,26 @@ namespace Google.ProtocolBuffers
                 TestAllTypes.CreateBuilder().SetOptionalBool(true).Build().ToBuilder().Clear().Build()));
                 TestAllTypes.CreateBuilder().SetOptionalBool(true).Build().ToBuilder().Clear().Build()));
         }
         }
 
 
+        [Test]
+        public void BuildModifyAndRebuild()
+        {
+            TestAllTypes.Builder b1 = new TestAllTypes.Builder();
+            b1.SetDefaultInt32(1);
+            b1.AddRepeatedInt32(2);
+            b1.SetOptionalForeignMessage(ForeignMessage.DefaultInstance);
+
+            TestAllTypes m1 = b1.Build();
+
+            b1.SetDefaultInt32(5);
+            b1.AddRepeatedInt32(6);
+            b1.SetOptionalForeignMessage(b1.OptionalForeignMessage.ToBuilder().SetC(7));
+
+            TestAllTypes m2 = b1.Build();
+            
+            Assert.AreEqual("{\"optional_foreign_message\":{},\"repeated_int32\":[2],\"default_int32\":1}", m1.ToJson());
+            Assert.AreEqual("{\"optional_foreign_message\":{\"c\":7},\"repeated_int32\":[2,6],\"default_int32\":5}", m2.ToJson());
+        }
+
         [Test]
         [Test]
         public void CloneOnChangePrimitive()
         public void CloneOnChangePrimitive()
         {
         {