public void Start() { _controller = _input.BuildRemoteController(); var context = new StorytellerContext(_controller, _input); if (_controller.BinPath.IsEmpty()) { throw new Exception("Could not determine any BinPath for the testing AppDomain. Has the Storyteller specification project been compiled, \nor is Storyteller using the wrong compilation target maybe?\n\ntype 'st.exe ? open' or st.exe ? run' to see the command usages\n\n"); } context.Start(); var registry = new FubuRegistry(); registry.AlterSettings <DiagnosticsSettings>(_ => _.TraceLevel = TraceLevel.Verbose); registry.Mode = "development"; registry.HostWith <NOWIN>(); registry.Services.For <IRemoteController>().Use(_controller); registry.Services.For <StorytellerContext>().Use(context); registry.Services.IncludeRegistry <WebApplicationRegistry>(); _server = registry.ToRuntime(); }
public void see_tracing_logs_in_verbose_mode_happy_path() { var registry = new FubuRegistry(); registry.ServiceBus.Enable(true); registry.Features.Diagnostics.Enable(TraceLevel.Verbose); registry.ServiceBus.EnableInMemoryTransport(); registry.AlterSettings <LightningQueueSettings>(x => x.DisableIfNoChannels = true); using (var runtime = registry.ToRuntime()) { var bus = runtime.Get <IServiceBus>(); bus.Consume(new TracedInput()); var history = runtime.Get <IChainExecutionHistory>(); var log = history.RecentReports().Single(x => x.RootChain != null && x.RootChain.InputType() == typeof(TracedInput)); log.Request["headers"].ShouldBeOfType <Dictionary <string, object> >(); log.Steps.Any().ShouldBeTrue(); log.Steps.Any(x => x.Log is StringMessage).ShouldBeTrue(); log.Steps.Each(x => Debug.WriteLine(x)); } }
public void get_error_messages_in_production_mode() { var registry = new FubuRegistry(); registry.ServiceBus.Enable(true); registry.Features.Diagnostics.Enable(TraceLevel.Production); registry.ServiceBus.EnableInMemoryTransport(); registry.AlterSettings <LightningQueueSettings>(x => x.DisableIfNoChannels = true); using (var runtime = registry.ToRuntime()) { var bus = runtime.Get <IServiceBus>(); bus.Consume(new TracedInput { Fail = true }); var history = runtime.Get <IChainExecutionHistory>(); var log = history.RecentReports().Single(x => x.RootChain != null && x.RootChain.InputType() == typeof(TracedInput)); log.Steps.Any(x => x.Log is ExceptionReport).ShouldBeTrue(); log.HadException.ShouldBeTrue(); } }
public void blows_up_with_no_saml_certificate_repository() { var registry = new FubuRegistry(); registry.AlterSettings <AuthenticationSettings>(_ => { _.Enabled = true; _.Saml2.Enabled = true; }); var samlCertificateRepository = MockRepository.GenerateMock <ISamlCertificateRepository>(); samlCertificateRepository.Stub(r => r.AllKnownCertificates()) .Return(new SamlCertificate[0]); registry.Services.SetServiceIfNone <IPrincipalBuilder>(MockRepository.GenerateMock <IPrincipalBuilder>()); registry.Services.AddService <ISamlResponseHandler>(MockRepository.GenerateMock <ISamlResponseHandler>()); //registry.Services.SetServiceIfNone<ISamlCertificateRepository>(samlCertificateRepository); Exception <StructureMapConfigurationException> .ShouldBeThrownBy(() => { registry.ToRuntime(); }); }
public void register_with_basic_authentication_disabled() { var registry = new FubuRegistry(); registry.AlterSettings <AuthenticationSettings>(_ => { _.Enabled = true; _.Saml2.Enabled = true; }); var samlCertificateRepository = MockRepository.GenerateMock <ISamlCertificateRepository>(); samlCertificateRepository.Stub(x => x.AllKnownCertificates()).Return(new SamlCertificate[0]); registry.Services.SetServiceIfNone <ISamlCertificateRepository>(samlCertificateRepository); registry.Services.SetServiceIfNone <IPrincipalBuilder>(MockRepository.GenerateMock <IPrincipalBuilder>()); registry.Services.AddService <ISamlResponseHandler>(MockRepository.GenerateMock <ISamlResponseHandler>()); registry.AlterSettings <AuthenticationSettings>(x => { x.MembershipEnabled = MembershipStatus.Disabled; }); using (var runtime = registry.ToRuntime()) { var container = runtime.Get <IContainer>(); var strategies = container.GetAllInstances <IAuthenticationStrategy>(); strategies.Single().ShouldBeOfType <SamlAuthenticationStrategy>(); } }
private void registeredTypeIs <TService, TImplementation>() { var registry = new FubuRegistry(); registry.Features.Authentication.Configure(x => { x.Enabled = true; x.Saml2.Enabled = true; }); registry.Services.AddService <IPrincipalBuilder>(MockRepository.GenerateMock <IPrincipalBuilder>()); var samlCertificateRepository = MockRepository.GenerateMock <ISamlCertificateRepository>(); samlCertificateRepository.Stub(x => x.AllKnownCertificates()).Return(new SamlCertificate[0]); registry.Services.SetServiceIfNone <ISamlCertificateRepository>(samlCertificateRepository); registry.Services.SetServiceIfNone <IPrincipalBuilder>(MockRepository.GenerateMock <IPrincipalBuilder>()); registry.Services.AddService <ISamlResponseHandler>(MockRepository.GenerateMock <ISamlResponseHandler>()); using (var runtime = registry.ToRuntime()) { var container = runtime.Get <IContainer>(); container.Model.For <TService>().Default.ReturnedType.ShouldBe(typeof(TImplementation)); } }
public void is_registered() { var registry = new FubuRegistry(); registry.AlterSettings <CommonViewNamespaces>(x => { x.Add("Foo"); x.Add("Bar"); }); using (var runtime = registry.ToRuntime()) { var container = runtime.Get <IContainer>(); var useNamespaces = container.GetInstance <CommonViewNamespaces>(); useNamespaces.Namespaces.ShouldContain(typeof(VirtualPathUtility).Namespace); useNamespaces.Namespaces.ShouldContain(typeof(string).Namespace); useNamespaces.Namespaces.ShouldContain(typeof(FileSet).Namespace); useNamespaces.Namespaces.ShouldContain(typeof(ParallelQuery).Namespace); useNamespaces.Namespaces.ShouldContain(typeof(HtmlTag).Namespace); useNamespaces.Namespaces.ShouldContain("FubuMVC.Tests.Http.Hosting"); useNamespaces.Namespaces.ShouldContain("Foo"); useNamespaces.Namespaces.ShouldContain("Bar"); } }
public void override_services() { var registry = new FubuRegistry(); registry.Services.IncludeRegistry <ThingRegistry>(); using (var runtime = registry.ToRuntime()) { var container = runtime.Get <IContainer>(); var facility = container.GetInstance <IServiceFactory>().As <StructureMapServiceFactory>(); facility.Get <ThingUser>().Thing.ShouldBeOfType <AThing>(); facility.StartNewScope(); facility.Container.Role.ShouldBe(ContainerRole.ProfileOrChild); facility.Container.Configure(_ => _.For <IThing>().Use <BThing>().Singleton()); var bthing = facility.Get <ThingUser>().Thing.ShouldBeOfType <BThing>(); facility.TeardownScope(); // back to normal facility.Get <ThingUser>().Thing.ShouldBeOfType <AThing>(); } }
public void can_inject_the_right_html_on_GET_for_html_text() { var registry = new FubuRegistry(); registry.AlterSettings <OwinSettings>(x => { x.AddMiddleware <HtmlHeadInjectionMiddleware>().Arguments.With(new InjectionOptions { Content = e => new HtmlTag("script").Attr("foo", "bar").ToString() }); }); using (var server = registry.ToRuntime()) { server.Scenario(_ => { _.Get.Action <SimpleHtmlEndpoint>(x => x.get_html_content()); _.ContentShouldContain("<script foo=\"bar\"></script></head>"); }); server.Scenario(_ => { _.Get.Action <SimpleHtmlEndpoint>(x => x.get_text_content()); _.ContentShouldNotContain("<script foo=\"bar\"></script></head>"); }); } }
public void StartUp() { try { _server = _registry.ToRuntime(); GlobalMessageTracking.SendMessage(new ApplicationStarted { ApplicationName = _registry.GetType().Name, HomeAddress = _server.BaseAddress, Timestamp = DateTime.Now, Watcher = _server.Get <AssetSettings>().CreateFileWatcherManifest(_server.Files) }); } catch (HostingFailedException e) { GlobalMessageTracking.SendMessage(new InvalidApplication { ExceptionText = e.Message, Message = "Access denied." }); } catch (Exception e) { GlobalMessageTracking.SendMessage(new InvalidApplication { ExceptionText = e.ToString(), Message = "Bootstrapping {0} Failed!".ToFormat(_registry.GetType().Name) }); } }
private FubuRuntime serverFor(Action <OwinSettings> action) { var registry = new FubuRegistry(); registry.AlterSettings(action); registry.HostWith <Katana>(); return(registry.ToRuntime()); }
public void SetUp() { var registry = new FubuRegistry(x => { x.Actions.IncludeType <AsyncAction>(); x.Policies.Local.Add <EarlyReturnConvention>(); x.HostWith <Katana>(); }); _server = registry.ToRuntime(); }
public void register_a_non_default_culture_info() { var registry = new FubuRegistry(); registry.Features.Localization.Enable(true); registry.Features.Localization.Configure(x => { x.DefaultCulture = new CultureInfo("en-CA"); }); using (var runtime = registry.ToRuntime()) { runtime.Get <CultureInfo>().Name.ShouldBe("en-CA"); } }
public void can_set_the_node_name_programmatically() { var registry = new FubuRegistry { NodeName = "MyNode" }; using (var fubuRuntime = registry.ToRuntime()) { fubuRuntime.Get <ChannelGraph>().Name.ShouldBe("MyNode"); } }
private void withTraceLevel(TraceLevel level, Action <IContainer> action) { var registry = new FubuRegistry(); registry.Features.Diagnostics.Enable(level); using (var runtime = registry.ToRuntime()) { var container = runtime.Get <IContainer>(); action(container); } }
public void AuthenticationSetup() { var registry = new FubuRegistry(); configure(registry); registry.Features.Authentication.Enable(true); server = registry.ToRuntime(); theContainer = server.Get <IContainer>(); beforeEach(); }
private void registeredTypeIs <TService, TImplementation>() { var registry = new FubuRegistry(); registry.Import <NavigationRegistryExtension>(); using (var runtime = registry.ToRuntime()) { var container = runtime.Get <IContainer>(); container.Model.For <TService>().Default.ReturnedType.ShouldBe(typeof(TImplementation)); } }
public void can_happily_plug_in_an_alternative_route_policy() { FakeRoutePolicy.IWasCalled = false; var registry = new FubuRegistry(); registry.RoutePolicy <FakeRoutePolicy>(); using (var runtime = registry.ToRuntime()) { } FakeRoutePolicy.IWasCalled.ShouldBeTrue(); }
public void should_start_when_transport_disabled() { var registry = new FubuRegistry(); registry.AlterSettings <TransportSettings>(x => { x.Enabled = true; x.InMemoryTransport = InMemoryTransportMode.Enabled; }); registry.AlterSettings <LightningQueueSettings>(x => x.DisableIfNoChannels = true); using (var application = registry.ToRuntime()) { } }
public void find_files_for_public_folder_only() { var registry = new FubuRegistry(); registry.AlterSettings <AssetSettings>(x => { x.Mode = SearchMode.PublicFolderOnly; }); using (var runtime = registry.ToRuntime()) { var graph = runtime.Get <IAssetFinder>().FindAll(); graph.Assets.OrderBy(x => x.Url).Select(x => x.Url) .ShouldHaveTheSameElementsAs("public/1.0.1/d.js", "public/1.0.1/e.js", "public/1.0.1/f.js", "public/javascript/a.js", "public/javascript/b.js", "public/javascript/c.js"); } }
public void the_order_of_the_configuration_action_was_wrong() { var registry = new FubuRegistry(); registry.Actions.IncludeType <TestEndpoint>(); registry.Features.AntiForgery.Enable(true); using (var runtime = registry.ToRuntime()) { var graph = runtime.Get <BehaviorGraph>(); graph.ChainFor <TestEndpoint>(x => x.post_csrf(null)) .OfType <AntiForgeryNode>().Any() .ShouldBeTrue(); } }
public void end_to_end() { var registry = new FubuRegistry(); registry.Features.ServerSentEvents.Enable(true); using (var runtime = registry.ToRuntime()) { var chain = runtime.Behaviors.ChainFor <ChannelWriter <FakeTopic> >(x => x.Write(null)); var container = runtime.Get <IContainer>(); container.GetInstance <IChannelInitializer <FakeTopic> >() .ShouldBeOfType <DefaultChannelInitializer <FakeTopic> >(); container.GetInstance <IActionBehavior>(chain.UniqueId.ToString()); } }
public void do_not_blow_up() { var registry = new FubuRegistry(); registry.ServiceBus.Enable(true); registry.ServiceBus.EnableInMemoryTransport(); registry.Services.For <LightningQueueSettings>().Use(new LightningQueueSettings { DisableIfNoChannels = true }); using (var runtime = registry.ToRuntime()) { // just looking for the absence of an exception here } }
public void does_blow_up_if_not_opted_into_the_disable_behavior() { var registry = new FubuRegistry(); registry.ServiceBus.Enable(true); registry.Services.For <LightningQueueSettings>().Use(new LightningQueueSettings { DisableIfNoChannels = false }); Exception <FubuException> .ShouldBeThrownBy(() => { using (var runtime = registry.ToRuntime()) { } }); }
private AuthorizationPreviewService withAuthorizationRules(Action <BehaviorGraph> configure) { var registry = new FubuRegistry(); registry.Actions.IncludeType <OneController>(); registry.Actions.IncludeType <TwoController>(); registry.Configure(configure); _runtime = registry.ToRuntime(); return(_runtime.Get <AuthorizationPreviewService>()); }
public void register_services() { var registry = new FubuRegistry(); registry.Features.ServerSentEvents.Enable(true); using (var runtime = registry.ToRuntime()) { var container = runtime.Get <IContainer>(); container.DefaultRegistrationIs <IEventPublisher, EventPublisher>(); container.DefaultRegistrationIs <IServerEventWriter, ServerEventWriter>(); container.DefaultRegistrationIs(typeof(IEventQueueFactory <>), typeof(DefaultEventQueueFactory <>)); container.DefaultSingletonIs <ITopicChannelCache, TopicChannelCache>(); } }
public void custom_auth_handler() { var registry = new FubuRegistry(); registry.Services.ReplaceService <IAuthorizationFailureHandler, CustomAuthHandler>(); AuthorizationCheck.IsAuthorized = false; using (var server = registry.ToRuntime()) { server.Scenario(_ => { _.Get.Action <AuthorizedEndpoint>(x => x.get_authorized_text()); _.StatusCodeShouldBe(HttpStatusCode.Redirect); _.Header(HttpResponseHeaders.Location).SingleValueShouldEqual("/403"); }); } }
public void should_place_composite_error_handler() { var registry = new FubuRegistry(); registry.ServiceBus.Enable(true); registry.Handlers.Include <MyConsumer>(); registry.ServiceBus.EnableInMemoryTransport(); registry.Policies.Global.Add <RespondThenMoveToErrorsPolicy>(); using (var runtime = registry.ToRuntime()) { runtime.Behaviors.Handlers.Each(x => { x.ErrorHandlers.Count.ShouldBe(1); }); } }
public void can_register_custom_binding_services() { var registry = new FubuRegistry(); registry.Models .BindModelsWith <ExampleModelBinder>() .BindPropertiesWith <ExamplePropertyBinder>() .ConvertUsing <ExampleConverter>(); using (var runtime = registry.ToRuntime()) { var container = runtime.Get <IContainer>(); container.ShouldHaveRegistration <IConverterFamily, ExampleConverter>(); container.ShouldHaveRegistration <IPropertyBinder, ExamplePropertyBinder>(); container.ShouldHaveRegistration <IModelBinder, ExampleModelBinder>(); } }
public void SetUp() { registry = new FubuRegistry(); container = new Lazy <IContainer>(() => { var c = new Container(x => { x.For <ISettingsProvider>().Use <SettingsProvider>(); x.For <ISettingsSource>().Add <FakeSettingsData>(); x.For <ISettingsSource>().Add(new AppSettingsSettingSource(SettingCategory.core)); }); registry.StructureMap(c); registry.ToRuntime(); return(c); }); }