Пример #1
0
            public void CustomMappingStrategyUsedWhenExplicitStrategyDefined()
            {
                typeLocator.Setup(mock => mock.GetTypes(It.IsAny <Func <Type, Boolean> >())).Returns(new[] { typeof(ExplicitStrategyAggregate) });

                var registry = new CommandHandlerRegistry(aggregateStore.Object, typeLocator.Object, serviceProvider.Object);
                var handler  = registry.GetHandlerFor(new FakeCommand());

                Assert.NotNull(handler);
            }
            public void CustomMappingStrategyUsedWhenExplicitStrategyDefined()
            {
                typeLocator.Setup(mock => mock.GetTypes(It.IsAny<Func<Type, Boolean>>())).Returns(new[] { typeof(ExplicitStrategyAggregate) });

                var registry = new CommandHandlerRegistry(aggregateStore.Object, typeLocator.Object, serviceProvider.Object);
                var handler = registry.GetHandlerFor(new FakeCommand());

                Assert.NotNull(handler);
            }
Пример #3
0
            public void ThrowMappingExceptionIfHandlerNotFound()
            {
                typeLocator.Setup(mock => mock.GetTypes(It.IsAny <Func <Type, Boolean> >())).Returns(new[] { typeof(AlternateImplicitStrategyAggregate) });

                var registry = new CommandHandlerRegistry(aggregateStore.Object, typeLocator.Object, serviceProvider.Object);
                var ex       = Assert.Throws <MappingException>(() => registry.GetHandlerFor(new FakeCommand()));

                Assert.Equal(Exceptions.CommandHandlerNotFound.FormatWith(typeof(FakeCommand)), ex.Message);
            }
Пример #4
0
            public void GetCommandHandlerBasedOnCommandType()
            {
                typeLocator.Setup(mock => mock.GetTypes(It.IsAny <Func <Type, Boolean> >())).Returns(new[] { typeof(ImplicitStrategyAggregate), typeof(AlternateImplicitStrategyAggregate) });

                var registry = new CommandHandlerRegistry(aggregateStore.Object, typeLocator.Object, serviceProvider.Object);
                var handler  = registry.GetHandlerFor(new FakeCommand());

                Assert.Equal(typeof(ImplicitStrategyAggregate), handler.AggregateType);
            }
Пример #5
0
            public void CanResolveRegisteredServices()
            {
                typeLocator.Setup(mock => mock.GetTypes(It.IsAny <Func <Type, Boolean> >())).Returns(new[] { typeof(ServicedAggregate) });
                serviceProvider.Setup(mock => mock.GetService(typeof(FakeService))).Returns(new FakeService());

                var registry = new CommandHandlerRegistry(aggregateStore.Object, typeLocator.Object, serviceProvider.Object);
                var handler  = registry.GetHandlerFor(new FakeCommand());

                Assert.NotNull(handler);
            }
Пример #6
0
            public void RegisteredServiceOnlyResolvedOncePerHandler()
            {
                var aggregateId = GuidStrategy.NewGuid();

                typeLocator.Setup(mock => mock.GetTypes(It.IsAny <Func <Type, Boolean> >())).Returns(new[] { typeof(ServicedAggregate) });
                aggregateStore.Setup(mock => mock.Get(typeof(ServicedAggregate), aggregateId)).Returns(new ServicedAggregate());
                serviceProvider.Setup(mock => mock.GetService(typeof(FakeService))).Returns(new FakeService());

                var registry = new CommandHandlerRegistry(aggregateStore.Object, typeLocator.Object, serviceProvider.Object);

                using (var context = new CommandContext(GuidStrategy.NewGuid(), HeaderCollection.Empty, new CommandEnvelope(aggregateId, new FakeCommand())))
                {
                    var handler1 = registry.GetHandlerFor(new FakeCommand());
                    handler1.Handle(context);
                    handler1.Handle(context);

                    var handler2 = registry.GetHandlerFor(new FakeCommand());
                    handler2.Handle(context);
                    handler2.Handle(context);
                }

                serviceProvider.Verify(mock => mock.GetService(typeof(FakeService)), Times.Once());
            }
            public void CanResolveRegisteredServices()
            {
                typeLocator.Setup(mock => mock.GetTypes(It.IsAny<Func<Type, Boolean>>())).Returns(new[] { typeof(ServicedAggregate) });
                serviceProvider.Setup(mock => mock.GetService(typeof(FakeService))).Returns(new FakeService());

                var registry = new CommandHandlerRegistry(aggregateStore.Object, typeLocator.Object, serviceProvider.Object);
                var handler = registry.GetHandlerFor(new FakeCommand());

                Assert.NotNull(handler);
            }
            public void ThrowMappingExceptionIfHandlerNotFound()
            {
                typeLocator.Setup(mock => mock.GetTypes(It.IsAny<Func<Type, Boolean>>())).Returns(new[] { typeof(AlternateImplicitStrategyAggregate) });

                var registry = new CommandHandlerRegistry(aggregateStore.Object, typeLocator.Object, serviceProvider.Object);
                var ex = Assert.Throws<MappingException>(() => registry.GetHandlerFor(new FakeCommand()));

                Assert.Equal(Exceptions.CommandHandlerNotFound.FormatWith(typeof(FakeCommand)), ex.Message);
            }
            public void GetCommandHandlerBasedOnCommandType()
            {
                typeLocator.Setup(mock => mock.GetTypes(It.IsAny<Func<Type, Boolean>>())).Returns(new[] { typeof(ImplicitStrategyAggregate), typeof(AlternateImplicitStrategyAggregate) });

                var registry = new CommandHandlerRegistry(aggregateStore.Object, typeLocator.Object, serviceProvider.Object);
                var handler = registry.GetHandlerFor(new FakeCommand());

                Assert.Equal(typeof(ImplicitStrategyAggregate), handler.AggregateType);
            }
            public void RegisteredServiceOnlyResolvedOncePerHandler()
            {
                var aggregateId = GuidStrategy.NewGuid();

                typeLocator.Setup(mock => mock.GetTypes(It.IsAny<Func<Type, Boolean>>())).Returns(new[] { typeof(ServicedAggregate) });
                aggregateStore.Setup(mock => mock.Get(typeof(ServicedAggregate), aggregateId)).Returns(new ServicedAggregate());
                serviceProvider.Setup(mock => mock.GetService(typeof(FakeService))).Returns(new FakeService());

                var registry = new CommandHandlerRegistry(aggregateStore.Object, typeLocator.Object, serviceProvider.Object);
                using (var context = new CommandContext(GuidStrategy.NewGuid(), HeaderCollection.Empty, new CommandEnvelope(aggregateId, new FakeCommand())))
                {
                    var handler1 = registry.GetHandlerFor(new FakeCommand());
                    handler1.Handle(context);
                    handler1.Handle(context);

                    var handler2 = registry.GetHandlerFor(new FakeCommand());
                    handler2.Handle(context);
                    handler2.Handle(context);
                }

                serviceProvider.Verify(mock => mock.GetService(typeof(FakeService)), Times.Once());
            }