public void OneofProperties() { // Switch the oneof case between each of the different options, and check everything behaves // as expected in each case. var message = new TestAllTypes(); Assert.AreEqual("", message.OneofString); Assert.AreEqual(0, message.OneofUint32); Assert.AreEqual(ByteString.Empty, message.OneofBytes); Assert.IsNull(message.OneofNestedMessage); Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.None, message.OneofFieldCase); message.OneofString = "sample"; Assert.AreEqual("sample", message.OneofString); Assert.AreEqual(0, message.OneofUint32); Assert.AreEqual(ByteString.Empty, message.OneofBytes); Assert.IsNull(message.OneofNestedMessage); Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofString, message.OneofFieldCase); var bytes = ByteString.CopyFrom(1, 2, 3); message.OneofBytes = bytes; Assert.AreEqual("", message.OneofString); Assert.AreEqual(0, message.OneofUint32); Assert.AreEqual(bytes, message.OneofBytes); Assert.IsNull(message.OneofNestedMessage); Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofBytes, message.OneofFieldCase); message.OneofUint32 = 20; Assert.AreEqual("", message.OneofString); Assert.AreEqual(20, message.OneofUint32); Assert.AreEqual(ByteString.Empty, message.OneofBytes); Assert.IsNull(message.OneofNestedMessage); Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofUint32, message.OneofFieldCase); var nestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 25 }; message.OneofNestedMessage = nestedMessage; Assert.AreEqual("", message.OneofString); Assert.AreEqual(0, message.OneofUint32); Assert.AreEqual(ByteString.Empty, message.OneofBytes); Assert.AreEqual(nestedMessage, message.OneofNestedMessage); Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofNestedMessage, message.OneofFieldCase); message.ClearOneofField(); Assert.AreEqual("", message.OneofString); Assert.AreEqual(0, message.OneofUint32); Assert.AreEqual(ByteString.Empty, message.OneofBytes); Assert.IsNull(message.OneofNestedMessage); Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.None, message.OneofFieldCase); }
public void OneofProperties() { // Switch the oneof case between each of the different options, and check everything behaves // as expected in each case. var message = new TestAllTypes(); Assert.AreEqual("", message.OneofString); Assert.AreEqual(0, message.OneofUint32); Assert.AreEqual(ByteString.Empty, message.OneofBytes); Assert.IsNull(message.OneofNestedMessage); Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.None, message.OneofFieldCase); message.OneofString = "sample"; Assert.AreEqual("sample", message.OneofString); Assert.AreEqual(0, message.OneofUint32); Assert.AreEqual(ByteString.Empty, message.OneofBytes); Assert.IsNull(message.OneofNestedMessage); Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofString, message.OneofFieldCase); var bytes = ByteString.CopyFrom(1, 2, 3); message.OneofBytes = bytes; Assert.AreEqual("", message.OneofString); Assert.AreEqual(0, message.OneofUint32); Assert.AreEqual(bytes, message.OneofBytes); Assert.IsNull(message.OneofNestedMessage); Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofBytes, message.OneofFieldCase); message.OneofUint32 = 20; Assert.AreEqual("", message.OneofString); Assert.AreEqual(20, message.OneofUint32); Assert.AreEqual(ByteString.Empty, message.OneofBytes); Assert.IsNull(message.OneofNestedMessage); Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofUint32, message.OneofFieldCase); var nestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 25 }; message.OneofNestedMessage = nestedMessage; Assert.AreEqual("", message.OneofString); Assert.AreEqual(0, message.OneofUint32); Assert.AreEqual(ByteString.Empty, message.OneofBytes); Assert.AreEqual(nestedMessage, message.OneofNestedMessage); Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofNestedMessage, message.OneofFieldCase); message.ClearOneofField(); Assert.AreEqual("", message.OneofString); Assert.AreEqual(0, message.OneofUint32); Assert.AreEqual(ByteString.Empty, message.OneofBytes); Assert.IsNull(message.OneofNestedMessage); Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.None, message.OneofFieldCase); }