コード例 #1
0
        public void WhenSelectingHandlerWithNullParamterThenThrowsArgumentNullException()
        {
            // Assign
            DefaultCommandHandlerSelector resolver = this.CreateTestableService();

            // Act & assert
            ExceptionAssert.ThrowsArgumentNull(() => resolver.SelectHandler(null), "request");
        }
コード例 #2
0
        public void WhenSelectingBadHandlerThenThrowsInvalidOperationException()
        {
            // Assign
            DefaultCommandHandlerSelector resolver = this.CreateTestableService();
            CommandHandlerRequest         request  = new CommandHandlerRequest(this.config, new BadCommand());

            // Act & assert
            Assert.Throws <InvalidOperationException>(() => resolver.SelectHandler(request));
        }
コード例 #3
0
        public void WhenSelectingDuplicateHandlerThenThrowsInvalidOperationException()
        {
            // Assign
            DefaultCommandHandlerSelector resolver = this.CreateTestableService();
            CommandHandlerRequest         request  = new CommandHandlerRequest(this.config, new SimpleCommand());

            this.config.Services.Replace(typeof(ICommandHandlerTypeResolver), new DuplicateCommandHandlerTypeResolver());

            // Act & assert
            Assert.Throws <InvalidOperationException>(() => resolver.SelectHandler(request));
        }
コード例 #4
0
        public void WhenSelectingHandlerThenReturnHandlerDesciptor()
        {
            // Assign
            DefaultCommandHandlerSelector resolver = this.CreateTestableService();
            CommandHandlerRequest         request  = new CommandHandlerRequest(this.config, new SimpleCommand());

            this.config.Services.Replace(typeof(ICommandHandlerTypeResolver), new SimpleCommandHandlerTypeResolver());

            // Act
            var descriptor = resolver.SelectHandler(request);

            // Assert
            Assert.NotNull(descriptor);
            Assert.Equal(typeof(SimpleHandler1), descriptor.HandlerType);
            Assert.Equal(typeof(SimpleCommand), descriptor.MessageType);
        }
コード例 #5
0
        public void WhenGettingHandlerMappingThenReturnsMapping()
        {
            // Assign
            DefaultCommandHandlerSelector resolver = this.CreateTestableService();

            this.config.Services.Replace(typeof(ICommandHandlerTypeResolver), new MultipleCommandHandlerTypeResolver());

            // Act
            var mapping = resolver.GetHandlerMapping();

            // Assert
            Assert.NotNull(mapping);
            Assert.Equal(2, mapping.Count);
            Assert.True(mapping.ContainsKey(typeof(SimpleCommand)));
            Assert.True(mapping.ContainsKey(typeof(SimpleCommand2)));

            Assert.Equal(mapping[typeof(SimpleCommand)].HandlerType, typeof(SimpleHandler1));
            Assert.Equal(mapping[typeof(SimpleCommand2)].HandlerType, typeof(SimpleHandler3));
        }
コード例 #6
0
        public DefaultServices(ProcessorConfiguration configuration)
        {
            if (configuration == null)
            {
                throw Error.ArgumentNull("configuration");
            }

            this.configuration = configuration;

            // Initialize the dictionary with all known service types, even if the list for that service type is
            // empty, because we will throw if the developer tries to read or write unsupported types.
            DefaultCommandHandlerSelector commandHandlerSelector = new DefaultCommandHandlerSelector(this.configuration);

            this.SetSingle <ICommandHandlerSelector>(commandHandlerSelector);
            this.SetSingle <ICommandHandlerDescriptorProvider>(commandHandlerSelector);
            this.SetSingle <ICommandHandlerActivator>(new DefaultCommandHandlerActivator());
            this.SetSingle <ICommandHandlerTypeResolver>(new DefaultCommandHandlerTypeResolver());

            // Events
            DefaultEventHandlerSelector eventHandlerSelector = new DefaultEventHandlerSelector(this.configuration);

            this.SetSingle <IEventHandlerSelector>(eventHandlerSelector);
            this.SetSingle <IEventHandlerDescriptorProvider>(eventHandlerSelector);
            this.SetSingle <IEventHandlerActivator>(new DefaultEventHandlerActivator());
            this.SetSingle <IEventHandlerTypeResolver>(new DefaultEventHandlerTypeResolver());
            this.SetSingle <ICommandHandlerInvoker>(new DefaultCommandHandlerInvoker());
            this.SetSingle <IEventHandlerInvoker>(new DefaultEventHandlerInvoker());

            this.SetMultiple <IFilterProvider>(new ConfigurationFilterProvider(), new HandlerFilterProvider());

            this.SetSingle <IAssembliesResolver>(new DefaultAssembliesResolver());

            this.SetSingle <IProxyBuilder>(new DefaultProxyBuilder());
            this.SetSingle <IInterceptionProvider>(new DefaultInterceptionProvider(this.configuration));
            this.SetMultiple <IInterceptor>(new IInterceptor[0]);
            this.SetSingle <ICommandValidator>(new DefaultCommandValidator());

            this.SetSingle <ModelMetadataProvider>(new DataAnnotationsModelMetadataProvider());
            this.SetSingle <IModelFlattener>(new DefaultModelFlattener());

            this.SetSingle <IPrincipalProvider>(new DefaultPrincipalProvider());

            this.SetSingle <IEventStore>(new NullEventStore());

            // Validation
            this.SetMultiple <ModelValidatorProvider>(new DataAnnotationsModelValidatorProvider());
            ModelValidatorCache validatorCache = new ModelValidatorCache(new Lazy <ModelValidatorProvider[]>(this.GetModelValidatorProviders));

            this.SetSingle <IModelValidatorCache>(validatorCache);

            // Tracing
            this.SetSingle <ITraceManager>(new TraceManager());
            this.SetSingle <ITraceWriter>(null);

            this.SetSingle <ICommandWorker>(new DefaultCommandWorker(configuration));
            this.SetSingle <IEventWorker>(new DefaultEventWorker(configuration));
            this.SetSingle <IMessageProcessor>(null);

            this.SetSingle <IQueryService>(new DefaultQueryService());

            // Exception handling
            this.SetSingle <IExceptionHandler>(null);
            this.SetMultiple <IExceptionLogger>();

            // Queuing
            this.SetSingle <ICommandReceiver>(null);
            this.SetSingle <ICommandSender>(null);

            this.serviceTypesSingle = new HashSet <Type>(this.defaultServicesSingle.Keys);
            this.serviceTypesMulti  = new HashSet <Type>(this.defaultServicesMulti.Keys);

            // Reset the caches and the known dependency scope
            this.ResetCache();
        }