コード例 #1
0
        public void MultipleHandlers_OneEvent()
        {
            var bus        = new DefaultEventBus();
            var logStream1 = new List <LogEvent>();
            var logStream2 = new List <LogEvent>();
            var handler1   = new LogEventHandler1(logStream1);
            var handler2   = new LogEventHandler2(logStream2);

            bus.Subscribe <LogEvent, LogEventHandler1>(handler1);
            bus.Subscribe <LogEvent, LogEventHandler2>(handler2);
            var ev  = new LogEvent("log");
            var res = bus.Publish(ev);

            Assert.IsTrue(logStream1.Count == 1,
                          "There must be one log item in stream1");

            Assert.IsTrue(logStream1[0].Text.Equals(ev.Text, StringComparison.Ordinal),
                          "Log item's text aren't equal in stream1");

            Assert.IsTrue(logStream2.Count == 1,
                          "There must be one log item in stream2");

            Assert.IsTrue(logStream2[0].Text.Equals(ev.Text, StringComparison.Ordinal),
                          "Log item's text aren't equal in stream2");

            Assert.IsNotNull(res,
                             "Event handler was not found");

            Assert.IsNotNull(res.CatchAllResults,
                             "Catch-all handlers must not be null");

            Assert.IsTrue(res.CatchAllResults.Length == 0,
                          "There must be no catch-all results");

            Assert.IsTrue(res.StartedAt <= res.FinishedAt,
                          "StartedAt > FinishedAt!");

            Assert.IsTrue(res.Duration.Ticks >= 0,
                          "Duration is negative");

            Assert.IsNotNull(res.HandlerResults,
                             "Handler result is null");

            Assert.IsTrue(res.HandlerResults.Length == 2,
                          "Handler result is not added");

            Assert.IsTrue(res.HandlerResults.Any(a => a.Handler.Equals(handler1)),
                          "handler1 does not exist in result");

            Assert.IsTrue(res.HandlerResults.Any(a => a.Handler.Equals(handler2)),
                          "handler2 does not exist in result");

            bus.Dispose();
        }
コード例 #2
0
        public void OneHandler_OneEvent()
        {
            var bus       = new DefaultEventBus();
            var logStream = new List <LogEvent>();
            var handler   = new LogEventHandler1(logStream);

            bus.Subscribe <LogEvent, LogEventHandler1>(handler);
            var ev  = new LogEvent("log-1");
            var res = bus.Publish(ev);

            Assert.IsTrue(logStream.Count == 1,
                          "There must be one log item in stream");

            Assert.IsTrue(logStream[0].Text.Equals(ev.Text, StringComparison.Ordinal),
                          "Log item's text aren't equal");

            Assert.IsNotNull(res,
                             "Event handler was not found");

            Assert.IsNotNull(res.CatchAllResults,
                             "Catch-all handlers must not be null");

            Assert.IsTrue(res.CatchAllResults.Length == 0,
                          "There must be no catch-all results");

            Assert.IsTrue(res.StartedAt <= res.FinishedAt,
                          "StartedAt > FinishedAt!");

            Assert.IsTrue(res.Duration.Ticks >= 0,
                          "Duration is negative");

            Assert.IsNotNull(res.HandlerResults,
                             "Handler result is null");

            Assert.IsTrue(res.HandlerResults.Length == 1,
                          "Handler result is not added");

            Assert.IsTrue(res.HandlerResults[0].Handler.Equals(handler),
                          "Handler in result is not equal to the actual handler!");

            bus.Dispose();
        }