Beispiel #1
0
        public void TestGetExtensionTValue()
        {
            TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
                                                    .SetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite, 3);

            Assert.AreEqual(3, builder.GetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite));
        }
Beispiel #2
0
        public void TestGetExtensionTNull()
        {
            TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
            string value = builder.GetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite);

            Assert.IsNull(value);
        }
Beispiel #3
0
        public void TestIndexedByDescriptor()
        {
            TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
            Assert.IsFalse(builder.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite));

            builder[UnitTestLiteProtoFile.OptionalInt32ExtensionLite.Descriptor] = 123;

            Assert.IsTrue(builder.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite));
            Assert.AreEqual(123, builder.GetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite));
        }
Beispiel #4
0
        public void TestGetExtensionTList()
        {
            TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
                                                    .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 1)
                                                    .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 2)
                                                    .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 3);

            IList <int> values = builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite);

            Assert.AreEqual(3, values.Count);
        }
Beispiel #5
0
        public void TestAddRepeatedFieldByDescriptor()
        {
            TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
                                                    .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0);
            Assert.AreEqual(1, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite));

            IFieldDescriptorLite f = UnitTestLiteProtoFile.RepeatedInt32ExtensionLite.Descriptor;

            builder.AddRepeatedField(f, 123);
            Assert.AreEqual(2, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite));
            Assert.AreEqual(123, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 1));
        }
Beispiel #6
0
        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 TestGetExtensionTIndex()
        {
            TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
                                                    .AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 0)
                                                    .AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 1)
                                                    .AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 2);

            for (int i = 0; i < 3; i++)
            {
                Assert.AreEqual(i, builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, i));
            }
        }
Beispiel #8
0
        public void TestIndexedByDescriptorAndOrdinal()
        {
            TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
                                                    .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0);
            Assert.AreEqual(1, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite));

            IFieldDescriptorLite f = UnitTestLiteProtoFile.RepeatedInt32ExtensionLite.Descriptor;

            builder[f, 0] = 123;

            Assert.AreEqual(1, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite));
            Assert.AreEqual(123, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0));
        }
Beispiel #9
0
 public void TestGetExtensionTEmpty()
 {
     TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
     Assert.AreEqual(0, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite).Count);
 }
Beispiel #10
0
 public void TestGetExtensionTIndexOutOfRange()
 {
     TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
     builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0);
 }
 public void TestGetExtensionTIndexOutOfRange()
 {
     TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
     Assert.Throws <ArgumentOutOfRangeException>(() => builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, 0));
 }