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_Enum() { TestOneof2.Builder builder = TestOneof2.CreateBuilder(); TestOneof2 message = builder.SetFooEnum(TestOneof2.Types.NestedEnum.BAR).Build(); TestOneof2 message2 = TestOneof2.CreateBuilder().MergeFrom(message).Build(); Assert.IsTrue(message2.HasFooEnum); Assert.AreEqual(message2.FooEnum, TestOneof2.Types.NestedEnum.BAR); }
public void TestOneofSerialization_Enum() { TestOneof2.Builder builder = TestOneof2.CreateBuilder(); TestOneof2 message = builder.SetFooEnum(TestOneof2.Types.NestedEnum.BAR).Build(); ByteString serialized = message.ToByteString(); TestOneof2 message2 = TestOneof2.ParseFrom(serialized); Assert.IsTrue(message2.HasFooEnum); Assert.AreEqual(message2.FooEnum, TestOneof2.Types.NestedEnum.BAR); }
public void TestOneofTypes_Enum() { TestOneof2.Builder builder = TestOneof2.CreateBuilder(); Assert.AreEqual(builder.FooEnum, TestOneof2.Types.NestedEnum.FOO); Assert.IsTrue(builder.SetFooEnum(TestOneof2.Types.NestedEnum.BAR).HasFooEnum); Assert.AreEqual(builder.FooEnum, TestOneof2.Types.NestedEnum.BAR); TestOneof2 message = builder.BuildPartial(); Assert.IsTrue(message.HasFooEnum); Assert.AreEqual(message.FooEnum, TestOneof2.Types.NestedEnum.BAR); Assert.IsFalse(builder.ClearFooEnum().HasFooEnum); TestOneof2 message2 = builder.Build(); Assert.IsFalse(message2.HasFooEnum); Assert.AreEqual(message2.FooEnum, TestOneof2.Types.NestedEnum.FOO); }