public void Given_command_server_runnig()
        {
            var config = ZazServer.ConfigureAsSelfHosted(URL, new ServerConfiguration
            {
                Registry = new FooCommandRegistry(),
                Broker = new DelegatingCommandBroker((cmd, ctx) =>
                {
                    throw new InvalidOperationException("Server failed...");
                    // return Task.Factory.StartNew(() => { });
                })
            });

            using (var host = new HttpSelfHostServer(config))
            {
                host.OpenAsync().Wait();

                // Client side
                var bus = new ZazClient(URL);
                try
                {
                    bus.PostAsync(new FooCommand
                    {
                        Message = "Hello world"
                    }).Wait();
                }
                catch (Exception ex)
                {
                    _resultEx = ex;
                }
            }
        }
 public void Should_successfully_send_command()
 {
     var bus = new ZazClient(URL);
     bus.PostAsync(new PrintMessage
     {
         Message = "Hello world"
     }).Wait();
 }
Beispiel #3
0
 static void Main()
 {
     var bus = new ZazClient("http://localhost.fiddler:9302/Commands");
     bus.PostAsync(new PrintMessage
     {
         Message = "Hello world"
     }).Wait();
 }
        public void Should_execute_the_command_with_valid_tokent_attached()
        {
            var bus = new ZazClient(URL1, new ZazConfiguration
            {
                ConfigureDefaultHeaders = c => c.Add("X-Api-Token", "ValidToken")
            });
            bus.PostAsync(new FooCommand { Message = "Hello world" }).Wait();

            _postedCommand.Should().NotBeNull();
        }
        public void Should_fail_when_token_is_not_attached()
        {
            var bus = new ZazClient(URL1, new ZazConfiguration
            {
                ConfigureDefaultHeaders = c => c.Add("X-Api-Token", "InvalidToken")
            });

            Action res = () => bus.PostAsync(new FooCommand { Message = "Hello world" }).Wait();

            res.ShouldThrow<Exception>();
        }
        public void Given_command_server_runnig()
        {
            var config = ZazServer.ConfigureAsSelfHosted(URL, new ServerConfiguration
            {
                Registry = new ReflectionCommandRegistry(typeof(__SampleCommandsMarker).Assembly),
                Broker = new ReflectionCommandBroker(typeof(__SampleHandlersMarker).Assembly),
            });

            _host = new HttpSelfHostServer(config);
            _host.OpenAsync().Wait();

            _client = new ZazClient(URL);
        }
        public void Should_successfully_send_command()
        {
            Action send = () =>
            {
                var configuration = new ZazConfiguration();
                configuration.SetupSimpleBasicAuthentication("user", "unknown");
                var bus = new ZazClient(URL, configuration);

                bus.PostAsync(new FooCommand
                {
                    Message = "Hello world"
                }).Wait();
            };

            send.ShouldThrow<Exception>();
        }
 public void Given_command_server_runnig()
 {
     // Client side
     var bus = new ZazClient(URL);
     try
     {
         bus.PostAsync(new FooCommand
         {
             Message = "Hello world"
         }).Wait();
     }
     catch (Exception ex)
     {
         _resultEx = ex;
     }
 }
        public void Should_despatch_commands_between_controllers_by_prefixes()
        {
            var client1 = new ZazClient(URL1);
            var client2 = new ZazClient(URL2);

            var cmd1 = new FooCommand
            {
                Message = "Command #1"
            };
            var cmd2 = new FooCommand
            {
                Message = "Command #2"
            };

            client1.PostAsync(cmd1).Wait();
            client2.PostAsync(cmd2).Wait();

            _api1Command.Message.Should().Be(cmd1.Message);
            _api2Command.Message.Should().Be(cmd2.Message);
        }
        public void Given_command_server_runnig()
        {
            _commandBroker = new NullCommandBroker();

            var config = ZazServer.ConfigureAsSelfHosted(URL, new ServerConfiguration
            {
                Registry = new ReflectionCommandRegistry(typeof(__SampleCommandsMarker).Assembly),
                Broker = _commandBroker,
            });

            using (var host = new HttpSelfHostServer(config))
            {
                host.OpenAsync().Wait();

                var bus = new ZazClient(URL);
                bus.PostAsync(new HugeFoo
                {
                    Data = new String('a', 2097152)
                }).Wait();
            }
        }
        public void Given_command_server_runnig()
        {
            var serverConfiguration = new ServerConfiguration
            {
                Registry = new FooCommandRegistry(),
                Broker = new DelegatingCommandBroker((cmd, ctx) =>
                {
                    _postedCommand = cmd;
                    _ctx = ctx;

                    _principal = Thread.CurrentPrincipal;

                    return Task.Factory.StartNew(() => { });
                }),
                ConfigureHttp = http => http.SetupBasicAuthentication("supr", "booper", "")
            };

            var config = ZazServer.ConfigureAsSelfHosted(URL, serverConfiguration);
            _host = new HttpSelfHostServer(config);

            //SimpleBasicAuthenticationHandler.Configure(config, cred => cred.UserName == "supr" && cred.Password == "booper");

            using (new HttpSelfHostServer(config))
            {
                _host.OpenAsync().Wait();

                // Client side
                var configuration = new ZazConfiguration();
                configuration.SetupSimpleBasicAuthentication("supr", "booper");

                var client = new ZazClient(URL, configuration);

                client.PostAsync(new FooCommand
                {
                    Message = "Hello world"
                }).Wait();
            }
        }
        public void Given_command_server_runnig()
        {
            var config = ZazServer.ConfigureAsSelfHosted(URL, new ServerConfiguration
            {
                Registry = new FooCommandRegistry(),
                Broker = new DelegatingCommandBroker((cmd, ctx) =>
                {
                    _postedCommand = cmd;
                    _ctx = ctx;

                    return Task.Factory.StartNew(() =>
                    {
                        ctx.Log.Info("Hello word! #1");
                        Thread.Sleep(TimeSpan.FromSeconds(1));

                        ctx.Log.Info("Hello word! #2");
                        Thread.Sleep(TimeSpan.FromSeconds(1));

                        ctx.Log.Info("Hello word! #3");
                        Thread.Sleep(TimeSpan.FromSeconds(1));

                        ctx.Log.Info("Hello word! #4");
                    });
                })
            });

            using (var host = new HttpSelfHostServer(config))
            {
                host.OpenAsync().Wait();

                var bus = new ZazClient(URL);
                bus.PostAsync(new FooCommand
                {
                    Message = "Heeeeelllllloooooo!"
                }).Wait();
            }
        }
        public void Should_successfully_send_all_commands_and_recieve_the_result()
        {
            const int concurrentCalls = 20;

            var allTasks = new List<Task>();

            for (var i = 0; i < concurrentCalls; i++)
            {
                var local = i;
                var task = Task.Factory.StartNew(() =>
                {
                    var client = new ZazClient(URL);
                    var cmd = new PrintMessage { Message = "Hello world #" + (local + 1) };
                    var result = client.PostAsync(cmd, new[] { "Tag1" }).Result;
                    return result;
                });

                allTasks.Add(task);
            }

            var allTasksArray = allTasks.ToArray();
            Task.WaitAll(allTasksArray, TimeSpan.FromMinutes(5));

            var counters = new
            {
                RanToCompletion = allTasks.Count(task => task.Status == TaskStatus.RanToCompletion),
                Canceled = allTasks.Count(task => task.Status == TaskStatus.Canceled),
                Created = allTasks.Count(task => task.Status == TaskStatus.Created),
                Faulted = allTasks.Count(task => task.Status == TaskStatus.Faulted),
                Running = allTasks.Count(task => task.Status == TaskStatus.Running),
                WaitingForActivation = allTasks.Count(task => task.Status == TaskStatus.WaitingForActivation),
                WaitingForChildrenToComplete = allTasks.Count(task => task.Status == TaskStatus.WaitingForChildrenToComplete),
                WaitingToRun = allTasks.Count(task => task.Status == TaskStatus.WaitingToRun),
            };

            counters.RanToCompletion.Should().Be(concurrentCalls, "All tasks should be completed in reasonable period of time", counters);
        }