public void TypeAndInterfaceDescription() { var description = TypeDescription.GetDescriptor(typeof(IValidDBusObjectInterface)); Assert.Equal(typeof(IValidDBusObjectInterface), description.Type); Assert.Equal("tmds.dbus.tests.empty", description.InterfaceName); }
public void ValidMembers(Type type, bool expectedValid) { bool valid = true; try { var description = TypeDescription.GetDescriptor(type); } catch (System.Exception e) { Assert.IsAssignableFrom <ArgumentException>(e); valid = false; } Assert.Equal(expectedValid, valid); }
public void ValidInterfaceType(Type type, bool expectedValid) { var proxyBuilder = new ClientProxyManager(null); bool valid = true; try { var description = TypeDescription.GetDescriptor(type); } catch (System.Exception e) { Assert.IsAssignableFrom <ArgumentException>(e); valid = false; } Assert.Equal(expectedValid, valid); }
public void Properties(Type type) { var description = TypeDescription.GetDescriptor(type); var interf = description.Interfaces[0]; Assert.NotNull(interf.Properties); var nameProperty = interf.Properties.Where(p => p.Name == "Name").SingleOrDefault(); Assert.NotNull(nameProperty); Assert.Equal("s", nameProperty.Signature); var ageProperty = interf.Properties.Where(p => p.Name == "Age").SingleOrDefault(); Assert.NotNull(ageProperty); Assert.Equal("i", ageProperty.Signature); var isMarriedProperty = interf.Properties.Where(p => p.Name == "IsMarried").SingleOrDefault(); Assert.NotNull(isMarriedProperty); Assert.Equal("b", isMarriedProperty.Signature); }
public void UnsupportedInterfaces(Type type) { Assert.Throws <ArgumentException>(() => TypeDescription.GetDescriptor(type)); }
public void MethodDescription() { // Task FooAsync(); var description = TypeDescription.GetDescriptor(typeof(IValidDBusMethod1)); var methodDescription = description.Interfaces[0].Methods[0]; Assert.Equal("Foo", methodDescription.Name); Assert.Equal(null, methodDescription.OutType); Assert.Equal((Signature?)null, methodDescription.InSignature); Assert.Equal((Signature?)null, methodDescription.OutSignature); Assert.Equal(0, methodDescription.InArguments.Count); Assert.Equal(0, methodDescription.OutArguments.Count); Assert.Equal(typeof(IValidDBusMethod1).GetTypeInfo().GetMethod("FooAsync"), methodDescription.MethodInfo); // Task FooAsync(int arg1); description = TypeDescription.GetDescriptor(typeof(IValidDBusMethod2)); methodDescription = description.Interfaces[0].Methods[0]; Assert.Equal("Foo", methodDescription.Name); Assert.Equal(null, methodDescription.OutType); Assert.Equal("i", methodDescription.InSignature); Assert.Equal((Signature?)null, methodDescription.OutSignature); Assert.Equal(0, methodDescription.OutArguments.Count); Assert.Equal(typeof(IValidDBusMethod2).GetTypeInfo().GetMethod("FooAsync"), methodDescription.MethodInfo); Assert.NotNull(methodDescription.InArguments); Assert.Equal(1, methodDescription.InArguments.Count); var argDescription = methodDescription.InArguments[0]; Assert.Equal("arg1", argDescription.Name); Assert.Equal(typeof(int), argDescription.Type); Assert.Equal("i", argDescription.Signature); // Task FooAsync(int arg1, int arg2); description = TypeDescription.GetDescriptor(typeof(IValidDBusMethod3)); methodDescription = description.Interfaces[0].Methods[0]; Assert.Equal("Foo", methodDescription.Name); Assert.Equal(null, methodDescription.OutType); Assert.Equal("ii", methodDescription.InSignature); Assert.Equal((Signature?)null, methodDescription.OutSignature); Assert.Equal(0, methodDescription.OutArguments.Count); Assert.Equal(typeof(IValidDBusMethod3).GetTypeInfo().GetMethod("FooAsync"), methodDescription.MethodInfo); Assert.NotNull(methodDescription.InArguments); Assert.Equal(2, methodDescription.InArguments.Count); argDescription = methodDescription.InArguments[0]; Assert.Equal("arg1", argDescription.Name); Assert.Equal(typeof(int), argDescription.Type); Assert.Equal("i", argDescription.Signature); argDescription = methodDescription.InArguments[1]; Assert.Equal("arg2", argDescription.Name); Assert.Equal(typeof(int), argDescription.Type); Assert.Equal("i", argDescription.Signature); // Task FooAsync(IntPair val); description = TypeDescription.GetDescriptor(typeof(IValidDBusMethod4)); methodDescription = description.Interfaces[0].Methods[0]; Assert.Equal("Foo", methodDescription.Name); Assert.Equal(null, methodDescription.OutType); Assert.Equal("(ii)", methodDescription.InSignature); Assert.Equal((Signature?)null, methodDescription.OutSignature); Assert.Equal(0, methodDescription.OutArguments.Count); Assert.Equal(typeof(IValidDBusMethod4).GetTypeInfo().GetMethod("FooAsync"), methodDescription.MethodInfo); Assert.NotNull(methodDescription.InArguments); Assert.Equal(1, methodDescription.InArguments.Count); argDescription = methodDescription.InArguments[0]; Assert.Equal("val", argDescription.Name); Assert.Equal(typeof(IntPair), argDescription.Type); Assert.Equal("(ii)", argDescription.Signature); // Task FooAsync([Argument("arg")]IntPair val); description = TypeDescription.GetDescriptor(typeof(IValidDBusMethod5)); methodDescription = description.Interfaces[0].Methods[0]; Assert.Equal("Foo", methodDescription.Name); Assert.Equal(null, methodDescription.OutType); Assert.Equal("(ii)", methodDescription.InSignature); Assert.Equal((Signature?)null, methodDescription.OutSignature); Assert.Equal(0, methodDescription.OutArguments.Count); Assert.Equal(typeof(IValidDBusMethod5).GetTypeInfo().GetMethod("FooAsync"), methodDescription.MethodInfo); Assert.NotNull(methodDescription.InArguments); Assert.Equal(1, methodDescription.InArguments.Count); argDescription = methodDescription.InArguments[0]; Assert.Equal("arg", argDescription.Name); Assert.Equal(typeof(IntPair), argDescription.Type); Assert.Equal("(ii)", argDescription.Signature); // Task<int> FooAsync(); description = TypeDescription.GetDescriptor(typeof(IValidDBusMethod6)); methodDescription = description.Interfaces[0].Methods[0]; Assert.Equal("Foo", methodDescription.Name); Assert.Equal(typeof(int), methodDescription.OutType); Assert.Equal((Signature?)null, methodDescription.InSignature); Assert.Equal("i", methodDescription.OutSignature); Assert.Equal(0, methodDescription.InArguments.Count); Assert.Equal(typeof(IValidDBusMethod6).GetTypeInfo().GetMethod("FooAsync"), methodDescription.MethodInfo); Assert.NotNull(methodDescription.OutArguments); Assert.Equal(1, methodDescription.OutArguments.Count); argDescription = methodDescription.OutArguments[0]; Assert.Equal("value", argDescription.Name); Assert.Equal(typeof(int), argDescription.Type); Assert.Equal("i", argDescription.Signature); // Task<IntPair> FooAsync(); description = TypeDescription.GetDescriptor(typeof(IValidDBusMethod7)); methodDescription = description.Interfaces[0].Methods[0]; Assert.Equal("Foo", methodDescription.Name); Assert.Equal(typeof(IntPair), methodDescription.OutType); Assert.Equal((Signature?)null, methodDescription.InSignature); Assert.Equal("ii", methodDescription.OutSignature); Assert.Equal(0, methodDescription.InArguments.Count); Assert.Equal(typeof(IValidDBusMethod7).GetTypeInfo().GetMethod("FooAsync"), methodDescription.MethodInfo); Assert.NotNull(methodDescription.OutArguments); Assert.Equal(2, methodDescription.OutArguments.Count); argDescription = methodDescription.OutArguments[0]; Assert.Equal("arg1", argDescription.Name); Assert.Equal(typeof(int), argDescription.Type); Assert.Equal("i", argDescription.Signature); argDescription = methodDescription.OutArguments[1]; Assert.Equal("arg2", argDescription.Name); Assert.Equal(typeof(int), argDescription.Type); Assert.Equal("i", argDescription.Signature); // [return: Argument("arg")] // Task<IntPair> FooAsync(); description = TypeDescription.GetDescriptor(typeof(IValidDBusMethod8)); methodDescription = description.Interfaces[0].Methods[0]; Assert.Equal("Foo", methodDescription.Name); Assert.Equal(typeof(IntPair), methodDescription.OutType); Assert.Equal((Signature?)null, methodDescription.InSignature); Assert.Equal("(ii)", methodDescription.OutSignature); Assert.Equal(0, methodDescription.InArguments.Count); Assert.Equal(typeof(IValidDBusMethod8).GetTypeInfo().GetMethod("FooAsync"), methodDescription.MethodInfo); Assert.NotNull(methodDescription.OutArguments); Assert.Equal(1, methodDescription.OutArguments.Count); argDescription = methodDescription.OutArguments[0]; Assert.Equal("arg", argDescription.Name); Assert.Equal(typeof(IntPair), argDescription.Type); Assert.Equal("(ii)", argDescription.Signature); // Task<(int arg1, string arg2)> FooAsync(); description = TypeDescription.GetDescriptor(typeof(IValidDBusMethod9)); methodDescription = description.Interfaces[0].Methods[0]; Assert.Equal("Foo", methodDescription.Name); Assert.Equal(typeof(ValueTuple <int, string>), methodDescription.OutType); Assert.Equal((Signature?)null, methodDescription.InSignature); Assert.Equal("is", methodDescription.OutSignature); Assert.Equal(0, methodDescription.InArguments.Count); Assert.Equal(typeof(IValidDBusMethod9).GetTypeInfo().GetMethod("FooAsync"), methodDescription.MethodInfo); Assert.NotNull(methodDescription.OutArguments); Assert.Equal(2, methodDescription.OutArguments.Count); argDescription = methodDescription.OutArguments[0]; Assert.Equal("arg1", argDescription.Name); Assert.Equal(typeof(int), argDescription.Type); Assert.Equal("i", argDescription.Signature); argDescription = methodDescription.OutArguments[1]; Assert.Equal("arg2", argDescription.Name); Assert.Equal(typeof(string), argDescription.Type); Assert.Equal("s", argDescription.Signature); // Task<ValueTuple<int, string>> FooAsync(); description = TypeDescription.GetDescriptor(typeof(IValidDBusMethod10)); methodDescription = description.Interfaces[0].Methods[0]; Assert.Equal("Foo", methodDescription.Name); Assert.Equal(typeof(ValueTuple <int, string>), methodDescription.OutType); Assert.Equal((Signature?)null, methodDescription.InSignature); Assert.Equal("is", methodDescription.OutSignature); Assert.Equal(0, methodDescription.InArguments.Count); Assert.Equal(typeof(IValidDBusMethod10).GetTypeInfo().GetMethod("FooAsync"), methodDescription.MethodInfo); Assert.NotNull(methodDescription.OutArguments); Assert.Equal(2, methodDescription.OutArguments.Count); argDescription = methodDescription.OutArguments[0]; Assert.Equal("Item1", argDescription.Name); Assert.Equal(typeof(int), argDescription.Type); Assert.Equal("i", argDescription.Signature); argDescription = methodDescription.OutArguments[1]; Assert.Equal("Item2", argDescription.Name); Assert.Equal(typeof(string), argDescription.Type); Assert.Equal("s", argDescription.Signature); // [return: Argument("arg")] // Task<(int arg1, string arg2)> FooAsync(); description = TypeDescription.GetDescriptor(typeof(IValidDBusMethod11)); methodDescription = description.Interfaces[0].Methods[0]; Assert.Equal("Foo", methodDescription.Name); Assert.Equal(typeof(ValueTuple <int, string>), methodDescription.OutType); Assert.Equal((Signature?)null, methodDescription.InSignature); Assert.Equal("(is)", methodDescription.OutSignature); Assert.Equal(0, methodDescription.InArguments.Count); Assert.Equal(typeof(IValidDBusMethod11).GetTypeInfo().GetMethod("FooAsync"), methodDescription.MethodInfo); Assert.NotNull(methodDescription.OutArguments); Assert.Equal(1, methodDescription.OutArguments.Count); argDescription = methodDescription.OutArguments[0]; Assert.Equal("arg", argDescription.Name); Assert.Equal(typeof(ValueTuple <int, string>), argDescription.Type); Assert.Equal("(is)", argDescription.Signature); // Task FooAsync(ValueTuple<int, string> val); description = TypeDescription.GetDescriptor(typeof(IValidDBusMethod12)); methodDescription = description.Interfaces[0].Methods[0]; Assert.Equal("Foo", methodDescription.Name); Assert.Equal(null, methodDescription.OutType); Assert.Equal("(is)", methodDescription.InSignature); Assert.Equal((Signature?)null, methodDescription.OutSignature); Assert.Equal(0, methodDescription.OutArguments.Count); Assert.Equal(typeof(IValidDBusMethod12).GetTypeInfo().GetMethod("FooAsync"), methodDescription.MethodInfo); Assert.NotNull(methodDescription.InArguments); Assert.Equal(1, methodDescription.InArguments.Count); argDescription = methodDescription.InArguments[0]; Assert.Equal("val", argDescription.Name); Assert.Equal(typeof(ValueTuple <int, string>), argDescription.Type); Assert.Equal("(is)", argDescription.Signature); // Task FooAsync([Argument("arg")]ValueTuple<int, string> val); description = TypeDescription.GetDescriptor(typeof(IValidDBusMethod13)); methodDescription = description.Interfaces[0].Methods[0]; Assert.Equal("Foo", methodDescription.Name); Assert.Equal(null, methodDescription.OutType); Assert.Equal("(is)", methodDescription.InSignature); Assert.Equal((Signature?)null, methodDescription.OutSignature); Assert.Equal(0, methodDescription.OutArguments.Count); Assert.Equal(typeof(IValidDBusMethod13).GetTypeInfo().GetMethod("FooAsync"), methodDescription.MethodInfo); Assert.NotNull(methodDescription.InArguments); Assert.Equal(1, methodDescription.InArguments.Count); argDescription = methodDescription.InArguments[0]; Assert.Equal("arg", argDescription.Name); Assert.Equal(typeof(ValueTuple <int, string>), argDescription.Type); Assert.Equal("(is)", argDescription.Signature); }
public void SignalDescription() { // Task<IDisposable> WatchSomethingAsync(Action a); var description = TypeDescription.GetDescriptor(typeof(IValidSignal1)); var signalDescription = description.Interfaces[0].Signals[0]; Assert.Equal("Something", signalDescription.Name); Assert.Equal(false, signalDescription.HasOnError); Assert.Equal(null, signalDescription.SignalType); Assert.Equal(typeof(Action), signalDescription.ActionType); Assert.Equal((Signature?)null, signalDescription.SignalSignature); Assert.Equal(0, signalDescription.SignalArguments.Count); Assert.Equal(typeof(IValidSignal1).GetTypeInfo().GetMethod("WatchSomethingAsync"), signalDescription.MethodInfo); // Task<IDisposable> WatchSomethingAsync(Action<int> a); description = TypeDescription.GetDescriptor(typeof(IValidSignal2)); signalDescription = description.Interfaces[0].Signals[0]; Assert.Equal("Something", signalDescription.Name); Assert.Equal(false, signalDescription.HasOnError); Assert.Equal(typeof(int), signalDescription.SignalType); Assert.Equal(typeof(Action <int>), signalDescription.ActionType); Assert.Equal("i", signalDescription.SignalSignature); Assert.Equal(typeof(IValidSignal2).GetTypeInfo().GetMethod("WatchSomethingAsync"), signalDescription.MethodInfo); Assert.NotNull(signalDescription.SignalArguments); Assert.Equal(1, signalDescription.SignalArguments.Count); var argDescription = signalDescription.SignalArguments[0]; Assert.Equal("value", argDescription.Name); Assert.Equal(typeof(int), argDescription.Type); Assert.Equal("i", argDescription.Signature); // Task<IDisposable> WatchSomethingAsync(Action<IntPair> a); description = TypeDescription.GetDescriptor(typeof(IValidSignal3)); signalDescription = description.Interfaces[0].Signals[0]; Assert.Equal("Something", signalDescription.Name); Assert.Equal(typeof(IntPair), signalDescription.SignalType); Assert.Equal(typeof(Action <IntPair>), signalDescription.ActionType); Assert.Equal("ii", signalDescription.SignalSignature); Assert.Equal(typeof(IValidSignal3).GetTypeInfo().GetMethod("WatchSomethingAsync"), signalDescription.MethodInfo); Assert.NotNull(signalDescription.SignalArguments); Assert.Equal(2, signalDescription.SignalArguments.Count); argDescription = signalDescription.SignalArguments[0]; Assert.Equal("arg1", argDescription.Name); Assert.Equal(typeof(int), argDescription.Type); Assert.Equal("i", argDescription.Signature); argDescription = signalDescription.SignalArguments[1]; Assert.Equal("arg2", argDescription.Name); Assert.Equal(typeof(int), argDescription.Type); Assert.Equal("i", argDescription.Signature); //Task<IDisposable> WatchSomethingAsync([Argument("myArg")]Action<IntPair> a); description = TypeDescription.GetDescriptor(typeof(IValidSignal4)); signalDescription = description.Interfaces[0].Signals[0]; Assert.Equal("Something", signalDescription.Name); Assert.Equal(typeof(IntPair), signalDescription.SignalType); Assert.Equal(typeof(Action <IntPair>), signalDescription.ActionType); Assert.Equal("(ii)", signalDescription.SignalSignature); Assert.Equal(typeof(IValidSignal4).GetTypeInfo().GetMethod("WatchSomethingAsync"), signalDescription.MethodInfo); Assert.NotNull(signalDescription.SignalArguments); Assert.Equal(1, signalDescription.SignalArguments.Count); argDescription = signalDescription.SignalArguments[0]; Assert.Equal("myArg", argDescription.Name); Assert.Equal(typeof(IntPair), argDescription.Type); Assert.Equal("(ii)", argDescription.Signature); // Task<IDisposable> WatchSomethingAsync(Action<(int arg1, string arg2)> a); description = TypeDescription.GetDescriptor(typeof(IValidSignal5)); signalDescription = description.Interfaces[0].Signals[0]; Assert.Equal("Something", signalDescription.Name); Assert.Equal(typeof(ValueTuple <int, string>), signalDescription.SignalType); Assert.Equal(typeof(Action <ValueTuple <int, string> >), signalDescription.ActionType); Assert.Equal("is", signalDescription.SignalSignature); Assert.Equal(typeof(IValidSignal5).GetTypeInfo().GetMethod("WatchSomethingAsync"), signalDescription.MethodInfo); Assert.NotNull(signalDescription.SignalArguments); Assert.Equal(2, signalDescription.SignalArguments.Count); argDescription = signalDescription.SignalArguments[0]; Assert.Equal("arg1", argDescription.Name); Assert.Equal(typeof(int), argDescription.Type); Assert.Equal("i", argDescription.Signature); argDescription = signalDescription.SignalArguments[1]; Assert.Equal("arg2", argDescription.Name); Assert.Equal(typeof(string), argDescription.Type); Assert.Equal("s", argDescription.Signature); // Task<IDisposable> WatchSomethingAsync(Action<ValueTuple<int, string>> a); description = TypeDescription.GetDescriptor(typeof(IValidSignal6)); signalDescription = description.Interfaces[0].Signals[0]; Assert.Equal("Something", signalDescription.Name); Assert.Equal(typeof(ValueTuple <int, string>), signalDescription.SignalType); Assert.Equal(typeof(Action <ValueTuple <int, string> >), signalDescription.ActionType); Assert.Equal("is", signalDescription.SignalSignature); Assert.Equal(typeof(IValidSignal6).GetTypeInfo().GetMethod("WatchSomethingAsync"), signalDescription.MethodInfo); Assert.NotNull(signalDescription.SignalArguments); Assert.Equal(2, signalDescription.SignalArguments.Count); argDescription = signalDescription.SignalArguments[0]; Assert.Equal("Item1", argDescription.Name); Assert.Equal(typeof(int), argDescription.Type); Assert.Equal("i", argDescription.Signature); argDescription = signalDescription.SignalArguments[1]; Assert.Equal("Item2", argDescription.Name); Assert.Equal(typeof(string), argDescription.Type); Assert.Equal("s", argDescription.Signature); // Task<IDisposable> WatchSomethingAsync([Argument("myArg")]Action<(int arg1, string arg2)> a); description = TypeDescription.GetDescriptor(typeof(IValidSignal7)); signalDescription = description.Interfaces[0].Signals[0]; Assert.Equal("Something", signalDescription.Name); Assert.Equal(typeof(ValueTuple <int, string>), signalDescription.SignalType); Assert.Equal(typeof(Action <ValueTuple <int, string> >), signalDescription.ActionType); Assert.Equal("(is)", signalDescription.SignalSignature); Assert.Equal(typeof(IValidSignal7).GetTypeInfo().GetMethod("WatchSomethingAsync"), signalDescription.MethodInfo); Assert.NotNull(signalDescription.SignalArguments); Assert.Equal(1, signalDescription.SignalArguments.Count); argDescription = signalDescription.SignalArguments[0]; Assert.Equal("myArg", argDescription.Name); Assert.Equal(typeof(ValueTuple <int, string>), argDescription.Type); Assert.Equal("(is)", argDescription.Signature); // Task<IDisposable> WatchSomethingAsync(Action a, Action<Exception>); description = TypeDescription.GetDescriptor(typeof(IValidSignal8)); signalDescription = description.Interfaces[0].Signals[0]; Assert.Equal("Something", signalDescription.Name); Assert.Equal(true, signalDescription.HasOnError); Assert.Equal(null, signalDescription.SignalType); Assert.Equal(typeof(Action), signalDescription.ActionType); Assert.Equal((Signature?)null, signalDescription.SignalSignature); Assert.Equal(0, signalDescription.SignalArguments.Count); Assert.Equal(typeof(IValidSignal8).GetTypeInfo().GetMethod("WatchSomethingAsync"), signalDescription.MethodInfo); // Task<IDisposable> WatchSomethingAsync(Action<int> a, Action<Exception>); description = TypeDescription.GetDescriptor(typeof(IValidSignal9)); signalDescription = description.Interfaces[0].Signals[0]; Assert.Equal("Something", signalDescription.Name); Assert.Equal(true, signalDescription.HasOnError); Assert.Equal(typeof(int), signalDescription.SignalType); Assert.Equal(typeof(Action <int>), signalDescription.ActionType); Assert.Equal("i", signalDescription.SignalSignature); Assert.Equal(typeof(IValidSignal9).GetTypeInfo().GetMethod("WatchSomethingAsync"), signalDescription.MethodInfo); Assert.NotNull(signalDescription.SignalArguments); Assert.Equal(1, signalDescription.SignalArguments.Count); argDescription = signalDescription.SignalArguments[0]; Assert.Equal("value", argDescription.Name); Assert.Equal(typeof(int), argDescription.Type); Assert.Equal("i", argDescription.Signature); }