|
|
|
@ -35,8 +35,8 @@ using Proto2 = Google.Protobuf.TestProtos.Proto2; |
|
|
|
|
using NUnit.Framework; |
|
|
|
|
using System; |
|
|
|
|
using System.Collections; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
|
|
|
|
using static Google.Protobuf.TestProtos.Proto2.UnittestExtensions; |
|
|
|
|
|
|
|
|
|
namespace Google.Protobuf.Reflection |
|
|
|
@ -86,8 +86,8 @@ namespace Google.Protobuf.Reflection |
|
|
|
|
var dictionary = (IDictionary) fields[TestMap.MapStringStringFieldNumber].Accessor.GetValue(mapMessage); |
|
|
|
|
Assert.AreEqual(mapMessage.MapStringString, dictionary); |
|
|
|
|
Assert.AreEqual("value1", dictionary["key1"]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
public void GetValue_IncorrectType() |
|
|
|
|
{ |
|
|
|
@ -97,29 +97,29 @@ namespace Google.Protobuf.Reflection |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
public void HasValue_Proto3() |
|
|
|
|
{ |
|
|
|
|
IMessage message = SampleMessages.CreateFullTestAllTypes(); |
|
|
|
|
var fields = message.Descriptor.Fields; |
|
|
|
|
Assert.Throws<InvalidOperationException>(() => (fields[TestProtos.TestAllTypes.SingleBoolFieldNumber].Accessor as IFieldPresenceAccessor).HasValue(message)); |
|
|
|
|
public void HasValue_Proto3() |
|
|
|
|
{ |
|
|
|
|
IMessage message = SampleMessages.CreateFullTestAllTypes(); |
|
|
|
|
var fields = message.Descriptor.Fields; |
|
|
|
|
Assert.Throws<InvalidOperationException>(() => fields[TestProtos.TestAllTypes.SingleBoolFieldNumber].Accessor.HasValue(message)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
public void HasValue() |
|
|
|
|
{ |
|
|
|
|
IMessage message = new Proto2.TestAllTypes(); |
|
|
|
|
var fields = message.Descriptor.Fields; |
|
|
|
|
var accessor = fields[Proto2.TestAllTypes.OptionalBoolFieldNumber].Accessor as IFieldPresenceAccessor; |
|
|
|
|
|
|
|
|
|
Assert.False(accessor.HasValue(message)); |
|
|
|
|
|
|
|
|
|
accessor.SetValue(message, true); |
|
|
|
|
Assert.True(accessor.HasValue(message)); |
|
|
|
|
|
|
|
|
|
accessor.Clear(message); |
|
|
|
|
Assert.False(accessor.HasValue(message)); |
|
|
|
|
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)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
public void SetValue_SingleFields() |
|
|
|
|
{ |
|
|
|
@ -146,8 +146,8 @@ namespace Google.Protobuf.Reflection |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Assert.AreEqual(expected, message); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
public void SetValue_SingleFields_WrongType() |
|
|
|
|
{ |
|
|
|
@ -190,8 +190,8 @@ namespace Google.Protobuf.Reflection |
|
|
|
|
|
|
|
|
|
oneof.Accessor.Clear(message); |
|
|
|
|
Assert.AreEqual(TestProtos.TestAllTypes.OneofFieldOneofCase.None, message.OneofFieldCase); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
public void Clear() |
|
|
|
|
{ |
|
|
|
@ -243,26 +243,26 @@ namespace Google.Protobuf.Reflection |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
public void GetExtensionValue() |
|
|
|
|
{ |
|
|
|
|
var message = SampleMessages.CreateFullTestAllExtensions(); |
|
|
|
|
|
|
|
|
|
// test that the reflector works, since the reflector just runs through IExtendableMessage |
|
|
|
|
Assert.AreEqual(message.GetExtension(OptionalBoolExtension), Proto2.TestAllExtensions.Descriptor.FindFieldByNumber(OptionalBoolExtension.FieldNumber).Accessor.GetValue(message)); |
|
|
|
|
public void GetExtensionValue() |
|
|
|
|
{ |
|
|
|
|
var message = SampleMessages.CreateFullTestAllExtensions(); |
|
|
|
|
|
|
|
|
|
// test that the reflector works, since the reflector just runs through IExtendableMessage |
|
|
|
|
Assert.AreEqual(message.GetExtension(OptionalBoolExtension), Proto2.TestAllExtensions.Descriptor.FindFieldByNumber(OptionalBoolExtension.FieldNumber).Accessor.GetValue(message)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
public void GetRepeatedExtensionValue() |
|
|
|
|
{ |
|
|
|
|
// check to make sure repeated accessor uses GetOrRegister |
|
|
|
|
var message = new Proto2.TestAllExtensions(); |
|
|
|
|
|
|
|
|
|
Assert.IsNull(message.GetExtension(RepeatedBoolExtension)); |
|
|
|
|
Assert.IsNotNull(Proto2.TestAllExtensions.Descriptor.FindFieldByNumber(RepeatedBoolExtension.FieldNumber).Accessor.GetValue(message)); |
|
|
|
|
Assert.IsNotNull(message.GetExtension(RepeatedBoolExtension)); |
|
|
|
|
|
|
|
|
|
message.ClearExtension(RepeatedBoolExtension); |
|
|
|
|
Assert.IsNull(message.GetExtension(RepeatedBoolExtension)); |
|
|
|
|
public void GetRepeatedExtensionValue() |
|
|
|
|
{ |
|
|
|
|
// check to make sure repeated accessor uses GetOrRegister |
|
|
|
|
var message = new Proto2.TestAllExtensions(); |
|
|
|
|
|
|
|
|
|
Assert.IsNull(message.GetExtension(RepeatedBoolExtension)); |
|
|
|
|
Assert.IsNotNull(Proto2.TestAllExtensions.Descriptor.FindFieldByNumber(RepeatedBoolExtension.FieldNumber).Accessor.GetValue(message)); |
|
|
|
|
Assert.IsNotNull(message.GetExtension(RepeatedBoolExtension)); |
|
|
|
|
|
|
|
|
|
message.ClearExtension(RepeatedBoolExtension); |
|
|
|
|
Assert.IsNull(message.GetExtension(RepeatedBoolExtension)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|