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)); }
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; }
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; }
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)); }
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; }
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"})); }
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)); }
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 }); } }
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", })); }
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); }
public Using_Publishing_Methods() { _bus = new FakeBus(); _builder = new MethodScanner("Route").MakeBuilder(); _builder.SetPublisher(_bus); }
public HomeController() { _bus = ServiceLocator.Bus; _viewModelFacade = new ViewModelFacade(); }
public void SetUpBeforeScenario() { _fakeBus = new FakeBus(); _calculatorService = new CalculatorService(_fakeBus); }
public ProcedureApprovalRequestController() { _bus = ServiceLocator.Bus; }
protected override void DoSetUp() { fakeBus = new FakeBus(); }
public InventoryItemController() { _bus = Global._bus; _readmodel = new ReadModelFacade(); }
public HomeController(ILogger <HomeController> logger) { _logger = logger; _bus = ServiceLocator.Bus; _readmodel = new ReadModelFacade(); }
public static void RegisterBus(FakeBus bus) { _bus = bus; }
public void SetUp() { bus = new FakeBus(); }
public when_publishing_a_null_message_to_rabbitmq() { bus = new FakeBus(); message = null; publisher = new global::Workflow.RabbitMQ.Publisher(bus); }
public void BusSetUp() { _bus = new FakeBus(new FakeDriver(), 100, 50, 2, 1); _passengers = new FakePassenger(); _driver = new FakeDriver(); }
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; }
public When_sending_a_command_to_the_fakebus_with_multiple_command_handlers() { _bus = new FakeBus(); _bus.RegisterHandler <TestCommand>(_handler.Handle); }
public when_publishing_topic_message_to_rabbitmq() { bus = new FakeBus(); message = new TopicTestMessage(); publisher = new RabbitMQ.Publisher(bus); }
public HomeController() { _bus = ServiceLocator.Bus; _readmodel = new ReadModelFacade(); }
public void Given() { _bus = new FakeBus(); _builder = new MethodScanner("Route").MakeBuilder(); _builder.SetPublisher(_bus); }
public UsingPublishingMethods() { _bus = new FakeBus(); _builder = new MethodScanner("Route").MakeBuilder(); _builder.SetPublisher(_bus); }