From 61307b86f561721ac47ecd74d9fd1dffa0acad53 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Fri, 29 Apr 2016 10:10:40 +0100 Subject: Allow custom type URL prefixes in Any.Pack (And likewise ignore the prefix in unpack.) Fixes issue #1459. --- .../Google.Protobuf.Test/WellKnownTypes/AnyTest.cs | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs') diff --git a/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs b/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs index f3593e5f..f21be7d9 100644 --- a/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs +++ b/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs @@ -46,6 +46,24 @@ namespace Google.Protobuf.WellKnownTypes Assert.AreEqual(message.CalculateSize(), any.Value.Length); } + [Test] + public void Pack_WithCustomPrefix() + { + var message = SampleMessages.CreateFullTestAllTypes(); + var any = Any.Pack(message, "foo.bar/baz"); + Assert.AreEqual("foo.bar/baz/protobuf_unittest.TestAllTypes", any.TypeUrl); + Assert.AreEqual(message.CalculateSize(), any.Value.Length); + } + + [Test] + public void Pack_WithCustomPrefixTrailingSlash() + { + var message = SampleMessages.CreateFullTestAllTypes(); + var any = Any.Pack(message, "foo.bar/baz/"); + Assert.AreEqual("foo.bar/baz/protobuf_unittest.TestAllTypes", any.TypeUrl); + Assert.AreEqual(message.CalculateSize(), any.Value.Length); + } + [Test] public void Unpack_WrongType() { @@ -63,6 +81,15 @@ namespace Google.Protobuf.WellKnownTypes Assert.AreEqual(message, unpacked); } + [Test] + public void Unpack_CustomPrefix_Success() + { + var message = SampleMessages.CreateFullTestAllTypes(); + var any = Any.Pack(message, "foo.bar/baz"); + var unpacked = any.Unpack(); + Assert.AreEqual(message, unpacked); + } + [Test] public void ToString_WithValues() { -- cgit v1.2.3