public void StepArgumentTransformationShouldConvertNumberToBankAccount() { var stepTransformationBinding = stepTransformations.Single(x => x.Method.Name == "CreateBankAccount"); var invoker = new BindingInvoker(new RuntimeConfiguration(), new Mock <IErrorProvider>().Object); TimeSpan duration; var result = invoker.InvokeBinding(stepTransformationBinding, contextManagerStub.Object, new object[] { 1234 }, new Mock <ITestTracer>().Object, out duration); Assert.NotNull(result); Assert.That(result.GetType(), Is.EqualTo(typeof(BankAccount))); Assert.That(((BankAccount)result).AccountNumber, Is.EqualTo(1234)); }
public void TypeToTypeConverterShouldConvertTableToTable() { TypeToTypeConverter stepTransformationInstance = new TypeToTypeConverter(); var transformMethod = stepTransformationInstance.GetType().GetMethod("TableToTableConvert"); var stepTransformationBinding = CreateStepTransformationBinding(@"", transformMethod); var invoker = new BindingInvoker(ConfigurationLoader.GetDefault(), new Mock <IErrorProvider>().Object); TimeSpan duration; var result = invoker.InvokeBinding(stepTransformationBinding, contextManagerStub.Object, new object[] { new Table("h1") }, new Mock <ITestTracer>().Object, out duration); Assert.NotNull(result); Assert.That(result.GetType(), Is.EqualTo(typeof(Table))); Assert.That(((Table)result).Header, Is.EqualTo(new string[] { "transformed column", "h1" })); }
public void TypeToTypeConverterShouldConvertStringToString() { TypeToTypeConverter stepTransformationInstance = new TypeToTypeConverter(); var transformMethod = stepTransformationInstance.GetType().GetMethod("StringToStringConvert"); var stepTransformationBinding = CreateStepTransformationBinding(@"", transformMethod); var invoker = new BindingInvoker(ConfigurationLoader.GetDefault(), new Mock <IErrorProvider>().Object); TimeSpan duration; var result = invoker.InvokeBinding(stepTransformationBinding, contextManagerStub.Object, new object[] { "xyz" }, new Mock <ITestTracer>().Object, out duration); Assert.NotNull(result); Assert.That(result.GetType(), Is.EqualTo(typeof(string))); Assert.That(((string)result), Is.EqualTo("prefix xyz")); }
public async Task TypeToTypeConverterShouldConvertStringToString() { TypeToTypeConverter stepTransformationInstance = new TypeToTypeConverter(); var transformMethod = stepTransformationInstance.GetType().GetMethod("StringToStringConvert"); var stepTransformationBinding = CreateStepTransformationBinding(@"", transformMethod); var invoker = new BindingInvoker(ConfigurationLoader.GetDefault(), new Mock <IErrorProvider>().Object, new BindingDelegateInvoker()); var(result, _) = await invoker.InvokeBindingAsync(stepTransformationBinding, contextManagerStub.Object, new object[] { "xyz" }, new Mock <ITestTracer>().Object); Assert.NotNull(result); result.GetType().Should().Be <string>(); result.Should().Be("prefix xyz"); }
public void StepArgumentTransformationShouldConvertStringToUser() { var stepTransformationBinding = stepTransformations.Single(x => x.Method.Name == "CreateUser"); Assert.True(stepTransformationBinding.Regex.IsMatch("user xyz")); var invoker = new BindingInvoker(new RuntimeConfiguration(), new Mock <IErrorProvider>().Object); TimeSpan duration; var result = invoker.InvokeBinding(stepTransformationBinding, contextManagerStub.Object, new object[] { "xyz" }, new Mock <ITestTracer>().Object, out duration); Assert.NotNull(result); Assert.That(result.GetType(), Is.EqualTo(typeof(User))); Assert.That(((User)result).Name, Is.EqualTo("xyz")); }
public async Task TypeToTypeConverterShouldConvertTableToTable() { TypeToTypeConverter stepTransformationInstance = new TypeToTypeConverter(); var transformMethod = stepTransformationInstance.GetType().GetMethod("TableToTableConvert"); var stepTransformationBinding = CreateStepTransformationBinding(@"", transformMethod); var invoker = new BindingInvoker(ConfigurationLoader.GetDefault(), new Mock <IErrorProvider>().Object, new BindingDelegateInvoker()); var(result, _) = await invoker.InvokeBindingAsync(stepTransformationBinding, contextManagerStub.Object, new object[] { new Table("h1") }, new Mock <ITestTracer>().Object); Assert.NotNull(result); result.GetType().Should().Be <Table>(); ((Table)result).Header.Should().BeEquivalentTo(new string[] { "transformed column", "h1" }); }
public void UserConverterShouldConvertStringToUser() { UserCreator stepTransformationInstance = new UserCreator(); var transformMethod = stepTransformationInstance.GetType().GetMethod("Create"); var stepTransformationBinding = CreateStepTransformationBinding(@"user (\w+)", transformMethod); Assert.True(stepTransformationBinding.Regex.IsMatch("user xyz")); var invoker = new BindingInvoker(ConfigurationLoader.GetDefault(), new Mock <IErrorProvider>().Object); TimeSpan duration; var result = invoker.InvokeBinding(stepTransformationBinding, contextManagerStub.Object, new object[] { "xyz" }, new Mock <ITestTracer>().Object, out duration); Assert.NotNull(result); Assert.That(result.GetType(), Is.EqualTo(typeof(User))); Assert.That(((User)result).Name, Is.EqualTo("xyz")); }
public async Task UserConverterShouldConvertStringToUser() { UserCreator stepTransformationInstance = new UserCreator(); var transformMethod = stepTransformationInstance.GetType().GetMethod("Create"); var stepTransformationBinding = CreateStepTransformationBinding(@"user (\w+)", transformMethod); stepTransformationBinding.Regex.IsMatch("user xyz").Should().BeTrue(); var invoker = new BindingInvoker(ConfigurationLoader.GetDefault(), new Mock <IErrorProvider>().Object, new BindingDelegateInvoker()); var(result, _) = await invoker.InvokeBindingAsync(stepTransformationBinding, contextManagerStub.Object, new object[] { "xyz" }, new Mock <ITestTracer>().Object); Assert.NotNull(result); result.Should().BeOfType <User>(); ((User)result).Name.Should().Be("xyz"); }
public void TypeToTypeConverterShouldConvertStringToStringUsingRegex() { TypeToTypeConverter stepTransformationInstance = new TypeToTypeConverter(); var transformMethod = stepTransformationInstance.GetType().GetMethod("StringToStringConvertRegex"); var stepTransformationBinding = CreateStepTransformationBinding(@"string (\w+)", transformMethod); Assert.True(stepTransformationBinding.Regex.IsMatch("string xyz")); var invoker = new BindingInvoker(ConfigurationLoader.GetDefault(), new Mock <IErrorProvider>().Object, new SynchronousBindingDelegateInvoker()); TimeSpan duration; var result = invoker.InvokeBinding(stepTransformationBinding, contextManagerStub.Object, new object[] { "xyz" }, new Mock <ITestTracer>().Object, out duration); Assert.NotNull(result); result.GetType().Should().Be <string>(); result.Should().Be("prefix xyz"); }
static void BindingMarshal_cb(IntPtr raw_closure, IntPtr return_val, uint n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data) { try { GLib.Value[] inst_and_params = new GLib.Value [n_param_vals]; int gvalue_size = Marshal.SizeOf(typeof(GLib.Value)); for (int idx = 0; idx < n_param_vals; idx++) { inst_and_params [idx] = (GLib.Value)Marshal.PtrToStructure(new IntPtr(param_values.ToInt64() + idx * gvalue_size), typeof(GLib.Value)); } Widget w = inst_and_params [0].Val as Widget; BindingInvoker invoker = binding_invokers [(int)(long)inst_and_params [1]]; invoker.Invoke(w); } catch (Exception e) { GLib.ExceptionManager.RaiseUnhandledException(e, false); } }
static void ClassInit(GLib.GType gtype, Type t) { object[] attrs = t.GetCustomAttributes(typeof(BindingAttribute), true); if (attrs.Length == 0) { return; } string signame = t.Name.Replace(".", "_") + "_bindings"; IntPtr native_signame = GLib.Marshaller.StringToPtrGStrdup(signame); GLib.Object.RegisterSignal(signame, gtype, GLib.Signal.Flags.RunLast | GLib.Signal.Flags.Action, GLib.GType.None, new GLib.GType[] { GLib.GType.Long }, BindingDelegate); if (binding_invokers == null) { binding_invokers = new List <BindingInvoker> (); } foreach (BindingAttribute attr in attrs) { System.Reflection.MethodInfo mi = t.GetMethod(attr.Handler, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public); if (mi == null) { throw new Exception("Instance method " + attr.Handler + " not found in " + t); } GtkBindingArg arg = new GtkBindingArg(); arg.arg_type = GLib.GType.Long.Val; var bi = new BindingInvoker(mi, attr.Parms); binding_invokers.Add(bi); int binding_invoker_idx = binding_invokers.IndexOf(bi); #if WIN64LONGS arg.data.long_data = binding_invoker_idx; #else arg.data.long_data = new IntPtr(binding_invoker_idx); #endif GLib.SList binding_args = new GLib.SList(new object[] { arg }, typeof(GtkBindingArg), false, false); gtk_binding_entry_add_signall(gtk_binding_set_by_class(gtype.GetClassPtr()), (uint)attr.Key, attr.Mod, native_signame, binding_args.Handle); binding_args.Dispose(); } GLib.Marshaller.Free(native_signame); }
static void ClassInit (GLib.GType gtype, Type t) { object[] attrs = t.GetCustomAttributes (typeof (BindingAttribute), true); if (attrs.Length == 0) return; string signame = t.Name.Replace (".", "_") + "_bindings"; IntPtr native_signame = GLib.Marshaller.StringToPtrGStrdup (signame); RegisterSignal (signame, gtype, GLib.Signal.Flags.RunLast | GLib.Signal.Flags.Action, GLib.GType.None, new GLib.GType[] {GLib.GType.Long}, BindingDelegate); if (binding_invokers == null) binding_invokers = new List<BindingInvoker> (); foreach (BindingAttribute attr in attrs) { System.Reflection.MethodInfo mi = t.GetMethod (attr.Handler, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public); if (mi == null) throw new Exception ("Instance method " + attr.Handler + " not found in " + t); GtkBindingArg arg = new GtkBindingArg (); arg.arg_type = GLib.GType.Long.Val; var bi = new BindingInvoker (mi, attr.Parms); binding_invokers.Add (bi); int binding_invoker_idx = binding_invokers.IndexOf (bi); #if WIN64LONGS arg.data.long_data = binding_invoker_idx; #else arg.data.long_data = new IntPtr (binding_invoker_idx); #endif GLib.SList binding_args = new GLib.SList (new object[] {arg}, typeof (GtkBindingArg), false, false); gtk_binding_entry_add_signall (gtk_binding_set_by_class (gtype.GetClassPtr ()), (uint) attr.Key, attr.Mod, native_signame, binding_args.Handle); binding_args.Dispose (); } GLib.Marshaller.Free (native_signame); }