public void TestMissingExtensionsLite() { const int optionalInt32 = 12345678; TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder(); builder.SetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite, optionalInt32); builder.AddExtension(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite, 1.1); builder.AddExtension(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite, 1.2); builder.AddExtension(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite, 1.3); TestAllExtensionsLite msg = builder.Build(); Assert.IsTrue(msg.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite)); Assert.AreEqual(3, msg.GetExtensionCount(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite)); byte[] bits = msg.ToByteArray(); TestAllExtensionsLite copy = TestAllExtensionsLite.ParseFrom(bits); Assert.IsFalse(copy.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite)); Assert.AreEqual(0, copy.GetExtensionCount(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite)); Assert.AreNotEqual(msg, copy); //The lite runtime removes all unknown fields and extensions byte[] copybits = copy.ToByteArray(); Assert.AreEqual(0, copybits.Length); }
public void TestSetExtensionTIndex() { TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder() .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0) .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 1) .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 2); for (int i = 0; i < 3; i++) { Assert.AreEqual(i, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, i)); } builder.SetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0, 5); builder.SetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 1, 6); builder.SetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 2, 7); for (int i = 0; i < 3; i++) { Assert.AreEqual(5 + i, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, i)); } }
public void TestSetExtensionTIndexOutOfRange() { TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder(); builder.SetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0, -1); }
public void TestSetExtensionTIndexOutOfRange() { TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder(); Assert.Throws <ArgumentOutOfRangeException>(() => builder.SetExtension(UnittestLite.RepeatedInt32ExtensionLite, 0, -1)); }