예제 #1
0
        public void HasValue_Proto2_Repeated()
        {
            var message  = new Proto2.TestAllTypes();
            var accessor = ((IMessage)message).Descriptor.Fields[Proto2.TestAllTypes.RepeatedBoolFieldNumber].Accessor;

            Assert.Throws <InvalidOperationException>(() => accessor.HasValue(message));
        }
예제 #2
0
        public void HasValue_Proto2_Message()
        {
            var message = new Proto2.TestAllTypes();
            var field   = ((IMessage)message).Descriptor.Fields[Proto2.TestAllTypes.OptionalForeignMessageFieldNumber];

            Assert.False(field.Accessor.HasValue(message));
            message.OptionalForeignMessage = new Proto2.ForeignMessage();
            Assert.True(field.Accessor.HasValue(message));
            message.OptionalForeignMessage = null;
            Assert.False(field.Accessor.HasValue(message));
        }
예제 #3
0
        public void HasValue_Proto2_Primitive()
        {
            var message  = new Proto2.TestAllTypes();
            var accessor = ((IMessage)message).Descriptor.Fields[Proto2.TestAllTypes.OptionalInt64FieldNumber].Accessor;

            Assert.IsFalse(accessor.HasValue(message));
            message.OptionalInt64 = 5L;
            Assert.IsTrue(accessor.HasValue(message));
            message.ClearOptionalInt64();
            Assert.IsFalse(accessor.HasValue(message));
            message.OptionalInt64 = 0L;
            Assert.IsTrue(accessor.HasValue(message));
        }
예제 #4
0
        public void HasValue()
        {
            IMessage message  = new Proto2.TestAllTypes();
            var      fields   = message.Descriptor.Fields;
            var      accessor = fields[Proto2.TestAllTypes.OptionalBoolFieldNumber].Accessor;

            Assert.False(accessor.HasValue(message));

            accessor.SetValue(message, true);
            Assert.True(accessor.HasValue(message));

            accessor.Clear(message);
            Assert.False(accessor.HasValue(message));
        }
예제 #5
0
        public void HasValue_Proto2_Oneof()
        {
            var message  = new Proto2.TestAllTypes();
            var accessor = ((IMessage)message).Descriptor.Fields[Proto2.TestAllTypes.OneofStringFieldNumber].Accessor;

            Assert.False(accessor.HasValue(message));
            // Even though it's the default value, we still have a value.
            message.OneofString = "";
            Assert.True(accessor.HasValue(message));
            message.OneofString = "hello";
            Assert.True(accessor.HasValue(message));
            message.OneofUint32 = 10;
            Assert.False(accessor.HasValue(message));
        }
예제 #6
0
        public void Clear_Proto2_Oneof()
        {
            var message  = new Proto2.TestAllTypes();
            var accessor = ((IMessage)message).Descriptor.Fields[Proto2.TestAllTypes.OneofUint32FieldNumber].Accessor;

            // The field accessor Clear method only affects a oneof if the current case is the one being cleared.
            message.OneofString = "hello";
            Assert.AreEqual(Proto2.TestAllTypes.OneofFieldOneofCase.OneofString, message.OneofFieldCase);
            accessor.Clear(message);
            Assert.AreEqual(Proto2.TestAllTypes.OneofFieldOneofCase.OneofString, message.OneofFieldCase);

            message.OneofUint32 = 100;
            Assert.AreEqual(Proto2.TestAllTypes.OneofFieldOneofCase.OneofUint32, message.OneofFieldCase);
            accessor.Clear(message);
            Assert.AreEqual(Proto2.TestAllTypes.OneofFieldOneofCase.None, message.OneofFieldCase);
        }