public async Task ExecuteAsync(ReceivePipelineContext ctx, Func <Task> next) { var message = ctx.Load <Message>(); var messageId = await _dataStorage.StoreReceivedMessageAsync(new Persistence.ReceivedDbMessage() { Body = message.Body, Headers = message.Headers }); if (messageId == null) { //TODO: Canceled vote in context? return; } //TODO: co tutaj robi transakcja? bo powinno się kończyć na samym dole if (Transaction.Current != null) { var commitAction = ctx.Load <Func <Task> >(ReceivePipelineContext.CommitMessageAction); // Transaction.Current.TransactionCompleted += (sender, args) => // { // Transaction.Current.en // if(args.Transaction.TransactionInformation.) // commitAction() // } } await FuncInvoker.Invoke(next); //coś jeszcze będzie potrzebne? Mógł nie mieć handlera }
public void TestInvokeOut() { Assert.That( () => FuncInvoker.Create(typeof(Guid).GetMethod(nameof(Guid.TryParse))), Throws.TypeOf <NotSupportedException>() ); }
public void TestInvoke0() { // ReSharper disable once PossibleNullReferenceException var getLength = FuncInvoker.Create(typeof(string).GetProperty(nameof(string.Length)).GetMethod); Assert.That((int)getLength.Invoke(_string), Is.EqualTo(_string.Length)); }
public void TestInvokeVoid() { Assert.That( () => FuncInvoker.Create(typeof(TestFuncInvoker).GetMethod(nameof(SetUp))), Throws.TypeOf <NotSupportedException>() ); }
public void AfterActionCanReplaceResult() { ClassWithCtors fixedInstance = new ClassWithCtors(0); FuncInvoker <ClassWithCtors> activator = new FuncInvoker <ClassWithCtors> (new ConstructorLookupInfo(typeof(ClassWithCtors)).GetDelegate);; FuncInvokerWrapper <ClassWithCtors> wrapper = new FuncInvokerWrapper <ClassWithCtors> (activator, delegate(ClassWithCtors instance) { return(fixedInstance); }); ClassWithCtors one = wrapper.With(0); Assert.That(one, Is.SameAs(fixedInstance)); ClassWithCtors two = wrapper.With(0, "1"); Assert.That(two, Is.SameAs(fixedInstance)); ClassWithCtors threeInvoked1 = wrapper.Invoke(new object[] { 0, "1", 2 }); Assert.That(threeInvoked1, Is.SameAs(fixedInstance)); ClassWithCtors threeInvoked2 = wrapper.Invoke(new Type[] { typeof(int), typeof(string), typeof(int) }, new object[] { 0, "1", 2 }); Assert.That(threeInvoked2, Is.SameAs(fixedInstance)); }
public void TestThatFiveParametersIsTooMany() { Assert.That( () => FuncInvoker.Create(typeof(TestFuncInvoker).GetMethod(nameof(FiveParameters))), Throws.TypeOf <NotSupportedException>() ); }
public Task ExecuteAsync(OutgoingPipelineContext ctx, Func <Task> next) { var message = ctx.Load <Messages.Message>(); message.Headers.Add(Messages.MessageHeaders.DestinationAddress, _destinationAddressProvider.Get(message.Body.GetType())); return(FuncInvoker.Invoke(next)); }
public Task ExecuteAsync(OutgoingPipelineContext ctx, Func <Task> next) { var message = ctx.Load <Messages.Message>(); message.Headers[MessageHeaders.EventType] = MessageTypeConverters.GetTypeName(message.Body.GetType()); return(FuncInvoker.Invoke(next)); }
public void TestInvoke2() { var endsWith = FuncInvoker.Create( typeof(string).GetMethod("EndsWith", new[] { typeof(string), typeof(StringComparison) }) ); Assert.That((bool)endsWith.Invoke(_string, "BAR", StringComparison.OrdinalIgnoreCase), Is.True); }
public async Task ExecuteAsync(ReceivePipelineContext ctx, Func <Task> next) { var transportMessage = ctx.Load <TransportMessage>(); var serializer = _serializerFactory.Create(transportMessage); ctx.Save <Message>(await serializer.DeserializeAsync(transportMessage)); await FuncInvoker.Invoke(next); }
public async Task ExecuteAsync(ReceivePipelineContext ctx, Func <Task> next) { using (var tran = new TransactionScope( TransactionScopeOption.Required, TransactionScopeAsyncFlowOption.Enabled)) { await FuncInvoker.Invoke(next); tran.Complete(); } }
//Action(with no return type) and Func(with return type).... static void InvokeFunc(FuncInvoker func) { //Take the inputs for the required args... Console.WriteLine("Enter one double value"); double v1 = double.Parse(Console.ReadLine()); Console.WriteLine("Enter one more double value"); double v2 = double.Parse(Console.ReadLine()); func(v1, v2);//Call the function.... }
public async Task ExecuteAsync(ReceivePipelineContext ctx, Func <Task> next) { var message = ctx.Load <Message>(); var messageType = message.Headers[MessageHeaders.EventType]; var handlerType = MessageHandlersMapper.GetHandler(messageType); //TODO: może ten scope powinien się na równi z transakcją dziać, nawet by pasowało using (var scope = _serviceProvider.CreateScope()) { var handler = (IMessageHandler)scope.ServiceProvider.GetRequiredService(handlerType); await handler.HandleAsync((IMessage)ctx.Load <Message>().Body); } await FuncInvoker.Invoke(next); }
public void AfterActionIsExecuted() { bool afterActionCalled = false; FuncInvoker <ClassWithCtors> activator = new FuncInvoker <ClassWithCtors> (new ConstructorLookupInfo(typeof(ClassWithCtors)).GetDelegate);; FuncInvokerWrapper <ClassWithCtors> wrapper = new FuncInvokerWrapper <ClassWithCtors> (activator, delegate(ClassWithCtors instance) { afterActionCalled = true; return(instance); }); ClassWithCtors one = wrapper.With(0); Assert.That(afterActionCalled, Is.True); Assert.That(one.Ctor, Is.EqualTo("one")); afterActionCalled = false; ClassWithCtors two = wrapper.With(0, "1"); Assert.That(afterActionCalled, Is.True); Assert.That(two.Ctor, Is.EqualTo("two")); afterActionCalled = false; ClassWithCtors three = wrapper.With(0, "1", 2); Assert.That(afterActionCalled, Is.True); Assert.That(three.Ctor, Is.EqualTo("three")); afterActionCalled = false; ClassWithCtors threeInvoked1 = wrapper.Invoke(new object[] { 0, "1", 2 }); Assert.That(afterActionCalled, Is.True); Assert.That(threeInvoked1.Ctor, Is.EqualTo("three")); afterActionCalled = false; ClassWithCtors threeInvoked2 = wrapper.Invoke(new Type[] { typeof(int), typeof(string), typeof(int) }, new object[] { 0, "1", 2 }); Assert.That(afterActionCalled, Is.True); Assert.That(threeInvoked2.Ctor, Is.EqualTo("three")); }
public void TestStaticInvoke1() { var checkHostName = FuncInvoker.Create(typeof(Uri).GetMethod(nameof(Uri.CheckHostName))); Assert.That((UriHostNameType)checkHostName.Invoke("www.test.com"), Is.EqualTo(UriHostNameType.Dns)); }
public void TestInvoke0() { var getLength = FuncInvoker.Create(typeof(string).GetProperty("Length").GetMethod); Assert.That((int)getLength.Invoke(_string), Is.EqualTo(_string.Length)); }
public void TestInvoke1() { var contains = FuncInvoker.Create(typeof(string).GetMethod("Contains", new[] { typeof(string) })); Assert.That((bool)contains.Invoke(_string, "uba"), Is.True); }
public void TestInvokeThunk() { var newGuid = FuncInvoker.Create(typeof(Guid).GetMethod(nameof(Guid.NewGuid))); Assert.That((Guid)newGuid.Invoke(), Is.Not.EqualTo(Guid.Empty)); }
public void setHost(FuncInvoker host) { mHost = host; }
public void setClient(FuncInvoker obj) { mClient = obj; }