Example #1
0
        public void CqrsBuilder_ThrowsException_OnInvalidHandlerRegistration()
        {
            //Arrange
            var builder = new CqrsBuilder();

            //Act Assert
            Assert.Throws <InvalidCastException>(() => builder.Register(typeof(InvalidEventHandler)));
            Assert.Throws <InvalidCastException>(() => builder.Register(typeof(InvalidCommandHandler)));
            Assert.Throws <InvalidCastException>(() => builder.RegisterDefaultHandler(typeof(InvalidCommandHandler)));
        }
Example #2
0
        public void CqrsBuilder_ThrowsException_OnNullRegistration()
        {
            //Arrange
            var builder = new CqrsBuilder();

            //Act Assert
            Assert.Throws <ArgumentNullException>(() => builder.Register(null));
            Assert.Throws <ArgumentNullException>(() => builder.RegisterDefaultHandler(null));
            Assert.Throws <ArgumentNullException>(() => builder.AutoRegisterHandlers(null));
            Assert.Throws <ArgumentNullException>(() => builder.RegisterContainer(null));
            Assert.Throws <ArgumentNullException>(() => builder.RegisterResolver(null));
        }
Example #3
0
        public void CqrsBuilder_ThrowsInvalidCast_OnAddingInvalidHanlder(params Type[] handlerTypes)
        {
            //Arrange
            int fireTimes    = handlerTypes.Length + 1; // Add default handler for unknown methods
            var builder      = new CqrsBuilder();
            var registration = new Mock <IContainerRegistration>();

            registration
            .Setup(x => x.RegisterAction)
            .Returns(x => { });

            //Act
            builder.RegisterContainer(registration.Object);

            //Assert
            Assert.Throws <InvalidCastException>(() => builder.Register(handlerTypes));
        }
Example #4
0
        public void CqrsBuilder_FiresContainerRegistry_OnContainerRegistration(params Type[] handlerTypes)
        {
            //Arrange
            int fireTimes    = handlerTypes.Length + 1; // Add default handler for unknown methods
            var builder      = new CqrsBuilder();
            var registration = new Mock <IContainerRegistration>();

            registration
            .Setup(x => x.RegisterAction)
            .Returns(x => { });

            //Act
            builder.Register(handlerTypes);
            builder.RegisterContainer(registration.Object);

            //Assert
            registration.Verify(x => x.RegisterAction, Times.Exactly(fireTimes));
        }
Example #5
0
        public static ICqrsBuilder AddRapidCqrs(this ContainerBuilder containerBuilder)
        {
            _builder = new CqrsBuilder();
            _builder
            .RegisterContainer(new ContainerRegistration(x =>
                                                         containerBuilder
                                                         .RegisterType(x)
                                                         .AsSelf()
                                                         .InstancePerDependency()));

            containerBuilder
            .Register(x =>
            {
                var scope = x.Resolve <ILifetimeScope>();
                _builder.RegisterResolver(new BasicHandlerResolver(scope.Resolve));
                return(_builder.Build());
            })
            .As <IMediator>()
            .SingleInstance();

            return(_builder);
        }