public void TestOneofTypes_Message()
        {
            TestOneof2.Builder builder = TestOneof2.CreateBuilder();
            Assert.AreEqual(builder.FooMessage.QuxInt, 0);
            builder.SetFooMessage(TestOneof2.Types.NestedMessage.CreateBuilder().SetQuxInt(234).Build());
            Assert.IsTrue(builder.HasFooMessage);
            Assert.AreEqual(builder.FooMessage.QuxInt, 234);
            TestOneof2 message = builder.BuildPartial();

            Assert.IsTrue(message.HasFooMessage);
            Assert.AreEqual(message.FooMessage.QuxInt, 234);

            Assert.IsFalse(builder.ClearFooMessage().HasFooMessage);
            message = builder.Build();
            Assert.IsFalse(message.HasFooMessage);
            Assert.AreEqual(message.FooMessage.QuxInt, 0);

            builder = TestOneof2.CreateBuilder();
            Assert.IsFalse(builder.HasFooMessage);
            builder.SetFooMessage(TestOneof2.Types.NestedMessage.CreateBuilder().SetQuxInt(123));
            Assert.IsTrue(builder.HasFooMessage);
            Assert.AreEqual(builder.FooMessage.QuxInt, 123);
            message = builder.Build();
            Assert.IsTrue(message.HasFooMessage);
            Assert.AreEqual(message.FooMessage.QuxInt, 123);
        }
        public void TestSetOneofClearsOthers()
        {
            TestOneof2.Builder builder = TestOneof2.CreateBuilder();
            TestOneof2         message =
                builder.SetFooInt(123).SetFooString("foo").Build();

            Assert.IsTrue(message.HasFooString);
            TestUtil.AssertAtMostOneFieldSetOneof(message);

            message = builder.SetFooCord("bar").Build();
            Assert.IsTrue(message.HasFooCord);
            TestUtil.AssertAtMostOneFieldSetOneof(message);

            message = builder.SetFooStringPiece("baz").Build();
            Assert.IsTrue(message.HasFooStringPiece);
            TestUtil.AssertAtMostOneFieldSetOneof(message);

            message = builder.SetFooBytes(TestUtil.ToBytes("qux")).Build();
            Assert.IsTrue(message.HasFooBytes);
            TestUtil.AssertAtMostOneFieldSetOneof(message);

            message = builder.SetFooEnum(TestOneof2.Types.NestedEnum.FOO).Build();
            Assert.IsTrue(message.HasFooEnum);
            TestUtil.AssertAtMostOneFieldSetOneof(message);

            message = builder.SetFooMessage(
                TestOneof2.Types.NestedMessage.CreateBuilder().SetQuxInt(234).Build()).Build();
            Assert.IsTrue(message.HasFooMessage);
            TestUtil.AssertAtMostOneFieldSetOneof(message);

            message = builder.SetFooInt(123).Build();
            Assert.IsTrue(message.HasFooInt);
            TestUtil.AssertAtMostOneFieldSetOneof(message);
        }
        public void TestOneofMerge_message()
        {
            TestOneof2.Builder builder = TestOneof2.CreateBuilder();
            TestOneof2         message = builder.SetFooMessage(
                TestOneof2.Types.NestedMessage.CreateBuilder().SetQuxInt(234).Build()).Build();
            TestOneof2 message2 = TestOneof2.CreateBuilder().MergeFrom(message).Build();

            Assert.IsTrue(message2.HasFooMessage);
            Assert.AreEqual(message2.FooMessage.QuxInt, 234);
        }
        public void TestOneofSerialization_Message()
        {
            TestOneof2.Builder builder = TestOneof2.CreateBuilder();
            TestOneof2         message = builder.SetFooMessage(
                TestOneof2.Types.NestedMessage.CreateBuilder().SetQuxInt(234).Build()).Build();
            ByteString serialized = message.ToByteString();
            TestOneof2 message2   = TestOneof2.ParseFrom(serialized);

            Assert.IsTrue(message2.HasFooMessage);
            Assert.AreEqual(message2.FooMessage.QuxInt, 234);
        }