public void TestConvertFromFullComplete()
        {
            TestInteropPerson person = TestInteropPerson.CreateBuilder()
                                       .SetId(123)
                                       .SetName("abc")
                                       .SetEmail("*****@*****.**")
                                       .AddRangeCodes(new[] { 1, 2, 3 })
                                       .AddPhone(TestInteropPerson.Types.PhoneNumber.CreateBuilder().SetNumber("555-1234").Build())
                                       .AddPhone(TestInteropPerson.Types.PhoneNumber.CreateBuilder().SetNumber("555-5678").Build())
                                       .AddAddresses(
                TestInteropPerson.Types.Addresses.CreateBuilder().SetAddress("123 Seseme").SetCity("Wonderland").
                SetState("NA").SetZip(12345).Build())
                                       .SetExtension(UnitTestExtrasFullProtoFile.EmployeeId,
                                                     TestInteropEmployeeId.CreateBuilder().SetNumber("123").Build())
                                       .Build();

            Assert.IsTrue(person.IsInitialized);

            ExtensionRegistry registry = ExtensionRegistry.CreateInstance();

            UnitTestExtrasLiteProtoFile.RegisterAllExtensions(registry);

            TestInteropPersonLite copy = TestInteropPersonLite.ParseFrom(person.ToByteArray(), registry);

            TestUtil.AssertBytesEqual(person.ToByteArray(), copy.ToByteArray());
        }
Esempio n. 2
0
        public void TestRestoreFromOtherType()
        {
            TestInteropPerson person = TestInteropPerson.CreateBuilder()
                                       .SetId(123)
                                       .SetName("abc")
                                       .SetEmail("*****@*****.**")
                                       .AddRangeCodes(new[] { 1, 2, 3 })
                                       .AddPhone(TestInteropPerson.Types.PhoneNumber.CreateBuilder().SetNumber("555-1234").Build())
                                       .AddPhone(TestInteropPerson.Types.PhoneNumber.CreateBuilder().SetNumber("555-5678").Build())
                                       .AddAddresses(
                TestInteropPerson.Types.Addresses.CreateBuilder().SetAddress("123 Seseme").SetCity("Wonderland").
                SetState("NA").SetZip(12345).Build())
                                       .SetExtension(UnittestExtrasFull.EmployeeId,
                                                     TestInteropEmployeeId.CreateBuilder().SetNumber("123").Build())
                                       .Build();

            Assert.IsTrue(person.IsInitialized);

            TestEmptyMessage temp = TestEmptyMessage.ParseFrom(person.ToByteArray());

            Assert.AreEqual(7, temp.UnknownFields.FieldDictionary.Count);
            temp = temp.ToBuilder().Build();
            Assert.AreEqual(7, temp.UnknownFields.FieldDictionary.Count);

            ExtensionRegistry registry = ExtensionRegistry.CreateInstance();

            UnittestExtrasFull.RegisterAllExtensions(registry);

            TestInteropPerson copy = TestInteropPerson.ParseFrom(temp.ToByteArray(), registry);

            Assert.AreEqual(person, copy);
            Assert.AreEqual(person.ToByteArray(), copy.ToByteArray());
        }
Esempio n. 3
0
        public void TestConvertFromFullMinimal()
        {
            TestInteropPerson person = TestInteropPerson.CreateBuilder()
                                       .SetId(123)
                                       .SetName("abc")
                                       .Build();

            Assert.IsTrue(person.IsInitialized);

            TestInteropPersonLite copy = TestInteropPersonLite.ParseFrom(person.ToByteArray());

            Assert.AreEqual(person.ToByteArray(), copy.ToByteArray());
        }
Esempio n. 4
0
        public void TestCompareStringValues()
        {
            TestInteropPersonLite person = TestInteropPersonLite.CreateBuilder()
                                           .SetId(123)
                                           .SetName("abc")
                                           .SetEmail("*****@*****.**")
                                           .AddRangeCodes(new[] { 1, 2, 3 })
                                           .AddPhone(TestInteropPersonLite.Types.PhoneNumber.CreateBuilder().SetNumber("555-1234").Build())
                                           .AddPhone(
                TestInteropPersonLite.Types.PhoneNumber.CreateBuilder().SetNumber(
                    System.Text.Encoding.UTF8.GetString(AllBytes.ToByteArray(), 0, AllBytes.Length)).Build())
                                           .AddAddresses(
                TestInteropPersonLite.Types.Addresses.CreateBuilder().SetAddress("123 Seseme").SetCity("Wonderland")
                .SetState("NA").SetZip(12345).Build())
                                           .SetExtension(UnittestExtrasLite.EmployeeIdLite,
                                                         TestInteropEmployeeIdLite.CreateBuilder().SetNumber("123").Build())
                                           .Build();

            Assert.IsTrue(person.IsInitialized);

            ExtensionRegistry registry = ExtensionRegistry.CreateInstance();

            UnittestExtrasFull.RegisterAllExtensions(registry);

            TestInteropPerson copy = TestInteropPerson.ParseFrom(person.ToByteArray(), registry);

            Assert.AreEqual(person.ToByteArray(), copy.ToByteArray());

            TestInteropPerson.Builder copyBuilder = TestInteropPerson.CreateBuilder();
            TextFormat.Merge(
                person.ToString().Replace("[protobuf_unittest_extra.employee_id_lite]",
                                          "[protobuf_unittest_extra.employee_id]"), registry, copyBuilder);

            copy = copyBuilder.Build();
            Assert.AreEqual(person.ToByteArray(), copy.ToByteArray());

            string liteText = person.ToString().TrimEnd().Replace("\r", "");
            string fullText = copy.ToString().TrimEnd().Replace("\r", "");

            //map the extension type
            liteText = liteText.Replace("[protobuf_unittest_extra.employee_id_lite]",
                                        "[protobuf_unittest_extra.employee_id]");
            //lite version does not indent
            while (fullText.IndexOf("\n ", StringComparison.Ordinal) >= 0)
            {
                fullText = fullText.Replace("\n ", "\n");
            }

            Assert.AreEqual(fullText, liteText);
        }