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_Primitive() { TestOneof2.Builder builder = TestOneof2.CreateBuilder(); TestOneof2 message = builder.SetFooInt(123).Build(); TestOneof2 message2 = TestOneof2.CreateBuilder().MergeFrom(message).Build(); Assert.IsTrue(message2.HasFooInt); Assert.AreEqual(message2.FooInt, 123); }
public void TestOneofSerialization_Primitive() { TestOneof2.Builder builder = TestOneof2.CreateBuilder(); TestOneof2 message = builder.SetFooInt(123).Build(); ByteString serialized = message.ToByteString(); TestOneof2 message2 = TestOneof2.ParseFrom(serialized); Assert.IsTrue(message2.HasFooInt); Assert.AreEqual(message2.FooInt, 123); }
public void TestOneofTypes_Primitive() { TestOneof2.Builder builder = TestOneof2.CreateBuilder(); Assert.AreEqual(builder.FooInt, 0); Assert.IsFalse(builder.HasFooInt); Assert.IsTrue(builder.SetFooInt(123).HasFooInt); Assert.AreEqual(builder.FooInt, 123); TestOneof2 message = builder.BuildPartial(); Assert.IsTrue(message.HasFooInt); Assert.AreEqual(message.FooInt, 123); Assert.IsFalse(builder.ClearFooInt().HasFooInt); TestOneof2 message2 = builder.Build(); Assert.IsFalse(message2.HasFooInt); Assert.AreEqual(message2.FooInt, 0); }
public void TestOneofTypes_String() { TestOneof2.Builder builder = TestOneof2.CreateBuilder(); Assert.AreEqual(builder.FooString, ""); Assert.IsTrue(builder.SetFooString("foo").HasFooString); Assert.AreEqual(builder.FooString, "foo"); TestOneof2 message = builder.BuildPartial(); Assert.IsTrue(message.HasFooString); Assert.AreEqual(message.FooString, "foo"); Assert.IsFalse(builder.ClearFooString().HasFooString); TestOneof2 message2 = builder.Build(); Assert.IsFalse(message2.HasFooString); Assert.AreEqual(message2.FooString, ""); builder.SetFooInt(123); Assert.AreEqual(builder.FooString, ""); Assert.AreEqual(builder.FooInt, 123); message = builder.Build(); Assert.AreEqual(message.FooString, ""); Assert.AreEqual(message.FooInt, 123); }