Пример #1
1
        public async Task CheckThatEventsAreProperlyRecorded()
        {
            var bus = new FakeBus();

            var commandMessage = new { Text = "hej med dig min ven!!!!" };
            await bus.Send(commandMessage);

            var messageSentEvents = bus.Events.OfType<MessageSent>().ToList();

            Assert.That(messageSentEvents.Count, Is.EqualTo(1));
            Assert.That(messageSentEvents[0].CommandMessage, Is.EqualTo(commandMessage));
        }
Пример #2
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);

            var bus = new FakeBus();

            var storage = new EventStore(bus);
            var rep = new Repository<InventoryItem>(storage);
            var commands = new InventoryCommandHandlers(rep);
            bus.RegisterHandler<CheckInItemsToInventory>(commands.Handle);
            bus.RegisterHandler<CreateInventoryItem>(commands.Handle);
            bus.RegisterHandler<DeactivateInventoryItem>(commands.Handle);
            bus.RegisterHandler<RemoveItemsFromInventory>(commands.Handle);
            bus.RegisterHandler<RenameInventoryItem>(commands.Handle);
            var detail = new InvenotryItemDetailView();
            bus.RegisterHandler<InventoryItemCreated>(detail.Handle);
            bus.RegisterHandler<InventoryItemDeactivated>(detail.Handle);
            bus.RegisterHandler<InventoryItemRenamed>(detail.Handle);
            bus.RegisterHandler<ItemsCheckedInToInventory>(detail.Handle);
            bus.RegisterHandler<ItemsRemovedFromInventory>(detail.Handle);
            var list = new InventoryListView();
            bus.RegisterHandler<InventoryItemCreated>(list.Handle);
            bus.RegisterHandler<InventoryItemRenamed>(list.Handle);
            bus.RegisterHandler<InventoryItemDeactivated>(list.Handle);
            ServiceLocator.Bus = bus;
        }
Пример #3
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);

            var bus = new FakeBus();

            var storage = new EventStore(bus);
            var rep = new Repository<InventoryItemAggregateRoot>(storage);
            var commands = new InventoryItemCommandHandlers(rep);
            bus.RegisterHandler<InventoryItemCheckInCommand>(commands.Handle);
            bus.RegisterHandler<InventoryItemCreateCommand>(commands.Handle);
            bus.RegisterHandler<InventoryItemDeactivateCommand>(commands.Handle);
            bus.RegisterHandler<InventoryItemRemoveCommand>(commands.Handle);
            bus.RegisterHandler<InventoryItemRenameCommand>(commands.Handle);
            var detail = new InventoryItemDetailView();
            bus.RegisterHandler<InventoryItemCreatedEvent>(detail.Handle);
            bus.RegisterHandler<InventoryItemDeactivatedEvent>(detail.Handle);
            bus.RegisterHandler<InventoryItemRenamedEvent>(detail.Handle);
            bus.RegisterHandler<InventoryItemCheckedInEvent>(detail.Handle);
            bus.RegisterHandler<InventoryItemRemovedEvent>(detail.Handle);
            var list = new InventoryListView();
            bus.RegisterHandler<InventoryItemCreatedEvent>(list.Handle);
            bus.RegisterHandler<InventoryItemRenamedEvent>(list.Handle);
            bus.RegisterHandler<InventoryItemDeactivatedEvent>(list.Handle);
            ServiceLocator.Bus = bus;
        }
Пример #4
0
        public void CanClearEventsFromFakeBus()
        {
            var bus = new FakeBus();
            var commandMessage = new { Text = "hej med dig min ven!!!!" };
            bus.Send(commandMessage).Wait();

            bus.Clear();

            Assert.That(bus.Events.Count(), Is.EqualTo(0));
        }
Пример #5
0
        public void CanDoItAll()
        {
            var fakeBus = new FakeBus();

            fakeBus.Send(new MyMessage("send")).Wait();
            fakeBus.SendLocal(new MyMessage("send")).Wait();
            fakeBus.Publish(new MyMessage("send")).Wait();
            fakeBus.Defer(TimeSpan.FromSeconds(10), new MyMessage("send")).Wait();
            fakeBus.Subscribe<MyMessage>().Wait();
            fakeBus.Unsubscribe<MyMessage>().Wait();
        }
        private static FakeBus StickABusInIt(IPersistentStore store)
        {
            var bus = new FakeBus();
            var depositDetector = new DepositDetector(new Repository<LabelDepositJob>(new EventStore(bus)));
            bus.RegisterHandler<FileDeposit>(depositDetector.Handle);

            var depositHandler = new DepositHandler(store);
            bus.RegisterHandler<DepositDetected>(depositHandler.Handle);

            return bus;
        }
Пример #7
0
        public void CanInvokeCallback()
        {
            var fakeBus = new FakeBus();
            var callbacks = new List<string>();

            fakeBus.On<MessageSent>(e => callbacks.Add($"message sent: {e.CommandMessage}"));

            fakeBus.Send("whatever").Wait();

            Assert.That(callbacks, Is.EqualTo(new[] {"message sent: whatever"}));
        }
Пример #8
0
        public void CodeSampleForComment()
        {
            var fakeBus = new FakeBus();

            fakeBus.Send(new MyMessage("woohoo!")).Wait();

            var sentMessagesWithMyGreeting = fakeBus.Events
                .OfType<MessageSent<MyMessage>>()
                .Count(m => m.CommandMessage.Text == "woohoo!");

            Assert.That(sentMessagesWithMyGreeting, Is.EqualTo(1));
        }
Пример #9
0
        public static void RegisterHandlers(FakeBus bus, object obj)
        {
            var interfaces = obj.GetType().GetInterfaces().SelectMany(i => i.GetGenericArguments());

            foreach (var i in interfaces)
            {
                var handleMethod = obj.GetType().GetMethod("Handle", new Type[] { i });
                var del = Delegate.CreateDelegate(Expression.GetActionType(i), obj, handleMethod);

                MethodInfo register = bus.GetType().GetMethod("RegisterHandler").MakeGenericMethod(i);
                register.Invoke(bus, new object[] { del });
            }
        }
Пример #10
0
        void WireupInfrastructure()
        {
            var bus = new FakeBus();
            var storage = new EventStore(bus);
            var repository = new Repository<Article>(storage);
            var discovery = new MessageHandlerDiscovery(bus);

            discovery.AddMessageReciever(new ArticleCommandHandler(repository));
            discovery.AddMessageReciever(new ArticleListEventHandler());
            discovery.AddMessageReciever(new ArticleDetailsEventHandler());
            discovery.AddMessageReciever(new ArticlePriceChangedEventHandler());

            ServiceLocator.RegisterBus(bus);
        }
        public void InjectedWhateverWithWhateverInsideIsProperlyDisposed()
        {
            var injectionist = new Injectionist();
            var eventTracker = new EventTracker();

            injectionist.Register(c =>
            {
                var fakeBus = new FakeBus(c.Get<Disposable1>(), c.Get<EventTracker>());

                fakeBus.FakeBusDisposed += () =>
                {
                    foreach (var disposable in c.GetTrackedInstancesOf<IDisposable>().Reverse())
                    {
                        disposable.Dispose();
                    }
                };

                foreach (var disposable in c.GetTrackedInstancesOf<IInitializable>())
                {
                    disposable.Initialize();
                }

                return fakeBus;
            });
            injectionist.Register(c => new Disposable1(c.Get<Disposable2>(), c.Get<EventTracker>()));
            injectionist.Register(c => new Disposable2(c.Get<EventTracker>()));
            injectionist.Register(c => eventTracker);

            using (var bus = injectionist.Get<FakeBus>())
            {
                Console.WriteLine("Using the bus....");

                Console.WriteLine("Disposing it");
            }

            Console.WriteLine(@"Here's what happened:
{0}", string.Join(Environment.NewLine, eventTracker.Events.Select(e => "- " + e)));

            Assert.That(eventTracker.Events, Is.EqualTo(new[]
            {
                "EventTracker initialized",
                "Disposable2 initialized",
                "Disposable1 initialized",
                "Disposable1 disposed",
                "Disposable2 disposed",
                "EventTracker disposed",
                "FakeBus disposed",
            }));
        }
Пример #12
0
        protected void Application_Start()
        {
            Bootstrapper.Start();
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            #region Bus

            var bus = new FakeBus();

            var storage = new EventStore(bus);
            var rep = new Repository<MedicalApprovalProcedure>(storage);
            var commands = new CommandHandlers(rep);
            bus.RegisterHandler<CreateMedicalProcedureApprovalRequest>(commands.Handle);
            var eventHandler = new ManteqEventHandler();
            bus.RegisterHandler<ApprovalCreated>(eventHandler.Handle);
            ServiceLocator.Bus = bus;

            #endregion Bus
        }
        public void BootStrapTheApplication()
        {
            EventStoreDatabaseBootStrapper.BootStrap();
            ReportingDatabaseBootStrapper.BootStrap();

            var bus = new FakeBus();
            ServiceLocator.Bus = bus;
            //var storage = new InMemoryEventStore(bus);
            //var storage = new NHibernateSqliteEventStore(bus, NHibernateSessionHelper.CreateSessionFactory(), new BinaryFormatter());
            var storage = new SqliteEventStore(bus, new BinaryFormatter(), "Data Source=eventStore.db3");

            var rep = new DomainRepository<InventoryItem>(storage);
            var commands = new InventoryCommandHandlers(rep);
            bus.RegisterHandler<CheckInItemsToInventory>(commands.Handle);
            bus.RegisterHandler<CreateInventoryItem>(commands.Handle);
            bus.RegisterHandler<DeactivateInventoryItem>(commands.Handle);
            bus.RegisterHandler<RemoveItemsFromInventory>(commands.Handle);
            bus.RegisterHandler<RenameInventoryItem>(commands.Handle);

            var sqlInsertBuilder = new SqlInsertBuilder();
            var sqlSelectBuilder = new SqlSelectBuilder();
            var sqlUpdateBuilder = new SqlUpdateBuilder();
            var sqlDeleteBuilder = new SqlDeleteBuilder();
            var reportingRepository = new SQLiteReportingRepository("Data Source=reportingDataBase.db3", sqlSelectBuilder,
                                                                    sqlInsertBuilder, sqlUpdateBuilder, sqlDeleteBuilder);
            var detail = new InventoryItemDetailViewHandler(reportingRepository);
            ServiceLocator.ReportingRepository = reportingRepository;
            bus.RegisterHandler<InventoryItemCreated>(detail.Handle);
            bus.RegisterHandler<InventoryItemDeactivated>(detail.Handle);
            bus.RegisterHandler<InventoryItemRenamed>(detail.Handle);
            bus.RegisterHandler<ItemsCheckedInToInventory>(detail.Handle);
            bus.RegisterHandler<ItemsRemovedFromInventory>(detail.Handle);
            var list = new InventoryItemListViewHandler(reportingRepository);
            bus.RegisterHandler<InventoryItemCreated>(list.Handle);
            bus.RegisterHandler<InventoryItemRenamed>(list.Handle);
            bus.RegisterHandler<InventoryItemDeactivated>(list.Handle);
        }
Пример #14
0
 public Using_Publishing_Methods()
 {
     _bus = new FakeBus();
     _builder = new MethodScanner("Route").MakeBuilder();
     _builder.SetPublisher(_bus);
 }
Пример #15
0
 public HomeController()
 {
     _bus = ServiceLocator.Bus;
     _viewModelFacade = new ViewModelFacade();
 }
 public void SetUpBeforeScenario()
 {
     _fakeBus           = new FakeBus();
     _calculatorService = new CalculatorService(_fakeBus);
 }
 public ProcedureApprovalRequestController()
 {
     _bus = ServiceLocator.Bus;
 }
Пример #18
0
 protected override void DoSetUp()
 {
     fakeBus = new FakeBus();
 }
Пример #19
0
 public InventoryItemController()
 {
     _bus = Global._bus;
     _readmodel = new ReadModelFacade();
 }
Пример #20
0
 protected override void DoSetUp()
 {
     fakeBus = new FakeBus();
 }
Пример #21
0
 public HomeController(ILogger <HomeController> logger)
 {
     _logger    = logger;
     _bus       = ServiceLocator.Bus;
     _readmodel = new ReadModelFacade();
 }
Пример #22
0
 public static void RegisterBus(FakeBus bus)
 {
     _bus = bus;
 }
Пример #23
0
 public void SetUp()
 {
     bus = new FakeBus();
 }
 public ProcedureApprovalRequestController()
 {
     _bus = ServiceLocator.Bus;
 }
 public when_publishing_a_null_message_to_rabbitmq()
 {
     bus = new FakeBus();
     message = null;
     publisher = new global::Workflow.RabbitMQ.Publisher(bus);
 }
Пример #26
0
 public void BusSetUp()
 {
     _bus        = new FakeBus(new FakeDriver(), 100, 50, 2, 1);
     _passengers = new FakePassenger();
     _driver     = new FakeDriver();
 }
Пример #27
0
 public When_publishing_an_event_to_the_fakebus_with_a_single_event_handler_registered()
 {
     _bus = new FakeBus();
     _bus.RegisterHandler <TestEvent>(_handler.Handle);
 }
 public HomeController()
 {
     _bus = ServiceLocator.Bus;
 }
Пример #29
0
 public When_sending_a_command_to_the_fakebus_with_multiple_command_handlers()
 {
     _bus = new FakeBus();
     _bus.RegisterHandler <TestCommand>(_handler.Handle);
 }
Пример #30
0
 public HomeController()
 {
     _bus             = ServiceLocator.Bus;
     _viewModelFacade = new ViewModelFacade();
 }
 public when_publishing_topic_message_to_rabbitmq()
 {
     bus = new FakeBus();
     message = new TopicTestMessage();
     publisher = new RabbitMQ.Publisher(bus);
 }
Пример #32
0
 public HomeController()
 {
     _bus       = ServiceLocator.Bus;
     _readmodel = new ReadModelFacade();
 }
Пример #33
0
 public void Given()
 {
     _bus = new FakeBus();
     _builder = new MethodScanner("Route").MakeBuilder();
     _builder.SetPublisher(_bus);
 }
Пример #34
0
 public HomeController()
 {
     _bus = ServiceLocator.Bus;
     _readmodel = new ReadModelFacade();
 }
Пример #35
0
 public UsingPublishingMethods()
 {
     _bus     = new FakeBus();
     _builder = new MethodScanner("Route").MakeBuilder();
     _builder.SetPublisher(_bus);
 }