예제 #1
0
        public void ThrowsCommandBusExceptionWhenRegisterHandlerForSameCommandType()
        {
            var handler1Mock = new Mock <ICommandHandler <CommandFake1> >();
            var handler2Mock = new Mock <ICommandHandler <CommandFake1> >();

            var commandBus = new CommandBus();

            commandBus.RegisterHandler(handler1Mock.Object);

            Check.ThatCode(() => commandBus.RegisterHandler(handler2Mock.Object))
            .Throws <CommandBusException>();
        }
예제 #2
0
        private Configuration()
        {
            _bus = new CommandBus();
            var eventStore = new SqlStore(_bus);
            var repository = new DomainRepository(eventStore);

            //Registering my Commands to corresponding CommandHandlers
            var commandService = new UserCommandHandler(repository);

            _bus.RegisterHandler <CreateUserCommand>(commandService.Handle);
            _bus.RegisterHandler <UpdateUserCommand>(commandService.Handle);
        }
예제 #3
0
        public void SendCommandToCorrectCommandHandler()
        {
            var handler1Mock = new Mock <ICommandHandler <CommandFake1> >();
            var handler2Mock = new Mock <ICommandHandler <CommandFake2> >();

            var commandBus = new CommandBus();

            commandBus.RegisterHandler(handler1Mock.Object);
            commandBus.RegisterHandler(handler2Mock.Object);

            commandBus.Send(new CommandFake1());

            handler1Mock.Verify(x => x.Handle(It.IsAny <CommandFake1>()), Times.Once);
            handler2Mock.Verify(x => x.Handle(It.IsAny <CommandFake2>()), Times.Never);
        }
예제 #4
0
        public void ThrowsCommandBusExceptionWhenRegisterNullHandler()
        {
            var commandBus = new CommandBus();

            Check.ThatCode(() => commandBus.RegisterHandler((ICommandHandler <CommandFake1>)null))
            .Throws <CommandBusException>();
        }
예제 #5
0
        public void ThrowCommandHandlersExceptionWhenHandlerThrowsException()
        {
            var handler1Mock = new Mock <ICommandHandler <CommandFake1> >();

            handler1Mock.Setup(x => x.Handle(It.IsAny <CommandFake1>())).Throws(new CommandHandlerException("Error"));

            var commandBus = new CommandBus();

            commandBus.RegisterHandler(handler1Mock.Object);

            Check.ThatCode(() => commandBus.Send(new CommandFake1())).Throws <CommandHandlerException>();
        }
예제 #6
0
        public void Init()
        {
            this.ReadModelRepository = new GenericReadModelRepositoryFake();
            var viewModelGenerator = new ViewModelGenerator(this.ReadModelRepository);

            var eventBus = new EventBus();

            eventBus.Register <ItemCreated>(viewModelGenerator);
            eventBus.Register <ItemRenamed>(viewModelGenerator);
            eventBus.Register <UnitsAdded>(viewModelGenerator);
            eventBus.Register <UnitsRemoved>(viewModelGenerator);
            eventBus.Register <ItemDisabled>(viewModelGenerator);
            eventBus.Register <ItemEnabled>(viewModelGenerator);
            this.EventStore = new EventStoreFake(eventBus);

            var commandBus = new CommandBus();

            commandBus.RegisterHandler(new CreateItemHandler(this.EventStore));
            commandBus.RegisterHandler(new RenameItemHandler(this.EventStore));
            commandBus.RegisterHandler(new AddUnitsHandler(this.EventStore));
            commandBus.RegisterHandler(new RemoveUnitsHandler(this.EventStore));
            commandBus.RegisterHandler(new DisableItemHandler(this.EventStore));
            commandBus.RegisterHandler(new EnableItemHandler(this.EventStore));
            this.CommandBus = commandBus;
        }
예제 #7
0
        public static void Init(
            IEventStoreRegistration eventStore,
            IReadModelRepository readModelRepository)
        {
            if (ReadModelRepository != null)
            {
                throw new InvalidOperationException("Bootstrapper is already initialized.");
            }

            ReadModelRepository = readModelRepository;

            var eventBus = new EventBus();

            eventStore.SetEventBusToPublish(eventBus);
            var viewModelGenerator = new ViewModelGenerator(readModelRepository);

            eventBus.Register <ItemCreated>(viewModelGenerator);
            eventBus.Register <ItemRenamed>(viewModelGenerator);
            eventBus.Register <UnitsAdded>(viewModelGenerator);
            eventBus.Register <UnitsRemoved>(viewModelGenerator);
            eventBus.Register <ItemDisabled>(viewModelGenerator);
            eventBus.Register <ItemEnabled>(viewModelGenerator);

            var commandBus = new CommandBus();

            commandBus.RegisterHandler(new CreateItemHandler(eventStore));
            commandBus.RegisterHandler(new RenameItemHandler(eventStore));
            commandBus.RegisterHandler(new AddUnitsHandler(eventStore));
            commandBus.RegisterHandler(new RemoveUnitsHandler(eventStore));
            commandBus.RegisterHandler(new DisableItemHandler(eventStore));
            commandBus.RegisterHandler(new EnableItemHandler(eventStore));
            CommandBus = commandBus;
        }
예제 #8
0
        public void can_add_command_handler_and_use_it()
        {
            var commandBus = new CommandBus();
            var command    = new TestCommand();
            var handler    = new TestCommandHandler();

            commandBus.RegisterHandler(handler);

            commandBus.PublishCommand(command);

            Thread.Sleep(500); // wait for command thread to execute

            Assert.IsTrue(command.WasHandled);
        }
예제 #9
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);

            var bus = new CommandBus();
            var commands = new CommandHandlers();
            bus.RegisterHandler<PostTransactionCommand>(commands.Handle);
            ServiceLocator.CommandBus = bus;

            var events = new EventHandlers();
            DomainEvents.Register<AccountLockedEvent>(events.Handle);
            DomainEvents.Register<AccountOverdrawnEvent>(events.Handle);
            DomainEvents.Register<TransationPostedEvent>(events.Handle);
        }
예제 #10
0
        public void can_add_action_handler_and_use_it()
        {
            var commandBus = new CommandBus();
            var command    = new TestCommand();

            commandBus.RegisterHandler <TestCommand>(x =>
            {
                x.WasHandled = true;
            });

            commandBus.PublishCommand(command);

            Thread.Sleep(500); // wait for command thread to execute

            Assert.IsTrue(command.WasHandled);
        }
예제 #11
0
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Show graphics profiling information while debugging.
            if (System.Diagnostics.Debugger.IsAttached)
            {
                // Display the current frame rate counters
                //Application.Current.Host.Settings.EnableFrameRateCounter = true;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,
                // which shows areas of a page that are being GPU accelerated with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;
            }

            // Standard Silverlight initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            // setup container
            var state      = new ApplicationState();
            var commandBus = new CommandBus();

            var mainViewModel    = new MainViewModel();
            var addPageViewModel = new AddPageViewModel();

            _initializationAction = (IContainer x) =>
            {
                x.Register <ISettingsManager, SettingsManager>();
                x.Register <IStorageManager, StorageManager>();
                x.Register <IUIThreadInvoker, UIThreadInvoker>();
                x.Register <ICommandBus>(commandBus);
                x.Register <IApplicationState>(state);

                x.Register <INavigationServiceWrapper, NavigationServiceWrapper>();
                x.Register <IDialogService, DialogService>();
                x.Register <ITrialService, TrialService>();

                x.Register <ICommandHandler <ApplicationLoadedCommand>, ApplicationLoadedCommandHandler>();
                x.Register <ICommandHandler <MainPageLoadedCommand>, MainPageLoadedCommandHandler>();
                x.Register <ICommandHandler <AddNewShortCodeCommand>, AddNewShortCodeCommandHandler>();
                x.Register <ICommandHandler <EditShortCodeCommand>, EditShortCodeCommandHandler>();
                x.Register <ICommandHandler <SaveShortCodeCommand>, SaveShortCodeCommandHandler>();
                x.Register <ICommandHandler <DeleteShortCodeCommand>, DeleteShortCodeCommandHandler>();
                x.Register <ICommandHandler <SendSmsCommand>, SendSmsCommandHandler>();
                x.Register <ICommandHandler <DataLoadedMessage>, DataLoadedCommandHandler>();

                x.Register <IValidator <ShortCode>, ShortCodeValidator>();

                x.Register <IMainViewModel>(mainViewModel);
                x.Register <IAddPageViewModel>(addPageViewModel);
            };
            MicroMap.Initialize(_initializationAction);

            commandBus.RegisterHandler(MicroMap.GetInstance <ICommandHandler <ApplicationLoadedCommand> >());
            commandBus.RegisterHandler(MicroMap.GetInstance <ICommandHandler <MainPageLoadedCommand> >());
            commandBus.RegisterHandler(MicroMap.GetInstance <ICommandHandler <AddNewShortCodeCommand> >());
            commandBus.RegisterHandler(MicroMap.GetInstance <ICommandHandler <EditShortCodeCommand> >());
            commandBus.RegisterHandler(MicroMap.GetInstance <ICommandHandler <SaveShortCodeCommand> >());
            commandBus.RegisterHandler(MicroMap.GetInstance <ICommandHandler <DeleteShortCodeCommand> >());
            commandBus.RegisterHandler(MicroMap.GetInstance <ICommandHandler <SendSmsCommand> >());
            commandBus.RegisterHandler(MicroMap.GetInstance <ICommandHandler <DataLoadedMessage> >());
        }
예제 #12
0
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Show graphics profiling information while debugging.
            if (System.Diagnostics.Debugger.IsAttached)
            {
                // Display the current frame rate counters
                //Application.Current.Host.Settings.EnableFrameRateCounter = true;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,
                // which shows areas of a page that are being GPU accelerated with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;
            }

            // Standard Silverlight initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            // setup container
            var state = new ApplicationState();
            var commandBus = new CommandBus();

            var mainViewModel = new MainViewModel();
            var addPageViewModel = new AddPageViewModel();

            _initializationAction = (IContainer x) =>
            {
                x.Register<ISettingsManager, SettingsManager>();
                x.Register<IStorageManager, StorageManager>();
                x.Register<IUIThreadInvoker, UIThreadInvoker>();
                x.Register<ICommandBus>(commandBus);
                x.Register<IApplicationState>(state);

                x.Register<INavigationServiceWrapper, NavigationServiceWrapper>();
                x.Register<IDialogService, DialogService>();
                x.Register<ITrialService, TrialService>();

                x.Register<ICommandHandler<ApplicationLoadedCommand>, ApplicationLoadedCommandHandler>();
                x.Register<ICommandHandler<MainPageLoadedCommand>, MainPageLoadedCommandHandler>();
                x.Register<ICommandHandler<AddNewShortCodeCommand>, AddNewShortCodeCommandHandler>();
                x.Register<ICommandHandler<EditShortCodeCommand>, EditShortCodeCommandHandler>();
                x.Register<ICommandHandler<SaveShortCodeCommand>, SaveShortCodeCommandHandler>();
                x.Register<ICommandHandler<DeleteShortCodeCommand>, DeleteShortCodeCommandHandler>();
                x.Register<ICommandHandler<SendSmsCommand>, SendSmsCommandHandler>();
                x.Register<ICommandHandler<DataLoadedMessage>, DataLoadedCommandHandler>();

                x.Register<IValidator<ShortCode>, ShortCodeValidator>();

                x.Register<IMainViewModel>(mainViewModel);
                x.Register<IAddPageViewModel>(addPageViewModel);
            };
            MicroMap.Initialize(_initializationAction);

            commandBus.RegisterHandler(MicroMap.GetInstance<ICommandHandler<ApplicationLoadedCommand>>());
            commandBus.RegisterHandler(MicroMap.GetInstance<ICommandHandler<MainPageLoadedCommand>>());
            commandBus.RegisterHandler(MicroMap.GetInstance<ICommandHandler<AddNewShortCodeCommand>>());
            commandBus.RegisterHandler(MicroMap.GetInstance<ICommandHandler<EditShortCodeCommand>>());
            commandBus.RegisterHandler(MicroMap.GetInstance<ICommandHandler<SaveShortCodeCommand>>());
            commandBus.RegisterHandler(MicroMap.GetInstance<ICommandHandler<DeleteShortCodeCommand>>());
            commandBus.RegisterHandler(MicroMap.GetInstance<ICommandHandler<SendSmsCommand>>());
            commandBus.RegisterHandler(MicroMap.GetInstance<ICommandHandler<DataLoadedMessage>>());
        }