Esempio n. 1
0
        public void EventBusThrowsIfMessageNameIsNotCorrectlyFormatted()
        {
            var stub1 = new StubEventHandler();
            var stub2 = new StubEventHandler2();
            var eventBus = new DefaultOrchardEventBus(new IEventHandler[] { stub1, stub2 });

            Assert.Throws<ArgumentException>(() => eventBus.Notify("StubEventHandlerIncrement", new Dictionary<string, object>()));
        }
Esempio n. 2
0
        public void EventBusThrowsIfMessageNameIsNotCorrectlyFormatted()
        {
            var stub1    = new StubEventHandler();
            var stub2    = new StubEventHandler2();
            var eventBus = new DefaultOrchardEventBus(new IEventHandler[] { stub1, stub2 });

            Assert.Throws <ArgumentException>(() => eventBus.Notify("StubEventHandlerIncrement", new Dictionary <string, object>()));
        }
Esempio n. 3
0
        public void EventsAreCorrectlyDispatchedToEventHandlers()
        {
            var stub1    = new StubEventHandler();
            var stub2    = new StubEventHandler2();
            var eventBus = new DefaultOrchardEventBus(new IEventHandler[] { stub1, stub2 });

            Assert.Equal(0, stub1.Count);
            eventBus.Notify("ITestEventHandler.Increment", new Dictionary <string, object>());
            Assert.Equal(1, stub1.Count);
        }
Esempio n. 4
0
        public void EventHandlerWontBeCalledWhenNoParameterMatchExists2()
        {
            var stub1 = new StubEventHandler();
            var stub2 = new StubEventHandler2();
            var eventBus = new DefaultOrchardEventBus(new IEventHandler[] { stub1, stub2 });

            Assert.Equal(0, stub1.Result);
            Dictionary<string, object> arguments = new Dictionary<string, object>();
            eventBus.Notify("ITestEventHandler.Sum", arguments);
            Assert.Equal(0, stub1.Result);
        }
Esempio n. 5
0
        public void EnumerableResultsAreTreatedLikeSelectMany()
        {
            var stub1 = new StubEventHandler();
            var stub2 = new StubEventHandler2();
            var eventBus = new DefaultOrchardEventBus(new IEventHandler[] { stub1, stub2 });

            var results = eventBus.Notify("ITestEventHandler.Gather", new Dictionary<string, object> { { "a", 42 }, { "b", "alpha" } }).Cast<string>();
            Assert.Equal(3, results.Count());
            Assert.Contains("42", results);
            Assert.Contains("alpha", results);
            Assert.Contains("[42,alpha]", results);
        }
Esempio n. 6
0
        public void StringResultsAreTreatedLikeSelect()
        {
            var stub1    = new StubEventHandler();
            var stub2    = new StubEventHandler2();
            var eventBus = new DefaultOrchardEventBus(new IEventHandler[] { stub1, stub2 });

            var results = eventBus.Notify("ITestEventHandler.GetString", new Dictionary <string, object>()).Cast <string>();

            Assert.Equal(2, results.Count());
            Assert.Contains("Foo", results);
            Assert.Contains("Bar", results);
        }
Esempio n. 7
0
        public void NonStringNonEnumerableResultsAreTreatedLikeSelect()
        {
            var stub1    = new StubEventHandler();
            var stub2    = new StubEventHandler2();
            var eventBus = new DefaultOrchardEventBus(new IEventHandler[] { stub1, stub2 });

            var results = eventBus.Notify("ITestEventHandler.GetInt", new Dictionary <string, object>()).Cast <int>();

            Assert.Equal(2, results.Count());
            Assert.Contains(1, results);
            Assert.Contains(2, results);
        }
Esempio n. 8
0
        public void EventHandlerWontBeCalledWhenNoParameterMatchExists2()
        {
            var stub1    = new StubEventHandler();
            var stub2    = new StubEventHandler2();
            var eventBus = new DefaultOrchardEventBus(new IEventHandler[] { stub1, stub2 });

            Assert.Equal(0, stub1.Result);
            Dictionary <string, object> arguments = new Dictionary <string, object>();

            eventBus.Notify("ITestEventHandler.Sum", arguments);
            Assert.Equal(0, stub1.Result);
        }
Esempio n. 9
0
        public void EventParametersAreCorrectlyPassedToExactlyMatchingMethodWhenThereIsOne2()
        {
            var stub1    = new StubEventHandler();
            var stub2    = new StubEventHandler2();
            var eventBus = new DefaultOrchardEventBus(new IEventHandler[] { stub1, stub2 });

            Assert.Equal(0, stub1.Result);
            Dictionary <string, object> arguments = new Dictionary <string, object>();

            arguments["a"] = 1000;
            eventBus.Notify("ITestEventHandler.Sum", arguments);
            Assert.Equal(3000, stub1.Result);
        }
Esempio n. 10
0
        public void EventParametersArePassedInCorrectOrderToEventHandlers()
        {
            var stub1    = new StubEventHandler();
            var stub2    = new StubEventHandler2();
            var eventBus = new DefaultOrchardEventBus(new IEventHandler[] { stub1, stub2 });

            Assert.Equal(0, stub1.Result);
            Dictionary <string, object> arguments = new Dictionary <string, object>();

            arguments["a"] = 2600;
            arguments["b"] = 5200;
            eventBus.Notify("ITestEventHandler.Substract", arguments);
            Assert.Equal(-2600, stub1.Result);
        }
Esempio n. 11
0
        public void EnumerableResultsAreTreatedLikeSelectMany()
        {
            var stub1    = new StubEventHandler();
            var stub2    = new StubEventHandler2();
            var eventBus = new DefaultOrchardEventBus(new IEventHandler[] { stub1, stub2 });

            var results = eventBus.Notify("ITestEventHandler.Gather", new Dictionary <string, object> {
                { "a", 42 }, { "b", "alpha" }
            }).Cast <string>();

            Assert.Equal(3, results.Count());
            Assert.Contains("42", results);
            Assert.Contains("alpha", results);
            Assert.Contains("[42,alpha]", results);
        }
Esempio n. 12
0
        public void EventParametersAreCorrectlyPassedToMatchingMethod()
        {
            var stub1    = new StubEventHandler();
            var stub2    = new StubEventHandler2();
            var eventBus = new DefaultOrchardEventBus(new IEventHandler[] { stub1, stub2 });

            Assert.Null(stub1.Summary);
            Dictionary <string, object> arguments = new Dictionary <string, object>();

            arguments["a"] = "a";
            arguments["b"] = "b";
            arguments["c"] = "c";
            eventBus.Notify("ITestEventHandler.Concat", arguments);
            Assert.Equal("abc", stub1.Summary);
        }
Esempio n. 13
0
        public void EventParametersAreCorrectlyPassedToBestMatchingMethodAndExtraParametersAreIgnored()
        {
            var stub1    = new StubEventHandler();
            var stub2    = new StubEventHandler2();
            var eventBus = new DefaultOrchardEventBus(new IEventHandler[] { stub1, stub2 });

            Assert.Equal(0, stub1.Result);
            Dictionary <string, object> arguments = new Dictionary <string, object>();

            arguments["a"] = 1000;
            arguments["b"] = 100;
            arguments["c"] = 10;
            arguments["e"] = 1;
            eventBus.Notify("ITestEventHandler.Sum", arguments);
            Assert.Equal(1110, stub1.Result);
        }
Esempio n. 14
0
        public void EventParametersArePassedInCorrectOrderToEventHandlers()
        {
            var stub1 = new StubEventHandler();
            var stub2 = new StubEventHandler2();
            var eventBus = new DefaultOrchardEventBus(new IEventHandler[] { stub1, stub2 });

            Assert.Equal(0, stub1.Result);
            Dictionary<string, object> arguments = new Dictionary<string, object>();
            arguments["a"] = 2600;
            arguments["b"] = 5200;
            eventBus.Notify("ITestEventHandler.Substract", arguments);
            Assert.Equal(-2600, stub1.Result);
        }
Esempio n. 15
0
        public void EventParametersAreCorrectlyPassedToExactlyMatchingMethodWhenThereIsOne2()
        {
            var stub1 = new StubEventHandler();
            var stub2 = new StubEventHandler2();
            var eventBus = new DefaultOrchardEventBus(new IEventHandler[] { stub1, stub2 });

            Assert.Equal(0, stub1.Result);
            Dictionary<string, object> arguments = new Dictionary<string, object>();
            arguments["a"] = 1000;
            eventBus.Notify("ITestEventHandler.Sum", arguments);
            Assert.Equal(3000, stub1.Result);
        }
Esempio n. 16
0
        public void EventsAreCorrectlyDispatchedToEventHandlers()
        {
            var stub1 = new StubEventHandler();
            var stub2 = new StubEventHandler2();
            var eventBus = new DefaultOrchardEventBus(new IEventHandler[] { stub1, stub2 });

            Assert.Equal(0, stub1.Count);
            eventBus.Notify("ITestEventHandler.Increment", new Dictionary<string, object>());
            Assert.Equal(1, stub1.Count);
        }
Esempio n. 17
0
        public void NonStringNonEnumerableResultsAreTreatedLikeSelect()
        {
            var stub1 = new StubEventHandler();
            var stub2 = new StubEventHandler2();
            var eventBus = new DefaultOrchardEventBus(new IEventHandler[] { stub1, stub2 });

            var results = eventBus.Notify("ITestEventHandler.GetInt", new Dictionary<string, object>()).Cast<int>();
            Assert.Equal(2, results.Count());
            Assert.Contains(1, results);
            Assert.Contains(2, results);
        }
Esempio n. 18
0
        public void StringResultsAreTreatedLikeSelect()
        {
            var stub1 = new StubEventHandler();
            var stub2 = new StubEventHandler2();
            var eventBus = new DefaultOrchardEventBus(new IEventHandler[] { stub1, stub2 });

            var results = eventBus.Notify("ITestEventHandler.GetString", new Dictionary<string, object>()).Cast<string>();
            Assert.Equal(2, results.Count());
            Assert.Contains("Foo", results);
            Assert.Contains("Bar", results);
        }
Esempio n. 19
0
        public void EventParametersAreCorrectlyPassedToBestMatchingMethodAndExtraParametersAreIgnored()
        {
            var stub1 = new StubEventHandler();
            var stub2 = new StubEventHandler2();
            var eventBus = new DefaultOrchardEventBus(new IEventHandler[] { stub1, stub2 });

            Assert.Equal(0, stub1.Result);
            Dictionary<string, object> arguments = new Dictionary<string, object>();
            arguments["a"] = 1000;
            arguments["b"] = 100;
            arguments["c"] = 10;
            arguments["e"] = 1;
            eventBus.Notify("ITestEventHandler.Sum", arguments);
            Assert.Equal(1110, stub1.Result);
        }
Esempio n. 20
0
        public void EventParametersAreCorrectlyPassedToMatchingMethod()
        {
            var stub1 = new StubEventHandler();
            var stub2 = new StubEventHandler2();
            var eventBus = new DefaultOrchardEventBus(new IEventHandler[] { stub1, stub2 });

            Assert.Null(stub1.Summary);
            Dictionary<string, object> arguments = new Dictionary<string, object>();
            arguments["a"] = "a";
            arguments["b"] = "b";
            arguments["c"] = "c";
            eventBus.Notify("ITestEventHandler.Concat", arguments);
            Assert.Equal("abc", stub1.Summary);
        }