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, string>>(); log.Steps.Any().ShouldBeTrue(); log.Steps.Any(x => x.Log is StringMessage).ShouldBeTrue(); log.Steps.Each(x => Debug.WriteLine(x)); } }
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 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 can_set_the_node_name_programmatically() { var registry = new FubuRegistry {NodeName = "MyNode"}; using (var fubuRuntime = registry.ToRuntime()) { fubuRuntime.Get<ChannelGraph>().Name.ShouldBe("MyNode"); } }
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 SetUp() { var registry = new FubuRegistry(x => { x.Actions.IncludeType<AsyncAction>(); x.Policies.Local.Add<EarlyReturnConvention>(); x.HostWith<Katana>(); }); _server = registry.ToRuntime(); }
public void AuthenticationSetup() { var registry = new FubuRegistry(); configure(registry); registry.Features.Authentication.Enable(true); server = registry.ToRuntime(); theContainer = server.Get<IContainer>(); beforeEach(); }
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 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 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 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 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 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 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 adds_the_authentication_node_if_it_exists() { var registry = new FubuRegistry(); registry.Actions.IncludeType<AuthenticatedEndpoint>(); registry.Configure( graph => { graph.Chains.OfType<RoutedChain>().Each(x => x.Authentication = new AuthNode()); }); using (var runtime = registry.ToRuntime()) { runtime.Behaviors.ChainFor<AuthenticatedEndpoint>(x => x.get_hello()) .First().ShouldBeOfType<AuthNode>(); } var chain = new RoutedChain("something"); var auth = new AuthNode(); chain.Authentication = auth; }
public void service_registrations() { var registry = new FubuRegistry(); registry.Features.Localization.Enable(true); using (var runtime = registry.ToRuntime()) { var container = runtime.Get<IContainer>(); container.GetInstance<CultureInfo>().Name.ShouldBe("en-US"); container.DefaultRegistrationIs<ICurrentCultureContext, CurrentCultureContext>(); container.DefaultRegistrationIs<ILocalizationMissingHandler, LocalizationMissingHandler>(); container.DefaultRegistrationIs<ILocalizationProviderFactory, LocalizationProviderFactory>(); container.DefaultSingletonIs<ILocalizationCache, LocalizationCache>(); container.ShouldHaveRegistration<IActivator, SpinUpLocalizationCaches>(); } }
public void public_folder_only() { var registry = new FubuRegistry(); registry.AlterSettings<AssetSettings>(x => { x.Mode = SearchMode.PublicFolderOnly; x.Version = null; }); using (var runtime = registry.ToRuntime()) { runtime.Scenario(_ => { _.Get.Action<PublicAssetFolderEndpoint>(x => x.get_public_asset_folder()); _.ContentShouldContain("*/public*"); }); } }
public void all_explicitly_changed_settings_should_get_registered_as_a_service() { var registry = new FubuRegistry(); var oneSettings = new OneSettings(); registry.ReplaceSettings(oneSettings); var twoSettings = new TwoSettings(); registry.ReplaceSettings(twoSettings); var threeSettings = new ThreeSettings(); registry.ReplaceSettings(threeSettings); using (var runtime = registry.ToRuntime()) { var container = runtime.Get<IContainer>(); container.DefaultRegistrationIs(oneSettings); container.DefaultRegistrationIs(twoSettings); container.DefaultRegistrationIs(threeSettings); } }
public void SetUp() { registry = new FubuRegistry(x => { x.Actions.IncludeType<TestController>(); }); container = new Container(x => { x.For<ICurrentChain>().Use(new CurrentChain(null, null)); x.For<IHttpRequest>().Use(OwinHttpRequest.ForTesting()); }); registry.StructureMap(container); registry.RootPath = AppDomain.CurrentDomain.BaseDirectory; fubuRuntime = registry.ToRuntime(); routes = fubuRuntime .Routes .Where(r => !r.As<Route>().Url.StartsWith("_content")) .ToList(); container.Configure(x => x.For<IOutputWriter>().Use(new InMemoryOutputWriter())); }
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 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 services_are_registered() { var registry = new FubuRegistry(); registry.Features.Authentication.Enable(true); using (var runtime = registry.ToRuntime()) { var container = runtime.Get<IContainer>(); container.DefaultRegistrationIs<ILockedOutRule, LockedOutRule>(); container.DefaultRegistrationIs<IAuthenticationService, AuthenticationService>(); container.ShouldHaveRegistration<IActivator, AuthenticationIsConfigured>(); container.DefaultRegistrationIs<IAuthenticationSession, TicketAuthenticationSession>(); container.DefaultRegistrationIs<IPrincipalContext, ThreadPrincipalContext>(); container.DefaultRegistrationIs<ITicketSource, CookieTicketSource>(); container.DefaultRegistrationIs<ILoginCookieService, LoginCookieService>(); container.DefaultRegistrationIs<IEncryptor, Encryptor>(); container.DefaultRegistrationIs<ILoginCookies, BasicFubuLoginCookies>(); container.DefaultRegistrationIs<IAuthenticationRedirector, AuthenticationRedirector>(); container.DefaultRegistrationIs<ILoginAuditor, NulloLoginAuditor>(); } }
public void see_tracing_logs_in_production_mode_happy_path() { 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()); 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 StringMessage).ShouldBeFalse(); } }
public void service_registrations() { var registry = new FubuRegistry(); registry.Actions.IncludeType<NothingEndpoint>(); // Have to do this to make it an isolated test registry.Features.Authentication.Enable(true); using (var runtime = registry.ToRuntime()) { var container = runtime.Get<IContainer>(); var theGraphWithBasicAuthentication = runtime.Behaviors; // This login endpoint was added theGraphWithBasicAuthentication.Chains.Where(x => x.InputType() == typeof(LoginRequest)) .Count().ShouldBe(2); // The logout endpoint was added theGraphWithBasicAuthentication.ChainFor(typeof(LogoutRequest)).ShouldNotBeNull(); container.DefaultRegistrationIs<ILoginSuccessHandler, LoginSuccessHandler>(); container.DefaultRegistrationIs<ILogoutSuccessHandler, LogoutSuccessHandler>(); } }
public void SetUp() { registry = new NavigationRegistry(); _graph = new Lazy<NavigationGraph>(() => { NavigationGraph graph = null; var r = new FubuRegistry(); r.Actions.IncludeType<Controller1>(); r.Policies.Global.Add(registry); r.Import<NavigationRegistryExtension>(); using (var runtime = r.ToRuntime()) { runtime.Get<IMenuResolver>().MenuFor(new NavigationKey("Root")); graph = runtime.Get<NavigationGraph>(); } return graph; }); }
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); } }
private FubuRuntime serverFor(Action<OwinSettings> action) { var registry = new FubuRegistry(); registry.AlterSettings(action); registry.HostWith<Katana>(); return 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 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>(); } }