Esempio n. 1
0
 public static void Scenario <T>(Action <Scenario> configuration) where T : FubuRegistry, new()
 {
     using (var host = FubuRuntime.For <T>())
     {
         host.Scenario(configuration);
     }
 }
Esempio n. 2
0
        private static async Task perform_work <TRegistry>(Action <IServiceBus> actualWork) where TRegistry : FubuRegistry, new()
        {
            PongConsumer.Count       = 0;
            PongConsumer.ReceivedAll = new TaskCompletionSource <bool>();
            using (var runtime = FubuRuntime.For <TRegistry>())
            {
                var bus   = runtime.Get <IServiceBus>();
                var tasks = new List <Task>();
                for (var i = 0; i < Times; ++i)
                {
                    if (i == 10)
                    {
                        if (JetBrains.Profiler.Windows.Api.PerformanceProfiler.IsActive)
                        {
                            JetBrains.Profiler.Windows.Api.PerformanceProfiler.Begin();
                            JetBrains.Profiler.Windows.Api.PerformanceProfiler.Start();
                        }
                    }
                    var task = Task.Run(() =>
                    {
                        actualWork(bus);
                    });
                    tasks.Add(task);
                }
                await Task.WhenAll(tasks);

                await PongConsumer.ReceivedAll.Task;
                if (JetBrains.Profiler.Windows.Api.PerformanceProfiler.IsActive)
                {
                    JetBrains.Profiler.Windows.Api.PerformanceProfiler.Stop();
                    JetBrains.Profiler.Windows.Api.PerformanceProfiler.EndSave();
                }
            }
        }
        public void SetUp()
        {
            // Need to do something about this.  Little ridiculous
            var settings = new BusSettings
            {
                Downstream = "lq.tcp://localhost:2050/downstream".ToUri()
            };


            theClock = new SettableClock();


            _runtime = FubuRuntime.For <DelayedRegistry>(_ =>
            {
                _.Services.ReplaceService(settings);
                _.Services.ReplaceService <ISystemTime>(theClock);
            });

            theServiceBus = _runtime.Get <IServiceBus>();
            //_runtime.Get<IPersistentQueues>().ClearAll();

            message1 = new OneMessage();
            message2 = new OneMessage();
            message3 = new OneMessage();
            message4 = new OneMessage();

            Debug.WriteLine("The current Utc time is " + theClock.UtcNow());

            theServiceBus.DelaySend(message1, theClock.UtcNow().AddHours(1));
            theServiceBus.DelaySend(message2, theClock.UtcNow().AddHours(1));
            theServiceBus.DelaySend(message3, theClock.UtcNow().AddHours(2));
            theServiceBus.DelaySend(message4, theClock.UtcNow().AddHours(2));
        }
Esempio n. 4
0
        public void use_complete_reset()
        {
            using (var runtime = FubuRuntime.For <MartenApp>())
            {
                var store = runtime.Get <IDocumentStore>();
                store.Advanced.Clean.CompletelyRemoveAll();

                using (var session = store.LightweightSession())
                {
                    session.Store(new User {
                        Id = "Jeremy"
                    }, new User {
                        Id = "Corey"
                    }, new User {
                        Id = "Jens"
                    });
                    session.SaveChanges();
                    session.Query <User>().Count().ShouldBe(3);
                }

                runtime.Get <ICompleteReset>().ResetState();

                using (var session = store.QuerySession())
                {
                    session.Query <User>().Any().ShouldBeFalse();
                }
            }
        }
Esempio n. 5
0
        public void SetUp()
        {
            TestMessageRecorder.Clear();

            // Need to do something about this.  Little ridiculous
            var settings = new BusSettings
            {
                Downstream = "lq.tcp://localhost:2040/downstream".ToUri()
            };
            var lightningUri = settings.Downstream.ToLightningUri();


            _runtime = FubuRuntime.For <ErrorRegistry>(x =>
            {
                x.Services.For <BusSettings>().Use(settings);
            });


            _runtime.Get <IPersistentQueues>().ClearAll();

            theServiceBus = _runtime.Get <IServiceBus>();

            _queueManager = _runtime.Get <IPersistentQueues>().PersistentManagerFor(lightningUri.Port, true);

            message1 = new OneMessage();

            theServiceBus.Send(message1);
        }
Esempio n. 6
0
        public void chain_is_on_the_endpoint()
        {
            var runtime  = FubuRuntime.For <SomeRegistry>();
            var endpoint = runtime.Get <IEndpointService>().EndpointFor <SomeEndpoint>(x => x.get_hello());

            endpoint.Chain.Calls.Single().HandlerType.ShouldBe(typeof(SomeEndpoint));
        }
        public void FixtureSetUp()
        {
            //FubuTransport.AllQueuesInMemory = true;

            runtime = FubuRuntime.For <TestingJobRegistry>();

            history        = runtime.Get <JobHistory>();
            clock          = runtime.Get <ISystemTime>().As <RewindableClock>();
            theController  = runtime.Get <IScheduledJobController>();
            thePersistence = runtime.Get <ISchedulePersistence>();
            theTimer       = runtime.Get <IJobTimer>();

            theController.Deactivate();
            theTimer.ClearAll();
            history.ClearAll();

            theStartingTime = (DateTimeOffset)DateTime.Today.AddHours(8).ToUniversalTime();

            theEndingTime = theStartingTime.AddSeconds(30);

            addTimes <Job1>(3);
            addTimes <Job2>(10);
            addTimes <Job3>(15);

            clock.Reset(theStartingTime.DateTime);

            theController.Activate();

            theController.IsActive().ShouldBeTrue();

            Thread.Sleep(32.Seconds());

            theController.Deactivate();
        }
Esempio n. 8
0
        public void querysession_is_wired_up()
        {
            using (var runtime = FubuRuntime.For <MartenApp>())
            {
                var store = runtime.Get <IDocumentStore>();

                store.Advanced.Clean.CompletelyRemoveAll();

                using (var session = store.LightweightSession())
                {
                    session.Store(new User {
                        Id = "Jeremy"
                    }, new User {
                        Id = "Corey"
                    }, new User {
                        Id = "Jens"
                    });
                    session.SaveChanges();
                }

                runtime.Scenario(_ =>
                {
                    _.Get.Url("");
                    _.ContentShouldBe("Corey, Jens, Jeremy");
                });
            }
        }
        public void invoking_a_chain_will_execute_completely_with_cascading_immediate_continuations()
        {
            using (var runtime = FubuRuntime.For <ChainInvokerTransportRegistry>())
            {
                var recorder = runtime.Get <MessageRecorder>();

                var invoker = runtime.Get <IChainInvoker>();

                MessageHistory.WaitForWorkToFinish(() =>
                {
                    invoker.InvokeNow(new TriggerImmediate {
                        Text = "First", ContinueText = "I'm good"
                    });
                });

                // Should process all the cascading messages that bubble up
                // and their cascaded messages
                recorder.Messages.ShouldContain("First");
                recorder.Messages.ShouldContain("I'm good");
                recorder.Messages.ShouldContain("I'm good-2");
                recorder.Messages.ShouldContain("I'm good-2-4");
                recorder.Messages.ShouldContain("I'm good-2-3");
                recorder.Messages.ShouldContain("Traced: I'm good");
            }
        }
Esempio n. 10
0
 private static async Task send_and_respond_roundtrip_separate_endpoints_helper()
 {
     using (FubuRuntime.For <PongerTransportRegistry>())
     {
         await perform_work <PingerTransportRegistry>(x => x.Send(new PingMessage()));
     }
 }
Esempio n. 11
0
 public void PurgeQueuesJob_is_registered()
 {
     using (var runtime = FubuRuntime.For <TestRegistry>())
     {
         runtime.Get <IPollingJobs>().Any(x => x is PollingJob <PurgeQueuesJob, LightningQueueSettings>)
         .ShouldBeTrue();
     }
 }
 public void should_be_applied_to_all()
 {
     using (var runtime = FubuRuntime.For <AuthorizedRegistry>(_ => _.Mode = "development"))
     {
         runtime.Behaviors.ChainFor <FubuDiagnosticsEndpoint>(x => x.get__fubu()).Authorization.AllowedRoles().ShouldContain("admin");
         runtime.Behaviors.ChainFor <EndpointExplorerFubuDiagnostics>(x => x.get_endpoints()).Authorization.AllowedRoles().ShouldContain("admin");
     }
 }
        public void should_throw_invalid_transport_exception_because_there_are_no_incoming_lq_transports()
        {
            var message =
                Exception <FubuException> .ShouldBeThrownBy(
                    () => FubuRuntime.For <BadTransportRegistry>()).Message;

            message.ShouldContain("You must have at least one incoming Lightning Queue channel for accepting replies");
        }
Esempio n. 14
0
        public void SetUp()
        {
            _runtime  = FubuRuntime.For <ApplicationRegistry>();
            behaviors = _runtime.Get <BehaviorGraph>();

            appChain = behaviors.ChainFor <ApplicationActions>(x => x.get_app_action());
            pakChain = behaviors.ChainFor <PackageActions>(x => x.get_pak_action());
        }
        public void SetUp()
        {
            ImmediateJob.Executed = DelayJob.Executed = DisabledJob.Executed = 0;

            theRuntime = FubuRuntime.For<PollingImmediateRegistry>()
                                      
                                      ;
        }
Esempio n. 16
0
        public void SetUp()
        {
            AJob.Reset();
            BJob.Reset();
            CJob.Reset();

            theRuntime = FubuRuntime.For <ScheduledJobRegistry>()

            ;
        }
Esempio n. 17
0
        private static void Main(string[] args)
        {
            using (var server = FubuRuntime.For <TestHarnessRegistry>(_ => _.HostWith <Katana>()))
            {
                Process.Start(server.BaseAddress);

                Console.WriteLine("Press any key to quit");
                Console.ReadLine();
            }
        }
Esempio n. 18
0
        public async Task registry_AddService_creates_instance()
        {
            var runtime = FubuRuntime.For <PingApp>();

            var count = runtime.CurrentContainer.GetAllInstances <IFakeService>().Count();

            count.ShouldBe(1);

            runtime.Dispose();
        }
Esempio n. 19
0
        public void command_logging_in_prod_mode()
        {
            using (var runtime = FubuRuntime.For <MartenApp>())
            {
                runtime.Get <IMartenSessionLogger>().ShouldBeOfType <NulloMartenLogger>();

                runtime.Get <IDocumentSession>().Logger.ShouldNotBeOfType <CommandRecordingLogger>();
                runtime.Get <IQuerySession>().Logger.ShouldNotBeOfType <CommandRecordingLogger>();
            }
        }
        public void posts_are_committed()
        {
            var container = new Container(new RavenDbRegistry());

            container.Configure(x => x.For <ITenantContext>().Use <NulloTenantContext>());

            container.Inject(new RavenDbSettings {
                RunInMemory = true
            });

            using (var application = FubuRuntime.For <NamedEntityRegistry>(_ =>
            {
                _.StructureMap(container);
                _.HostWith <Katana>();
            }))
            {
                application.Scenario(_ =>
                {
                    _.Post.Json(new NamedEntity {
                        Name = "Jeremy"
                    });
                });

                application.Scenario(_ =>
                {
                    _.Post.Json(new NamedEntity {
                        Name = "Josh"
                    });
                });

                application.Scenario(_ =>
                {
                    _.Post.Json(new NamedEntity {
                        Name = "Vyrak"
                    });
                });



                application.Get <ITransaction>().Execute <IDocumentSession>(session => {
                    session.Query <NamedEntity>()
                    .Customize(x => x.WaitForNonStaleResults())
                    .Each(x => Debug.WriteLine(x.Name));
                });


                application.Scenario(_ =>
                {
                    _.Get.Action <FakeEntityEndpoint>(x => x.get_names());
                    _.Response.Body.ReadAsJson <NamesResponse>()
                    .Names.ShouldHaveTheSameElementsAs("Jeremy", "Josh", "Vyrak");
                });
            }
        }
        public void can_register_modifiers_by_channel()
        {
            using (var runtime = FubuRuntime.For <ModifyingChannelRegistry>())
            {
                var graph = runtime.Get <ChannelGraph>();

                graph.ChannelFor <BusSettings>(x => x.Downstream).Modifiers.Single().ShouldBeOfType <FooModifier>();
                graph.ChannelFor <BusSettings>(x => x.Upstream).Modifiers.Single().ShouldBeOfType <BarModifier>();
                graph.ChannelFor <BusSettings>(x => x.Outbound).Modifiers.Any().ShouldBeFalse();
            }
        }
Esempio n. 22
0
 public static void do_the_home_page()
 {
     using (var runtime = FubuRuntime.For <SampleApp>())
     {
         runtime.Scenario(_ =>
         {
             _.Get.Url("");
             _.ContentShouldBe("Hello, World");
         });
     }
 }
Esempio n. 23
0
        public void the_delayed_processing_polling_job_is_registered()
        {
            using (var runtime = FubuRuntime.For <DelayedRegistry>())
            {
                runtime.Behaviors.Chains.Where(x => x.InputType() == typeof(JobRequest <DelayedEnvelopeProcessor>))
                .Each(x => Debug.WriteLine(x.Title()));

                runtime.Get <IPollingJobs>().Any(x => x is PollingJob <DelayedEnvelopeProcessor, TransportSettings>)
                .ShouldBeTrue();
            }
        }
Esempio n. 24
0
        public void SetUp()
        {
            OneJob.Executed = TwoJob.Executed = ThreeJob.Executed = 0;

            theRuntime = FubuRuntime.For <PollingRegistry>();
            theRuntime.Behaviors.PollingJobs.Any().ShouldBeTrue();

            container = theRuntime.Get <IContainer>();

            Wait.Until(() => ThreeJob.Executed > 10, timeoutInMilliseconds: 6000);
        }
        public void PersistedLoginAuditor_is_registered()
        {
            var container = new Container(new InMemoryPersistenceRegistry());

            using (
                var application =
                    FubuRuntime.For <FubuRepoWithPersistedMembership>(_ => _.StructureMap(container)))
            {
                application.Get <ILoginAuditor>().ShouldBeOfType <PersistedLoginAuditor>();
            }
        }
 public void can_inject_environment_keys_from_the_fubu_registry()
 {
     using (var server = FubuRuntime
                         .For <OverriddenEnvironmentRegistry>())
     {
         using (var client = new WebClient())
         {
             client.DownloadString(server.BaseAddress.AppendUrl("/environment/Foo")).ShouldBe("1");
             client.DownloadString(server.BaseAddress.AppendUrl("/environment/Bar")).ShouldBe("2");
         }
     }
 }
        public void able_to_derive_the_node_name_from_fubu_transport_registry_name()
        {
            using (var runtime = FubuRuntime.For <CustomTransportRegistry>())
            {
                runtime.Get <ChannelGraph>().Name.ShouldBe("custom");
            }

            using (var fubuRuntime = FubuRuntime.For <OtherRegistry>())
            {
                fubuRuntime.Get <ChannelGraph>().Name.ShouldBe("other");
            }
        }
Esempio n. 28
0
 static void StartDemo()
 {
     // Bootstrapping and runtime configuration
     var pingAppRuntime = FubuRuntime.For <PingApp>(_ =>
                                                    // Diagnostics
                                                    _.Features.Diagnostics.Enable(TraceLevel.Verbose)
                                                    );
     var pongAppRuntime = FubuRuntime.For <PongApp>(_ =>
                                                    // Diagnostics
                                                    _.Features.Diagnostics.Enable(TraceLevel.Verbose)
                                                    );
 }
Esempio n. 29
0
        public void has_all_the_chains_we_expect_through_FubuApplication()
        {
            using (var runtime = FubuRuntime.For <MyFirstTransport>())
            {
                var graph = runtime.Get <BehaviorGraph>();

                graph.Chains.Count(x => typeof(Foo1) == x.InputType()).ShouldBeGreaterThanOrEqualTo(1);
                graph.Chains.Count(x => typeof(Foo2) == x.InputType()).ShouldBeGreaterThanOrEqualTo(1);
                graph.Chains.Count(x => typeof(Foo3) == x.InputType()).ShouldBeGreaterThanOrEqualTo(1);
                graph.Chains.Count(x => typeof(Foo4) == x.InputType()).ShouldBeGreaterThanOrEqualTo(1);
            }
        }
Esempio n. 30
0
        public void the_order()
        {
            using (var runtime = FubuRuntime.For <Defaults>())
            {
                var handlers = runtime.Get <IHandlerPipeline>().ShouldBeOfType <HandlerPipeline>().Handlers;


                handlers[0].ShouldBeOfType <DelayedEnvelopeHandler>();
                handlers[1].ShouldBeOfType <ResponseEnvelopeHandler>();
                handlers[2].ShouldBeOfType <ChainExecutionEnvelopeHandler>();
                handlers[3].ShouldBeOfType <NoSubscriberHandler>();
            }
        }