public void PublicMethodsAreIncluded()
            {
                var attribute = new HandleByConventionAttribute {
                    PublicOnly = false
                };
                var handleMethods = attribute.GetHandleMethods(typeof(FakeHandler), new Mock <IServiceProvider>().Object);

                Assert.Equal(1, handleMethods.Count);
            }
            public void NonPublicMethodsAreExcluded()
            {
                var attribute = new HandleByConventionAttribute {
                    PublicOnly = true
                };
                var handleMethods = attribute.GetHandleMethods(typeof(FakeAggregate), new Mock <IServiceProvider>().Object);

                Assert.Equal(0, handleMethods.Count);
            }
            public void MethodsMatchingCustomNameAreIncluded()
            {
                var attribute = new HandleByConventionAttribute { MethodName = "Custom" };
                var handleMethods = attribute.GetHandleMethods(typeof(FakeHandler), new Mock<IServiceProvider>().Object);
                var handleMethod = handleMethods.Single().Value;
                var handler = new FakeHandler();

                handleMethod(handler, new FakeEvent());

                Assert.True(handler.Handled);
            }
            public void MethodsNamedHandleAreIgnored()
            {
                var attribute = new HandleByConventionAttribute { MethodName = "Custom" };
                var handleMethods = attribute.GetHandleMethods(typeof(FakeAggregate), new Mock<IServiceProvider>().Object);
                var handleMethod = handleMethods.Single().Value;
                var aggregate = new FakeAggregate();

                handleMethod(aggregate, new FakeCommand());

                Assert.True(aggregate.Handled);
            }
            public void MethodsMatchingCustomNameAreIncluded()
            {
                var attribute = new HandleByConventionAttribute {
                    MethodName = "Custom"
                };
                var handleMethods = attribute.GetHandleMethods(typeof(FakeHandler), new Mock <IServiceProvider>().Object);
                var handleMethod  = handleMethods.Single().Value;
                var handler       = new FakeHandler();

                handleMethod(handler, new FakeEvent());

                Assert.True(handler.Handled);
            }
            public void MethodsNamedHandleAreIgnored()
            {
                var attribute = new HandleByConventionAttribute {
                    MethodName = "Custom"
                };
                var handleMethods = attribute.GetHandleMethods(typeof(FakeAggregate), new Mock <IServiceProvider>().Object);
                var handleMethod  = handleMethods.Single().Value;
                var aggregate     = new FakeAggregate();

                handleMethod(aggregate, new FakeCommand());

                Assert.True(aggregate.Handled);
            }
            public void CannotOverloadHandleMethods()
            {
                var serviceProvider = new Mock <IServiceProvider>();
                var attribute       = new HandleByConventionAttribute {
                    PublicOnly = false
                };
                var expectedException = new MappingException(Exceptions.HandleMethodOverloaded.FormatWith(typeof(FakeHandler), "Void Handle(FakeEvent, FakeService, FakeService)"));

                serviceProvider.Setup(mock => mock.GetService(typeof(FakeService))).Returns(null);

                var actualException = Assert.Throws <MappingException>(() => attribute.GetHandleMethods(typeof(FakeHandler), serviceProvider.Object));

                Assert.Equal(expectedException.Message, actualException.Message);
            }
            public void PublicMethodsAreIncluded()
            {
                var attribute = new HandleByConventionAttribute { PublicOnly = false };
                var handleMethods = attribute.GetHandleMethods(typeof(FakeHandler), new Mock<IServiceProvider>().Object);

                Assert.Equal(1, handleMethods.Count);
            }
            public void CannotOverloadHandleMethods()
            {
                var serviceProvider = new Mock<IServiceProvider>();
                var attribute = new HandleByConventionAttribute { PublicOnly = false };
                var expectedException = new MappingException(Exceptions.HandleMethodOverloaded.FormatWith(typeof(FakeHandler), "Void Handle(FakeEvent, FakeService, FakeService)"));

                serviceProvider.Setup(mock => mock.GetService(typeof(FakeService))).Returns(null);

                var actualException = Assert.Throws<MappingException>(() => attribute.GetHandleMethods(typeof(FakeHandler), serviceProvider.Object));

                Assert.Equal(expectedException.Message, actualException.Message);
            }
            public void NonPublicMethodsAreExcluded()
            {
                var attribute = new HandleByConventionAttribute { PublicOnly = true };
                var handleMethods = attribute.GetHandleMethods(typeof(FakeAggregate), new Mock<IServiceProvider>().Object);

                Assert.Equal(0, handleMethods.Count);
            }