Esempio n. 1
0
        public void Run_in_test()
        {
            var streamer = EnvelopeStreamer.CreateDefault(typeof(CreateCustomer), typeof(CustomerCreated));

            var builder = new CqrsEngineBuilder(streamer);
            var account = new MemoryStorageConfig();

            var nuclear = account.CreateNuclear(new TestStrategy());
            var inbox = account.CreateInbox("input");
            var sender = account.CreateSimpleSender(streamer, "input");

            var handler = new RedirectToCommand();
            handler.WireToLambda<CreateCustomer>(customer => Consume(customer, nuclear, sender));
            handler.WireToLambda<CustomerCreated>(m => Console.WriteLine("Created!"));
            builder.Handle(inbox,  envelope => handler.InvokeMany(envelope.SelectContents()));

            using (var engine = builder.Build())
            {
                sender.SendOne(new CreateCustomer
                {
                    CustomerId = 1,
                    CustomerName = "Rinat Abdullin"
                });
                engine.RunForever();
            }
        }
Esempio n. 2
0
        CqrsEngineBuilder BootstrapHandlers(Setup setup)
        {
            var builder = new CqrsEngineBuilder(_streamer);
            var writer  = setup.Store.Container.GetWriter <unit, int>();
            var handler = new RedirectToCommand();

            handler.WireToLambda <AtomicMessage>(am => HandleAtomic(am, setup.Sender, writer));
            handler.WireToLambda <NuclearMessage>(am => HandleNuclear(am, setup.Sender, setup.Store));
            builder.Handle(setup.Inbox, envelope =>
            {
                foreach (var message in envelope.Items)
                {
                    handler.Invoke(message.Content);
                }
            });
            return(builder);
        }
        public void when_wire_to_lamda()
        {
            var command = new RedirectToCommand();
            var testClass = new TestClassWithMethod();
            command.WireToLambda<int>(i => { testClass.Summa += i; });
            command.Invoke(4);
            command.Invoke(4);

            Assert.AreEqual(8, testClass.Summa);
        }
Esempio n. 4
0
        public void when_wire_to_lamda()
        {
            var command   = new RedirectToCommand();
            var testClass = new TestClassWithMethod();

            command.WireToLambda <int>(i => { testClass.Summa += i; });
            command.Invoke(4);
            command.Invoke(4);

            Assert.AreEqual(8, testClass.Summa);
        }
Esempio n. 5
0
        CqrsEngineBuilder BootstrapHandlers(Setup setup)
        {
            var builder = new CqrsEngineBuilder(_streamer);
            var handler = new RedirectToCommand();

            handler.WireToLambda <FailingMessage>(am => SmartFailing(am, setup.Store));
            builder.Handle(setup.Inbox, envelope =>
            {
                foreach (var message in envelope.Items)
                {
                    handler.Invoke(message.Content);
                }
            });
            return(builder);
        }
Esempio n. 6
0
        public void Then_transactional_support_is_provided()
        {
            var streamer = EnvelopeStreamer.CreateDefault(typeof(Act));
            var builder  = new CqrsEngineBuilder(streamer);
            var setup    = ComposeComponents(streamer);

            var handler = new RedirectToCommand();

            handler.WireToLambda <Act>(act => Consume(act, setup.Storage));
            builder.Handle(setup.Inbox, envelope =>
            {
                using (var tx = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    handler.InvokeMany(envelope.Items.Select(i => i.Content));
                    tx.Complete();
                }
            });

            using (var source = new CancellationTokenSource())
                using (TestObserver.When <EnvelopeDispatched>(e => source.Cancel()))
                    using (var engine = builder.Build())
                    {
                        setup.Sender.SendBatch(new[] { new Act(), new Act(), new Act {
                                                           Fail = true
                                                       } });
                        setup.Sender.SendBatch(new[] { new Act(), new Act(), new Act() });


                        var task = engine.Start(source.Token);
                        //    Trace.WriteLine("Started");
                        if (!task.Wait(Debugger.IsAttached ? int.MaxValue : TestSpeed))
                        {
                            source.Cancel();
                            Assert.Fail("System should be stopped by now");
                        }

                        var storage = setup.Storage;
                        var count   = storage.GetSingletonOrNew <int>();
                        Assert.AreEqual(3, count, "Three acts are expected");
                    }
        }
        public void Then_transactional_support_is_provided()
        {
            var streamer = EnvelopeStreamer.CreateDefault(typeof(Act));
            var builder = new CqrsEngineBuilder(streamer);
            var setup = ComposeComponents(streamer);

            var handler = new RedirectToCommand();
            handler.WireToLambda<Act>(act => Consume(act, setup.Storage));
            builder.Handle(setup.Inbox, envelope =>
                {
                    using (var tx = new TransactionScope(TransactionScopeOption.RequiresNew))
                    {
                        handler.InvokeMany(envelope.Items.Select(i => i.Content));
                        tx.Complete();
                    }
                });

            using (var source = new CancellationTokenSource())
            using (TestObserver.When<EnvelopeDispatched>(e => source.Cancel()))
            using (var engine = builder.Build())
            {
                setup.Sender.SendBatch(new[] { new Act(), new Act(), new Act { Fail = true } });
                setup.Sender.SendBatch(new[] { new Act(), new Act(), new Act() });

                var task = engine.Start(source.Token);
                //    Trace.WriteLine("Started");
                if (!task.Wait(Debugger.IsAttached ? int.MaxValue : TestSpeed))
                {
                    source.Cancel();
                    Assert.Fail("System should be stopped by now");
                }

                var storage = setup.Storage;
                var count = storage.GetSingletonOrNew<int>();
                Assert.AreEqual(3, count, "Three acts are expected");
            }
        }
 CqrsEngineBuilder BootstrapHandlers(Setup setup)
 {
     var builder = new CqrsEngineBuilder(_streamer);
     var handler = new RedirectToCommand();
     handler.WireToLambda<FailingMessage>(am => SmartFailing(am, setup.Store));
     builder.Handle(setup.Inbox, envelope =>
         {
             foreach (var message in envelope.Items)
             {
                 handler.Invoke(message.Content);
             }
         });
     return builder;
 }
Esempio n. 9
0
 CqrsEngineBuilder BootstrapHandlers(Setup setup)
 {
     var builder = new CqrsEngineBuilder(_streamer);
     var writer = setup.Store.Container.GetWriter<unit, int>();
     var handler = new RedirectToCommand();
     handler.WireToLambda<AtomicMessage>(am => HandleAtomic(am, setup.Sender, writer));
     handler.WireToLambda<NuclearMessage>(am => HandleNuclear(am, setup.Sender, setup.Store));
     builder.Handle(setup.Inbox, envelope =>
     {
         foreach (var message in envelope.Items)
         {
             handler.Invoke(message.Content);
         }
     });
     return builder;
 }