public void NoMatchingRegistrationWithNoNoMatchingRegistrationEventHandler()
        {
            var busSettings     = new BusSettings();
            var updater         = new OuterPipelineDetector();
            var dependencyScope = new TestDependencyScope();

            var busBuilder         = new BusBuilder();
            var pipelineBuilder    = new PipelineBuilder(busBuilder);
            var pipelineRunBuilder = new PipelineRunBuilder(busSettings, pipelineBuilder, updater, dependencyScope);

            Action action = () => pipelineRunBuilder.GetRunnerForPipeline(typeof(TestCommand));

            action.ShouldThrowExactly <NoRegistrationForMessageException>().And.MessageType.Should().Be(typeof(TestCommand));
        }
        public async Task HandlingCommandWithNoRegisteredHandlerShouldRunNoMatchingRegistrationHandler()
        {
            var busSettings     = new BusSettings();
            var updater         = new OuterPipelineDetector();
            var dependencyScope = new TestDependencyScope();

            var handler     = new TestEventHandler();
            var handlerShim = new EventHandlerShim <NoMatchingRegistrationEvent, TestEventHandler>(handler);

            dependencyScope.AddObject(handlerShim);

            var busBuilder = new BusBuilder()
                             .RegisterEventHandler <NoMatchingRegistrationEvent, TestEventHandler>();
            var pipelineBuilder    = new PipelineBuilder(busBuilder);
            var pipelineRunBuilder = new PipelineRunBuilder(busSettings, pipelineBuilder, updater, dependencyScope);

            var runner = pipelineRunBuilder.GetRunnerForPipeline(typeof(TestCommand));

            await runner.Handle(new TestCommand());

            handler.CallsToHandle.Should().Be(1);
        }
예제 #3
0
        public object Create(object request, ISpecimenContext context)
        {
            var type = request as Type;

            if (type != null && _factories.ContainsKey(type))
            {
                return(_factories[type].Invoke(context, request));
            }

            if (TestDependencyScope.IsInitialized() && type != null && TestDependencyScope.Resolve(type) != null)
            {
                return(TestDependencyScope.Resolve(type));
            }

            var property = request as PropertyInfo;

            if (property == null)
            {
                return(new NoSpecimen());
            }

            if (_defaultValues.ContainsKey(property))
            {
                var value = _defaultValues[property];
                return(value);
            }

            if (_defaultBuilders.ContainsKey(property))
            {
                var builder = _defaultBuilders[property];
                var value   = builder(request, context);
                return(value);
            }

            return(new NoSpecimen());
        }