public void ProxySendsCommandsAndTheyAreReceivedCorrectly()
    {
        var options = new BusOptions()
        {
            QueueName = "ProxyTestQueue02"
        };
        var serviceMock = new OtherMicroserviceMock();

        using (var host = new MicroserviceHost <OtherMicroserviceMock>(serviceMock, options))
            using (var proxy = new MicroserviceProxy(options))
            {
                host.Open();

                var command = new SomeCommand()
                {
                    SomeValue = "teststring"
                };
                proxy.Execute(command);

                serviceMock.ReceivedFlag.WaitOne(500);

                Assert.True(serviceMock.SomeCommandHandlerHasBeenCalled);
                Assert.Equal("teststring", serviceMock.SomeCommandHandlerReceivedSomeCommand.SomeValue);
            }
    }
Exemple #2
0
        protected override async Task When()
        {
            var someCommand = new SomeCommand();
            await Bus.Send(someCommand);

            await Timeout.WaitUntil(() => MethodCallCounter.AllReceivedMessages.Any());
        }
        public void CanDoTheConfigThing()
        {
            var database = MongoHelper.InitializeTestDatabase();

            var fullConfiguration = CommandProcessor.With()
                                    .Logging(l => l.UseConsole())
                                    .EventStore(e => e.UseMongoDb(database, "Events"))
                                    .AggregateRootRepository(r => r.EnableInMemorySnapshotCaching(10000))
                                    .EventDispatcher(d => d.UseViewManagerEventDispatcher())
                                    .Options(o =>
            {
                o.PurgeExistingViews(true);
                o.AddDomainExceptionType <ApplicationException>();
                o.SetMaxRetries(10);
            });

            var processor = fullConfiguration.Create();

            RegisterForDisposal(processor);

            var someCommand = new SomeCommand();

            processor.ProcessCommand(someCommand);

            Assert.That(someCommand.WasProcessed, Is.EqualTo(true));
        }
        public void InvalidRoutesShouldThrow(SomeCommand command)
        {
            var httpRouteExtractor = new HttpRouteExtractor(AppDomainScanner.ScanForAllTypes);

            Action action = () => httpRouteExtractor.ExtractHttpRoute(command);

            action.ShouldThrow <PayloadRoutingException>();
        }
        public override async Task When(ITestHarnessBusFactory busFactory)
        {
            var bus = busFactory.Create();

            var someCommand = new SomeCommand();
            await bus.Send(someCommand);
            TimeSpan.FromSeconds(5).SleepUntil(() => MethodCallCounter.AllReceivedMessages.Any());
        }
        public void ValidRoutesShouldResolve(SomeCommand command, string expected)
        {
            var httpRouteExtractor = new HttpRouteExtractor(AppDomainScanner.ScanForAllTypes);

            var httpRoute = httpRouteExtractor.ExtractHttpRoute(command);

            httpRoute.Should().Be(expected);
        }
        public void Sending_command_when_multiple_handlers_throws()
        {
            var command = new SomeCommand();

            _kernel.Bind<ICommandHandler<SomeCommand>>().ToConstant(new ActionCommandHandler<SomeCommand>(c => { }));
            _kernel.Bind<ICommandHandler<SomeCommand>>().ToConstant(new ActionCommandHandler<SomeCommand>(c => { }));

            AssertionHelpers.ShouldThrow<InvalidOperationException>(() => _bus.Send(command));
        }
Exemple #8
0
        public int HandleCalculateCommand(SomeCommand command)
        {
            Console.WriteLine($"Got fib-request for {command.Value}");

            var fibResult = CalculateFib(command.Value);

            Console.WriteLine($"Calculated fib result: {fibResult}\n");

            return(fibResult);
        }
        public async Task SendExampleCommandWithoutResult(int amount)
        {
            var command = new SomeCommand {
                Value = amount
            };

            await _commandPublisher.SendCommandAsync(
                command,
                QueueName,
                VoidCommandKey);
        }
        public async Task <int> SendExampleCommandWithResult(int amount)
        {
            var command = new SomeCommand {
                Value = amount
            };

            return(await _commandPublisher.SendCommandAsync <int>(
                       command,
                       QueueName,
                       FibCommandKey));
        }
Exemple #11
0
        public void Sending_command_executes_handler()
        {
            ICommand handledCommand = null;

            Action<SomeCommand> handler = c => handledCommand = c;
            _kernel.Bind<ICommandHandler<SomeCommand>>().ToConstant(new ActionCommandHandler<SomeCommand>(handler));

            var command = new SomeCommand();

            _bus.Send(command);

            handledCommand.ShouldNotBeNull();
            handledCommand.ShouldBeSameAs(command);
        }
Exemple #12
0
        public void option_parsing_works()
        {
            SomeCommand defaults = new SomeCommand();

            defaults.DOption.ShouldBeFalse();
            defaults.Source.Should(Be.Null);
            defaults.Query.Should(Be.Null);

            // moo search foo -d --source http://this.that
            SomeCommand cmd = new SomeCommand(new string[] { "foo", "-d", "--source", "http://this.that" });

            cmd.DOption.ShouldBeTrue();
            cmd.Source.ShouldEqual("http://this.that");
            cmd.Query.ShouldEqual("foo");
        }
    public void HandlerNotInInterfaceShouldNotBeTriggered()
    {
        var options = new BusOptions()
        {
            QueueName = "TestQueue01"
        };
        var serviceMock = new HalfServiceMock();

        using (var host = new MicroserviceHost <HalfServiceMock>(serviceMock, options))
            using (var proxy = new MicroserviceProxy(options))
            {
                host.Open();

                var command = new SomeCommand()
                {
                    SomeValue = "teststring"
                };
                Action action = () => proxy.Execute(command);

                Assert.Throws <MicroserviceException>(action);
                Assert.False(serviceMock.SomeCommandHandlerHasBeenCalled);
            }
    }
    public void MicroserviceHostReceivesCommands()
    {
        var serviceMock = new SomeMicroserviceMock();

        using (var host = new MicroserviceHost <SomeMicroserviceMock>(serviceMock))
        {
            var options = new BusOptions()
            {
                QueueName = "microserviceQueue"
            };

            host.Open();

            var command = new SomeCommand()
            {
                SomeValue = "teststring"
            };
            SendMessage(command, options);
            serviceMock.ReceivedFlag.WaitOne(500);

            Assert.True(serviceMock.SomeCommandHandlerHasBeenCalled);
            Assert.False(serviceMock.TestCommandHandlerHasBeenCalled);
        }
    }
    public void ProxySendsCommands()
    {
        var options = new BusOptions()
        {
            QueueName = "ProxyTestQueue01"
        };
        var serviceMock = new OtherMicroserviceMock();

        using (var host = new MicroserviceHost <OtherMicroserviceMock>(serviceMock, options))
            using (var proxy = new MicroserviceProxy(options))
            {
                host.Open();

                var command = new SomeCommand()
                {
                    SomeValue = "teststring"
                };
                proxy.Execute(command);

                Thread.Sleep(500);

                Assert.True(serviceMock.SomeCommandHandlerHasBeenCalled);
            }
    }
 protected override async Task When()
 {
     var someCommand = new SomeCommand();
     await Bus.Send(someCommand);
     await Timeout.WaitUntil(() => MethodCallCounter.AllReceivedMessages.Any());
 }
Exemple #17
0
 public void HandleVoidCommand(SomeCommand command)
 {
     Console.WriteLine($"Got void-request for {command.Value}");
 }
 public override async Task When()
 {
     var someCommand = new SomeCommand();
     await Bus.Send(someCommand);
     TimeSpan.FromSeconds(5).SleepUntil(() => MethodCallCounter.AllReceivedMessages.Any());
 }
Exemple #19
0
 public PublishedEvent Handle(SomeCommand message)
 {
     return new PublishedEvent();
 }
 public override async Task WhenAsync()
 {
     var someCommand = new SomeCommand();
     await Subject.Send(someCommand);
     TimeSpan.FromSeconds(5).SleepUntil(() => MessageBroker.AllReceivedMessages.Any());
 }
Exemple #21
0
 public PublishedEvent Handle(SomeCommand message)
 {
     return(new PublishedEvent());
 }
Exemple #22
0
        public void Sending_command_when_no_handler_throws()
        {
            var command = new SomeCommand();

            AssertionHelpers.ShouldThrow<InvalidOperationException>(() => _bus.Send(command));
        }