public void RepeatedAddPrimitiveBeforeBuild() { TestAllTypes message = new TestAllTypes.Builder { RepeatedInt32List = { 1, 2, 3 } }.Build(); TestUtil.AssertEqual(new int[] { 1, 2, 3 }, message.RepeatedInt32List); }
public void ParseUnknownEnumValue() { FieldDescriptor singularField = TestAllTypes.Descriptor.FindDescriptor <FieldDescriptor>("optional_nested_enum"); FieldDescriptor repeatedField = TestAllTypes.Descriptor.FindDescriptor <FieldDescriptor>("repeated_nested_enum"); Assert.IsNotNull(singularField); Assert.IsNotNull(repeatedField); ByteString data = UnknownFieldSet.CreateBuilder() .AddField(singularField.FieldNumber, UnknownField.CreateBuilder() .AddVarint((int)TestAllTypes.Types.NestedEnum.BAR) .AddVarint(5) // not valid .Build()) .AddField(repeatedField.FieldNumber, UnknownField.CreateBuilder() .AddVarint((int)TestAllTypes.Types.NestedEnum.FOO) .AddVarint(4) // not valid .AddVarint((int)TestAllTypes.Types.NestedEnum.BAZ) .AddVarint(6) // not valid .Build()) .Build() .ToByteString(); { TestAllTypes message = TestAllTypes.ParseFrom(data); Assert.AreEqual(TestAllTypes.Types.NestedEnum.BAR, message.OptionalNestedEnum); TestUtil.AssertEqual(new[] { TestAllTypes.Types.NestedEnum.FOO, TestAllTypes.Types.NestedEnum.BAZ }, message.RepeatedNestedEnumList); TestUtil.AssertEqual(new[] { 5UL }, message.UnknownFields[singularField.FieldNumber].VarintList); TestUtil.AssertEqual(new[] { 4UL, 6UL }, message.UnknownFields[repeatedField.FieldNumber].VarintList); } { TestAllExtensions message = TestAllExtensions.ParseFrom(data, TestUtil.CreateExtensionRegistry()); Assert.AreEqual(TestAllTypes.Types.NestedEnum.BAR, message.GetExtension(UnitTestProtoFile.OptionalNestedEnumExtension)); TestUtil.AssertEqual(new[] { TestAllTypes.Types.NestedEnum.FOO, TestAllTypes.Types.NestedEnum.BAZ }, message.GetExtension(UnitTestProtoFile.RepeatedNestedEnumExtension)); TestUtil.AssertEqual(new[] { 5UL }, message.UnknownFields[singularField.FieldNumber].VarintList); TestUtil.AssertEqual(new[] { 4UL, 6UL }, message.UnknownFields[repeatedField.FieldNumber].VarintList); } }
public void RepeatedAppend() { TestAllTypes.Builder builder = TestAllTypes.CreateBuilder(); builder.AddRangeRepeatedInt32(new int[] { 1, 2, 3, 4 }); builder.AddRangeRepeatedForeignEnum((new ForeignEnum[] { ForeignEnum.FOREIGN_BAZ })); ForeignMessage foreignMessage = ForeignMessage.CreateBuilder().SetC(12).Build(); builder.AddRangeRepeatedForeignMessage(new ForeignMessage[] { foreignMessage }); TestAllTypes message = builder.Build(); TestUtil.AssertEqual(message.RepeatedInt32List, new int[] { 1, 2, 3, 4 }); TestUtil.AssertEqual(message.RepeatedForeignEnumList, new ForeignEnum[] { ForeignEnum.FOREIGN_BAZ }); Assert.AreEqual(1, message.RepeatedForeignMessageCount); Assert.AreEqual(12, message.GetRepeatedForeignMessage(0).C); }