diff --git a/dotnet/Razorvine.Pyrolite/Pyrolite/Pyro/PyroProxy.cs b/dotnet/Razorvine.Pyrolite/Pyrolite/Pyro/PyroProxy.cs index 5253f08..ca90462 100644 --- a/dotnet/Razorvine.Pyrolite/Pyrolite/Pyro/PyroProxy.cs +++ b/dotnet/Razorvine.Pyrolite/Pyrolite/Pyro/PyroProxy.cs @@ -122,7 +122,7 @@ protected void GetMetadata(string objectId) { /// Extract meta data and store it in the relevant properties on the proxy. /// If no attribute or method is exposed at all, throw an exception. /// - private void _processMetadata(IDictionary result) + protected void _processMetadata(IDictionary result) { // the collections in the result can be either an object[] or a HashSet or List, // depending on the serializer and Pyro version that is used @@ -132,12 +132,18 @@ private void _processMetadata(IDictionary result) pyroMethods = methods_array != null ? new HashSet(methods_array.Select(o => o as string)) : GetStringSet(result["methods"]); pyroAttrs = attrs_array != null ? new HashSet(attrs_array.Select(o => o as string)) : GetStringSet(result["attrs"]); - pyroOneway = oneway_array != null ? new HashSet(oneway_array.Select(o => o as string)) : GetStringSet(result["attrs"]); + pyroOneway = oneway_array != null ? new HashSet(oneway_array.Select(o => o as string)) : GetStringSet(result["oneway"]); if(!pyroMethods.Any() && !pyroAttrs.Any()) { throw new PyroException("remote object doesn't expose any methods or attributes"); } } + + protected void _processMetadata(IDictionary data) + { + var dict = (IDictionary) data; + _processMetadata(dict); + } protected static HashSet GetStringSet(object strings) { diff --git a/dotnet/Razorvine.Pyrolite/Tests/Pyro/SerializePyroTests.cs b/dotnet/Razorvine.Pyrolite/Tests/Pyro/SerializePyroTests.cs index 92b404e..43bee3c 100644 --- a/dotnet/Razorvine.Pyrolite/Tests/Pyro/SerializePyroTests.cs +++ b/dotnet/Razorvine.Pyrolite/Tests/Pyro/SerializePyroTests.cs @@ -164,6 +164,97 @@ public void TestBytes() } } + + /// + /// Some tests about the peculiarities of the handshake + /// + public class HandshakeTests + { + class MetadataProxy : PyroProxy + { + public MetadataProxy() : base("test", 999, "object42") + { + } + + public void TestMetadataHashtable(Hashtable table) + { + base._processMetadata(table); + } + + public void TestMetadataDictionary(IDictionary dict) + { + base._processMetadata(dict); + } + + public void TestMetadataGenericDict(IDictionary dict) + { + base._processMetadata(dict); + } + } + + + [Fact] + public void TestHandshakeDicts() + { + var proxy = new MetadataProxy(); + + var hashtable = new Hashtable + { + {"methods", new object[] {"method1"}}, + {"attrs", new List() {"attr1"}}, + {"oneway", new HashSet() {"oneway1"}} + }; + var dict = new SortedList + { + {"methods", new object[] {"method1"}}, + {"attrs", new List() {"attr1"}}, + {"oneway", new HashSet() {"oneway1"}} + }; + var gdict = new Dictionary + { + {"methods", new object[] {"method1"}}, + {"attrs", new List() {"attr1"}}, + {"oneway", new HashSet() {"oneway1"}} + }; + + var expectedMethods = new HashSet {"method1"}; + var expectedAttrs = new HashSet {"attr1"}; + var expectedOneway = new HashSet {"oneway1"}; + + proxy.pyroMethods.Clear(); + proxy.pyroAttrs.Clear(); + proxy.pyroOneway.Clear(); + proxy.TestMetadataHashtable(hashtable); + Assert.Equal(expectedMethods, proxy.pyroMethods); + Assert.Equal(expectedAttrs, proxy.pyroAttrs); + Assert.Equal(expectedOneway, proxy.pyroOneway); + + proxy.pyroMethods.Clear(); + proxy.pyroAttrs.Clear(); + proxy.pyroOneway.Clear(); + proxy.TestMetadataDictionary(dict); + Assert.Equal(expectedMethods, proxy.pyroMethods); + Assert.Equal(expectedAttrs, proxy.pyroAttrs); + Assert.Equal(expectedOneway, proxy.pyroOneway); + + proxy.pyroMethods.Clear(); + proxy.pyroAttrs.Clear(); + proxy.pyroOneway.Clear(); + proxy.TestMetadataDictionary(gdict); + Assert.Equal(expectedMethods, proxy.pyroMethods); + Assert.Equal(expectedAttrs, proxy.pyroAttrs); + Assert.Equal(expectedOneway, proxy.pyroOneway); + + proxy.pyroMethods.Clear(); + proxy.pyroAttrs.Clear(); + proxy.pyroOneway.Clear(); + proxy.TestMetadataGenericDict(gdict); + Assert.Equal(expectedMethods, proxy.pyroMethods); + Assert.Equal(expectedAttrs, proxy.pyroAttrs); + Assert.Equal(expectedOneway, proxy.pyroOneway); + } + } + /// /// Miscellaneous tests. ///