Beispiel #1
0
        public void TestXmlWithExtensionEnum()
        {
            TestXmlMessage message = TestXmlMessage.CreateBuilder()
                                     .SetExtension(UnittestExtrasXmltest.ExtensionEnum, EnumOptions.ONE)
                                     .Build();

            StringWriter sw = new StringWriter();

            XmlFormatWriter.CreateInstance(sw).WriteMessage("root", message);

            string xml = sw.ToString();

            ExtensionRegistry registry = ExtensionRegistry.CreateInstance();

            UnittestExtrasXmltest.RegisterAllExtensions(registry);

            XmlFormatReader rdr  = XmlFormatReader.CreateInstance(xml);
            TestXmlMessage  copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build();

            Assert.AreEqual(message, copy);
        }
        protected void FormatterAssert <TMessage>(TMessage message, params string[] expecting) where TMessage : IMessageLite
        {
            StringWriter sw = new StringWriter();

            JsonFormatWriter.CreateInstance(sw).WriteMessage(message);

            Content = sw.ToString();

            ExtensionRegistry registry = ExtensionRegistry.CreateInstance();

            UnittestExtrasXmltest.RegisterAllExtensions(registry);

            IMessageLite copy =
                JsonFormatReader.CreateInstance(Content)
                .Merge(message.WeakCreateBuilderForType(), registry).WeakBuild();

            Assert.AreEqual(typeof(TMessage), copy.GetType());
            Assert.AreEqual(message, copy);
            foreach (string expect in expecting)
            {
                Assert.IsTrue(Content.IndexOf(expect) >= 0);
            }
        }