Exemplo n.º 1
0
        public void FullIntegrationTest()
        {
            commandRelay.On <LoginEvent>().Do <LoginCommand>((cmd, ev) =>
            {
                cmd.eventBus   = eventBus;
                cmd.server     = server;
                cmd.loginEvent = ev;
            });

            commandRelay.On <LoginFailedEvent>().Do <LoginCommand>((cmd, ev) =>
            {
                cmd.eventBus   = eventBus;
                cmd.server     = server;
                cmd.loginEvent = ev;
            });

            commandRelay.On <LoginSuccessEvent>().Do <RecordLoginCommand>((cmd, ev) =>
            {
                cmd.userService = userService;
                cmd.loginEvent  = ev;
            }).Do <UpdateDisplayNameCommand>((cmd, ev) =>
            {
                cmd.userService = userService;
                cmd.userWidget  = userWidget;
            }).Do <FailingCommand>()
            .Do <ScrambleDisplayNameCommand>((cmd, ev) =>
            {
                cmd.userWidget = userWidget;
            });

            TestLogin("Foo Bar");
            TestLogin("Bing Baz");

            Assert.AreEqual(1, pool.UniqueInstances[typeof(LoginEvent)]);
            Assert.AreEqual(1, pool.UniqueInstances[typeof(LoginFailedEvent)]);
            Assert.AreEqual(2, pool.UniqueInstances[typeof(LoginSuccessEvent)]);
            Assert.AreEqual(2, pool.UniqueInstances[typeof(LoginCommand)]);             //A second LoginCommand is needed to respond to the first one failing before the first LoginCommand's Done method is called.
            Assert.AreEqual(1, pool.UniqueInstances[typeof(RecordLoginCommand)]);
            Assert.AreEqual(1, pool.UniqueInstances[typeof(UpdateDisplayNameCommand)]);
            Assert.AreEqual(1, pool.UniqueInstances[typeof(FailingCommand)]);
            Assert.IsFalse(pool.UniqueInstances.ContainsKey(typeof(ScrambleDisplayNameCommand)));
        }
Exemplo n.º 2
0
 public void OnDoCausesCommandToBeExecuted()
 {
     testObj.On <DummyEvent>().Do <DummyCommand>();
     eventBus.Dispatch <DummyEvent>();
     Assert.AreEqual(1, DummyCommand.ExecuteCount);
 }