public void Should_find_usages_of_class() { const string editorText = @"public class myclass { public void method() { } public void method_calling_method() { method(); } } "; var solution = new FakeSolution(); var project = new FakeProject(); project.AddFile(editorText); solution.Projects.Add(project); var bootstrapper = new ConfigurableBootstrapper(c => c.Dependency<ISolution>(solution)); var browser = new Browser(bootstrapper); var result = browser.Post("/findusages", with => { with.HttpRequest(); with.FormValue("FileName", "myfile"); with.FormValue("Line", "3"); with.FormValue("Column", "21"); with.FormValue("Buffer", editorText); }); var usages = result.Body.DeserializeJson<FindUsagesResponse>().Usages.ToArray(); usages.Count().ShouldEqual(2); usages[0].Text.Trim().ShouldEqual("public void method() { }"); usages[1].Text.Trim().ShouldEqual("method();"); }
public void GET_Given_An_Url_Shortened_Should_Return_Data_Of_The_Url() { //Arrange var url = new Model.Url("http://www.2dsolucoes.net"); var repository = new StubUrlStorage(url); var bootstrapper = new ConfigurableBootstrapper(with => { with.Dependency<IUrlStorage>(repository); }); var browser = new Browser(bootstrapper); //Act var urlAPI = string.Format("/urls/{0}", url.Short); var response = browser.Get(urlAPI, ctx => { ctx.HttpRequest(); }); dynamic result = response.Body.ToDynamic(); //Assert Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); Assert.That((string)result.Source, Is.EqualTo(url.Source)); Assert.That((string)result.Short, Is.EqualTo(url.Short)); }
public SerializerTests() { this.bootstrapper = new ConfigurableBootstrapper( configuration => configuration.Modules(new Type[] { typeof(SerializerTestModule) })); this.browser = new Browser(bootstrapper); }
public BrowserFixture() { var bootstrapper = new ConfigurableBootstrapper(); this.browser = new Browser(bootstrapper); }
public void SetUp() { _fakeShortener = new FakeShortener(); _bootstrapper = new ConfigurableBootstrapper(with => with.Dependency(_fakeShortener)); _browser = new Browser(_bootstrapper); }
public void Should_fail_to_resolve_route_because_it_does_have_an_invalid_condition() { // Given var cache = new FakeRouteCache(with => { with.AddGetRoute("/invalidcondition", "modulekey", ctx => false); }); var bootstrapper = new ConfigurableBootstrapper(with =>{ with.RouteCache(cache); }); var browser = new Browser(bootstrapper); // When var timer = new Stopwatch(); timer.Start(); for (var i = 0; i < numberOfTimesToResolveRoute; i++) { var result = browser.Get("/invalidcondition"); result.StatusCode.ShouldEqual(HttpStatusCode.NotFound); } timer.Stop(); // Then Debug.WriteLine(" took {0} to execute {1} times", timer.Elapsed, numberOfTimesToResolveRoute); }
public async Task Should_return_info_page_if_password_empty() { // Given var bootstrapper = new ConfigurableBootstrapper(with => { with.Configure(env => { env.Diagnostics( enabled: true, password: string.Empty, cryptographyConfiguration: this.cryptoConfig); }); with.EnableAutoRegistration(); with.Diagnostics<DefaultDiagnostics>(); }); var browser = new Browser(bootstrapper); // When var result = await browser.Get(DiagnosticsConfiguration.Default.Path); // Then Assert.True(result.Body.AsString().Contains("Diagnostics Disabled")); }
public void Should_return_main_page_with_valid_auth_cookie() { // Given var bootstrapper = new ConfigurableBootstrapper(with => { with.Configure(env => { env.Diagnostics( password: "******", cryptographyConfiguration: this.cryptoConfig); }); with.EnableAutoRegistration(); with.Diagnostics<FakeDiagnostics>(); }); var browser = new Browser(bootstrapper); // When var result = browser.Get(DiagnosticsConfiguration.Default.Path + "/interactive/providers/", with => { with.Cookie(DiagsCookieName, this.GetSessionCookieValue("password")); }); // Then should see our fake provider and not the default testing provider result.Body.AsString().ShouldContain("Fake testing provider"); result.Body.AsString().ShouldNotContain("Testing Diagnostic Provider"); }
public AbsoluteUrlTests() { this.bootstrapper = new ConfigurableBootstrapper( configuration => configuration.Modules(new Type[] { typeof(AbsoluteUrlTestModule) })); this.browser = new Browser(bootstrapper); }
public void FixtureSetup() { var formsAuthenticationConfiguration = new FormsAuthenticationConfiguration() { RedirectUrl = "~/login", UserMapper = new FakeUserMapper(new UserService()) }; var configuration = A.Fake<IRazorConfiguration>(); var bootstrapper = new ConfigurableBootstrapper(config => { config.Module<UsersModule>(); config.Module<LoginModule>(); config.ViewEngine(new RazorViewEngine(configuration)); }); var bootstrapper2 = new ConfigurableBootstrapper(config => { config.Module<UsersModule>(); config.Module<LoginModule>(); config.ViewEngine(new RazorViewEngine(configuration)); config.RequestStartup((x, pipelines, z) => FormsAuthentication.Enable(pipelines, formsAuthenticationConfiguration)); }); _notLoggedInBrowser = new Browser(bootstrapper); _loggedInBrowserResponse = new Browser(bootstrapper2).Post("/login", x => { x.HttpRequest(); x.FormValue("Username", "Chris1"); x.FormValue("Password", "123"); }); }
public void SetUpBase() { this.ContentRepository = MockRepository.GenerateMock<IContentRepository>(); this.ComponentLibrary = MockRepository.GenerateMock<IComponentSpecificationLibrary>(); this.KolaConfigurationRegistry = MockRepository.GenerateMock<IKolaConfigurationRegistry>(); this.DynamicSourceProvider = MockRepository.GenerateMock<IDynamicSourceProvider>(); var bootstrapper = new ConfigurableBootstrapper( with => { with.Dependency(this.ContentRepository); with.Dependency(this.ComponentLibrary); with.Dependency(this.KolaConfigurationRegistry); with.Dependency(this.DynamicSourceProvider); with.Dependency<TemplateResourceBuilder>(); with.Dependency<AmendmentDetailsResourceBuilder>(); with.Dependency<PathInstanceBuilder>(); with.Dependency<AmendmentsDetailsResourceBuilder>(); with.Dependency<UndoAmendmentDetailsResourceBuilder>(); with.Dependency<ComponentDetailsResourceBuilder>(); with.ResponseProcessor<TemplateJsonResultProcessor>(); with.ResponseProcessor<AmendmentDetailsJsonResultProcessor>(); with.ResponseProcessor<AmendmentsDetailsJsonResultProcessor>(); with.ResponseProcessor<UndoAmendmentDetailsJsonResultProcessor>(); with.ResponseProcessor<ComponentDetailsJsonResultProcessor>(); with.Dependency<TemplateService>(); with.Module<TemplateModule>(); }); this.Browser = new Browser(bootstrapper); }
public When_enabling_sessions() { _Bootstrapper = new ConfigurableBootstrapper(with => { with.DisableAutoRegistration(); }); KeyValueStoreSessions.Enable(_Bootstrapper, A.Fake<IKeyValueStore>()); }
public CaseSensitivityFixture() { var bootstrapper = new ConfigurableBootstrapper(with => { with.Module<MainModule>(); }); this.browser = new Browser(bootstrapper); }
public void Nsub_WithBootstrapper_GetCalled() { this.task.GetValue().Returns("i did not fail"); var bs = new ConfigurableBootstrapper( with => { with.Dependency(this.task).Module<IndexModule>(); }); var browser = new Browser(bs); var actual = browser.Get("/"); Assert.That(actual.Body.AsString(), Is.EqualTo("i did not fail")); }
public BrowserFixture() { var bootstrapper = new ConfigurableBootstrapper(config => config.Modules(typeof(EchoModule))); CookieBasedSessions.Enable(bootstrapper); this.browser = new Browser(bootstrapper); }
public PartialRenderingFixture() { var bootstrapper = new ConfigurableBootstrapper(with => { with.Module<PartialRenderingModule>(); }); this.browser = new Browser(bootstrapper); }
public static Browser CreateBrowserWithCancellationToken(RouteRegistrar registrar, CancellationToken cancel) { var bootstrapper = new ConfigurableBootstrapper(with => with .Module(new AsyncCancelModule(registrar)) .NancyEngine<NancyEngineWithAsyncCancellation>()); var browser = new Browser(bootstrapper); ((NancyEngineWithAsyncCancellation) bootstrapper.GetEngine()).CancellationToken = cancel; return browser; }
public SerializerTests() { this.bootstrapper = new ConfigurableBootstrapper( configuration => { configuration.Modules(new Type[] { typeof(SerializerTestModule) }); }); this.browser = new Browser(bootstrapper); }
public void Should_return_info_page_if_password_null() { var diagsConfig = new DiagnosticsConfiguration { Password = null, CryptographyConfiguration = this.cryptoConfig }; var bootstrapper = new ConfigurableBootstrapper(b => b.DiagnosticsConfiguration(diagsConfig)); var browser = new Browser(bootstrapper); var result = browser.Get("/_Nancy"); Assert.True(result.Body.AsString().Contains("Diagnostics Disabled")); }
public IdeaStrikeSpecBase() { Bootstrapper = new ConfigurableBootstrapper(with => { with.Module <TModule>(); with.Dependencies(_Users.Object, _Ideas.Object, _Features.Object, _Activity.Object, _Settings.Object, _Images.Object); with.DisableAutoRegistration(); with.NancyEngine <NancyEngine>(); }); }
public PartialRenderingFixture() { var bootstrapper = new ConfigurableBootstrapper(with => { with.Module <PartialRenderingModule>(); with.RootPathProvider <RootPathProvider>(); }); this.browser = new Browser(bootstrapper); }
public void FixtureSetup() { var configuration = A.Fake<IRazorConfiguration>(); var bootstrapper = new ConfigurableBootstrapper(config => { config.Module<TreesModule>(); config.ViewEngine(new RazorViewEngine(configuration)); }); _browser = new Browser(bootstrapper); }
public void LoginWithUsernameAndPasswordUnSuccessfully() { var expectedSettings = new AuthenticationSettings { UserAuthentication = true, UsePassword = true, PlexAuthToken = "abc" }; var plexFriends = new PlexFriends { User = new[] { new UserFriends { Username = "******", }, } }; var plexAuth = new PlexAuthentication { user = null }; AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings); PlexMock.Setup(x => x.GetUsers(It.IsAny <string>())).Returns(plexFriends); PlexMock.Setup(x => x.SignIn(It.IsAny <string>(), It.IsAny <string>())).Returns(plexAuth); var bootstrapper = new ConfigurableBootstrapper(with => { with.Module <UserLoginModule>(); with.Dependency(AuthMock.Object); with.Dependency(PlexMock.Object); with.RootPathProvider <TestRootPathProvider>(); }); bootstrapper.WithSession(new Dictionary <string, object>()); var browser = new Browser(bootstrapper); var result = browser.Post("/userlogin", with => { with.HttpRequest(); with.Header("Accept", "application/json"); with.FormValue("Username", "abc"); with.FormValue("Password", "abc"); }); Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode)); Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null); var body = JsonConvert.DeserializeObject <JsonResponseModel>(result.Body.AsString()); Assert.That(body.Result, Is.EqualTo(false)); Assert.That(body.Message, Is.Not.Empty); AuthMock.Verify(x => x.GetSettings(), Times.Once); PlexMock.Verify(x => x.SignIn(It.IsAny <string>(), It.IsAny <string>()), Times.Once); PlexMock.Verify(x => x.GetUsers(It.IsAny <string>()), Times.Never); }
public void PrepareTestBrowser() { _weightsService = new Mock <IWeightsService>(MockBehavior.Strict); var bootstrapper = new ConfigurableBootstrapper(with => { with.Module <WeightsModule>(); with.Dependencies(_weightsService.Object); }); _browser = new Browser(bootstrapper); }
public void When_host_nancy_via_IAppBuilder_then_should_handle_requests() { var bootstrapper = new ConfigurableBootstrapper(config => config.Module <TestModule>()); using (var server = TestServer.Create(app => app.UseNancy(opts => opts.Bootstrapper = bootstrapper))) { var response = server.CreateRequest("/").GetAsync().Result; Assert.Equal(response.StatusCode, System.Net.HttpStatusCode.OK); } }
public When_saving_a_session() { var boot = new ConfigurableBootstrapper(with => { with.DisableAutoRegistration(); with.Module<SessionTestModule>(); }); _Store = A.Fake<IKeyValueStore>(); KeyValueStoreSessions.Enable(boot, _Store); _Browser = new Browser(boot); }
public When_no_session_is_present() { var boot = new ConfigurableBootstrapper(with => { with.DisableAutoRegistration(); with.Module<SessionTestModule>(); }); KeyValueStoreSessions.Enable(boot, A.Fake<IKeyValueStore>()); var browser = new Browser(boot); _Response = browser.Get("/TestVariable"); }
public void SetUp() { var bootStrapper = new ConfigurableBootstrapper(with => { with.Dependency <IUserRepository>(userRepository = Substitute.For <IUserRepository>()); with.Dependency <IEmailService>(emailService = Substitute.For <IEmailService>()); with.Module <RootModule>(); }); browser = new Browser(bootStrapper); }
public static Browser CreateBrowserWithCancellationToken(RouteRegistrar registrar, CancellationToken cancel) { var bootstrapper = new ConfigurableBootstrapper(with => with .Module(new AsyncCancelModule(registrar)) .NancyEngine <NancyEngineWithAsyncCancellation>()); var browser = new Browser(bootstrapper); ((NancyEngineWithAsyncCancellation)bootstrapper.GetEngine()).CancellationToken = cancel; return(browser); }
public void When_host_nancy_via_IAppBuilder_then_should_handle_requests() { var bootstrapper = new ConfigurableBootstrapper(config => config.Module<TestModule>()); using(var server = TestServer.Create(app => app.UseNancy(opts => opts.Bootstrapper = bootstrapper))) { var response = server.CreateRequest("/").GetAsync().Result; Assert.Equal(response.StatusCode, System.Net.HttpStatusCode.OK); } }
public void EstablishContext() { this.BuildPlanFacadeService = Substitute.For <IFacadeService <BuildPlan, string, BuildPlanResource, BuildPlanResource> >(); this.BuildPlansReportFacadeService = Substitute.For <IBuildPlansReportFacadeService>(); this.BuildPlanRulesFacadeService = Substitute.For <IBuildPlanRulesFacadeService>(); this.BuildPlanDetailsFacadeService = Substitute .For <IFacadeService <BuildPlanDetail, BuildPlanDetailKey, BuildPlanDetailResource, BuildPlanDetailResource> >(); this.AuthorisationService = Substitute.For <IAuthorisationService>(); var bootstrapper = new ConfigurableBootstrapper( with => { with.Dependency(this.BuildPlanFacadeService); with.Dependency(this.BuildPlansReportFacadeService); with.Dependency(this.BuildPlanRulesFacadeService); with.Dependency(this.BuildPlanDetailsFacadeService); with.Dependency <IResourceBuilder <ResponseModel <BuildPlan> > >( new BuildPlanResourceBuilder(this.AuthorisationService)); with.Dependency <IResourceBuilder <ResponseModel <IEnumerable <BuildPlan> > > >( new BuildPlansResourceBuilder(this.AuthorisationService)); with.Dependency <IResourceBuilder <ResponseModel <BuildPlanRule> > >( new BuildPlanRuleResourceBuilder(this.AuthorisationService)); with.Dependency <IResourceBuilder <ResponseModel <IEnumerable <BuildPlanRule> > > >( new BuildPlanRulesResourceBuilder(this.AuthorisationService)); with.Dependency <IResourceBuilder <ResultsModel> >(new ResultsModelResourceBuilder()); with.Dependency <IResourceBuilder <ResponseModel <BuildPlanDetail> > >( new BuildPlanDetailResourceBuilder(this.AuthorisationService)); with.Dependency <IResourceBuilder <ResponseModel <IEnumerable <BuildPlanDetail> > > >( new BuildPlanDetailsResourceBuilder(this.AuthorisationService)); with.Module <BuildPlansModule>(); with.ResponseProcessor <BuildPlanResponseProcessor>(); with.ResponseProcessor <BuildPlansResponseProcessor>(); with.ResponseProcessor <BuildPlanRuleResponseProcessor>(); with.ResponseProcessor <BuildPlanRulesResponseProcessor>(); with.ResponseProcessor <BuildPlanDetailResponseProcessor>(); with.ResponseProcessor <BuildPlanDetailsResponseProcessor>(); with.ResponseProcessor <ResultsModelJsonResponseProcessor>(); with.RequestStartup( (container, pipelines, context) => { var claims = new List <Claim> { new Claim(ClaimTypes.Role, "employee"), new Claim(ClaimTypes.NameIdentifier, "test-user") }; var user = new ClaimsIdentity(claims, "jwt"); context.CurrentUser = new ClaimsPrincipal(user); }); }); this.Browser = new Browser(bootstrapper); }
public NancyModuleRunner(Action<ConfigurableBootstrapper.ConfigurableBoostrapperConfigurator> configuration) { var host = "localhost"; int port = TCPUtil.GetAvailableTCPPort(8081, 8090); BaseUrl = "http://" + host + ":" + port + "/"; var bootStrapper = new ConfigurableBootstrapper(configuration); _nancyHost = new NancyHost(bootStrapper, new Uri(BaseUrl)); _nancyHost.Start(); }
public void Should_use_default_type_when_no_type_or_instance_overrides_have_been_configured() { // Given var bootstrapper = new ConfigurableBootstrapper(); bootstrapper.Initialise(); // When var engine = bootstrapper.GetEngine(); // Then engine.ShouldBeOfType<NancyEngine>(); }
public NancyModuleRunner(Action <ConfigurableBootstrapper.ConfigurableBoostrapperConfigurator> configuration) { var host = "localhost"; int port = TCPUtil.GetAvailableTCPPort(8081, 8090); BaseUrl = "http://" + host + ":" + port + "/"; var bootStrapper = new ConfigurableBootstrapper(configuration); _nancyHost = new NancyHost(bootStrapper, new Uri(BaseUrl)); _nancyHost.Start(); }
public When_loading_a_session() { var boot = new ConfigurableBootstrapper(with => { with.DisableAutoRegistration(); with.Module<SessionTestModule>(); }); _Store = A.Fake<IKeyValueStore>(); A.CallTo(() => _Store.Load<IDictionary<string, object>>("12345")).Returns(new Dictionary<string, object> { { "TestVariable", "TestValue" } }); KeyValueStoreSessions.Enable(boot, _Store); _Browser = new Browser(boot); }
public async Task Should_pass_default_headers_in_get_request_when_using_inancybootstrapper_ctor() { // Given var bootstrapper = new ConfigurableBootstrapper(with => with.Module(this.captureRequestModule)); var sut = new Browser(bootstrapper, defaults: to => to.Accept(this.expected)); // When await sut.Get("/"); // Then this.captureRequestModule.CapturedRequest.Headers.Accept.First().Item1.ShouldEqual(this.expected); }
public void root_should_return_response_ok() { var bootstrapper = new ConfigurableBootstrapper(with => { with.Module<RootModule>(); }); var browser = new Browser(bootstrapper); var response = browser.Get("/"); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); }
public void EstablishContext() { this.ConsignmentFacadeService = Substitute.For <IFacadeService <Consignment, int, ConsignmentResource, ConsignmentUpdateResource> >(); this.HubFacadeService = Substitute.For <IFacadeService <Hub, int, HubResource, HubResource> >(); this.CarrierFacadeService = Substitute.For <IFacadeService <Carrier, string, CarrierResource, CarrierResource> >(); this.CartonTypeFacadeService = Substitute.For <IFacadeService <CartonType, string, CartonTypeResource, CartonTypeResource> >(); this.ShippingTermFacadeService = Substitute.For <IFacadeService <ShippingTerm, int, ShippingTermResource, ShippingTermResource> >(); var bootstrapper = new ConfigurableBootstrapper( with => { with.Dependency(this.ConsignmentFacadeService); with.Dependency(this.HubFacadeService); with.Dependency(this.CarrierFacadeService); with.Dependency(this.CartonTypeFacadeService); with.Dependency(this.ShippingTermFacadeService); with.Dependency <IResourceBuilder <Consignment> >(new ConsignmentResourceBuilder()); with.Dependency <IResourceBuilder <IEnumerable <Consignment> > >(new ConsignmentsResourceBuilder()); with.Dependency <IResourceBuilder <Hub> >(new HubResourceBuilder()); with.Dependency <IResourceBuilder <IEnumerable <Hub> > >(new HubsResourceBuilder()); with.Dependency <IResourceBuilder <ShippingTerm> >(new ShippingTermResourceBuilder()); with.Dependency <IResourceBuilder <IEnumerable <ShippingTerm> > >(new ShippingTermsResourceBuilder()); with.Dependency <IResourceBuilder <Carrier> >(new CarrierResourceBuilder()); with.Dependency <IResourceBuilder <IEnumerable <Carrier> > >(new CarriersResourceBuilder()); with.Dependency <IResourceBuilder <CartonType> >(new CartonTypeResourceBuilder()); with.Dependency <IResourceBuilder <IEnumerable <CartonType> > >(new CartonTypesResourceBuilder()); with.Module <ConsignmentsModule>(); with.ResponseProcessor <ConsignmentResponseProcessor>(); with.ResponseProcessor <ConsignmentsResponseProcessor>(); with.ResponseProcessor <HubResponseProcessor>(); with.ResponseProcessor <HubsResponseProcessor>(); with.ResponseProcessor <CarrierResponseProcessor>(); with.ResponseProcessor <CarriersResponseProcessor>(); with.ResponseProcessor <CartonTypeResponseProcessor>(); with.ResponseProcessor <CartonTypesResponseProcessor>(); with.ResponseProcessor <ShippingTermResponseProcessor>(); with.ResponseProcessor <ShippingTermsResponseProcessor>(); with.RequestStartup( (container, pipelines, context) => { var claims = new List <Claim> { new Claim(ClaimTypes.Role, "employee"), new Claim(ClaimTypes.NameIdentifier, "test-user") }; var user = new ClaimsIdentity(claims, "jwt"); context.CurrentUser = new ClaimsPrincipal(user); }); }); this.Browser = new Browser(bootstrapper); }
public void Should_return_login_page_with_no_auth_cookie() { var diagsConfig = new DiagnosticsConfiguration { Password = "******", CryptographyConfiguration = this.cryptoConfig }; var bootstrapper = new ConfigurableBootstrapper(b => b.DiagnosticsConfiguration(diagsConfig)); var browser = new Browser(bootstrapper); var result = browser.Get("/_Nancy"); result.Body["#login"].ShouldExistOnce(); }
public void Should_return_info_page_if_password_empty() { var diagsConfig = new DiagnosticsConfiguration { Password = string.Empty, CryptographyConfiguration = this.cryptoConfig }; var bootstrapper = new ConfigurableBootstrapper(b => b.DiagnosticsConfiguration(diagsConfig)); var browser = new Browser(bootstrapper); var result = browser.Get("/_Nancy"); Assert.True(result.Body.AsString().Contains("Diagnostics Disabled")); }
public async Task When_host_Nancy_via_IAppBuilder_should_read_X509Certificate2() { // Given var app = new AppBuilder(); var bootstrapper = new ConfigurableBootstrapper(config => config.Module<TestModule>()); var cert = @"-----BEGIN CERTIFICATE----- MIICNTCCAZ4CCQC21XwOAYG32zANBgkqhkiG9w0BAQUFADBfMQswCQYDVQQGEwJH QjETMBEGA1UECBMKU29tZS1TdGF0ZTEOMAwGA1UEChMFTmFuY3kxDjAMBgNVBAsT BU5hbmN5MRswGQYDVQQDExJodHRwOi8vbmFuY3lmeC5vcmcwHhcNMTYwMjIyMTE1 NzQ3WhcNMTcwMjIxMTE1NzQ3WjBfMQswCQYDVQQGEwJHQjETMBEGA1UECBMKU29t ZS1TdGF0ZTEOMAwGA1UEChMFTmFuY3kxDjAMBgNVBAsTBU5hbmN5MRswGQYDVQQD ExJodHRwOi8vbmFuY3lmeC5vcmcwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB AMT4vOtIH9Fzad+8KCGjMPkkVpCtn+L5H97bnI3x+y3x5lY0WRsK8FyxVshY/7fv TDeeVKUWanmbMkQjgFRYffA3ep3/AIguswYdANiNVHrx0L7DXNDcgsjRwaa6JVgQ 9iavlli0a80AF67FN1wfidlHCX53u3/fAjiSTwf7D+NBAgMBAAEwDQYJKoZIhvcN AQEFBQADgYEAh12A4NntHHdVMGaw+2umXkWqCOyAPuNhyBGUHK5vGON+VG0HPFaf 8P8eMtdF4deBHkrfoWxRuGGn2tJzNpZLiEf23BAivEf36IqwfkVP7/zDwI+bjVXC k64Un2uN8ALR/wLwfJzHfOLPtsca7ySWhlv8oZo2nk0vR34asQiGJDQ= -----END CERTIFICATE----- "; var embeddedCert = Encoding.UTF8.GetBytes(cert); app.Use(new Func<AppFunc, AppFunc>(next => (async env => { env.Add("ssl.ClientCertificate", new X509Certificate(embeddedCert)); await next.Invoke(env); }))); app.UseNancy(opts => { opts.Bootstrapper = bootstrapper; opts.EnableClientCertificates = true; }); var appFunc = app.Build(); var handler = new OwinHttpMessageHandler(appFunc); using (var httpClient = new HttpClient(handler) { BaseAddress = new Uri("http://localhost") }) { // When var response = await httpClient.GetAsync(new Uri("http://localhost/ssl")); // Then Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode); } }
public async Task When_host_Nancy_via_IAppBuilder_should_read_X509Certificate2() { // Given var app = new AppBuilder(); var bootstrapper = new ConfigurableBootstrapper(config => config.Module <TestModule>()); var cert = @"-----BEGIN CERTIFICATE----- MIICNTCCAZ4CCQC21XwOAYG32zANBgkqhkiG9w0BAQUFADBfMQswCQYDVQQGEwJH QjETMBEGA1UECBMKU29tZS1TdGF0ZTEOMAwGA1UEChMFTmFuY3kxDjAMBgNVBAsT BU5hbmN5MRswGQYDVQQDExJodHRwOi8vbmFuY3lmeC5vcmcwHhcNMTYwMjIyMTE1 NzQ3WhcNMTcwMjIxMTE1NzQ3WjBfMQswCQYDVQQGEwJHQjETMBEGA1UECBMKU29t ZS1TdGF0ZTEOMAwGA1UEChMFTmFuY3kxDjAMBgNVBAsTBU5hbmN5MRswGQYDVQQD ExJodHRwOi8vbmFuY3lmeC5vcmcwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB AMT4vOtIH9Fzad+8KCGjMPkkVpCtn+L5H97bnI3x+y3x5lY0WRsK8FyxVshY/7fv TDeeVKUWanmbMkQjgFRYffA3ep3/AIguswYdANiNVHrx0L7DXNDcgsjRwaa6JVgQ 9iavlli0a80AF67FN1wfidlHCX53u3/fAjiSTwf7D+NBAgMBAAEwDQYJKoZIhvcN AQEFBQADgYEAh12A4NntHHdVMGaw+2umXkWqCOyAPuNhyBGUHK5vGON+VG0HPFaf 8P8eMtdF4deBHkrfoWxRuGGn2tJzNpZLiEf23BAivEf36IqwfkVP7/zDwI+bjVXC k64Un2uN8ALR/wLwfJzHfOLPtsca7ySWhlv8oZo2nk0vR34asQiGJDQ= -----END CERTIFICATE----- "; var embeddedCert = Encoding.UTF8.GetBytes(cert); app.Use(new Func <AppFunc, AppFunc>(next => (async env => { env.Add("ssl.ClientCertificate", new X509Certificate(embeddedCert)); await next.Invoke(env); }))); app.UseNancy(opts => { opts.Bootstrapper = bootstrapper; opts.EnableClientCertificates = true; }); var appFunc = app.Build(); var handler = new OwinHttpMessageHandler(appFunc); using (var httpClient = new HttpClient(handler) { BaseAddress = new Uri("http://localhost") }) { // When var response = await httpClient.GetAsync(new Uri("http://localhost/ssl")); // Then Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode); } }
public async Task ServerModule_SearchArtist_Ok() { //Arrange var artistName = "Test"; var fakeHelloServices = Mock.Of <IIndex <string, IHelloService> >(); var fakeArtistSerachResult = new ArtistSearchModel { Artists = new List <Artist> { new Artist { Name = "Artist1", BannerImgUri = "/img1.png" }, new Artist { Name = "Artist2", BannerImgUri = "/img2.png" } } }; var fakeArtistSearchService = Mock.Of <IArtistSearchService>(); Mock.Get(fakeArtistSearchService).Setup(it => it.Serach(It.IsAny <string>())) .Returns(fakeArtistSerachResult); var bootstrapper = new ConfigurableBootstrapper(with => { with.RootPathProvider <TestingRootPathProvider>(); with.ViewFactory <TestingViewFactory>(); var module = new ServerModule(fakeHelloServices, fakeArtistSearchService); with.Module(module); }); var browser = new Browser(bootstrapper, defaults: to => to.Accept("application/json")); //Act var result = await browser.Get($"/searchArtist/{artistName}", with => { with.HttpRequest(); with.Header("accept", "text/html"); }); //Assert result.StatusCode.Should().Be(HttpStatusCode.OK); result.GetViewName().Should().Be("test"); result.GetModel <ArtistSearchModel>().Artists.Any().Should().BeTrue(); result.GetModel <ArtistSearchModel>().Should().Be(fakeArtistSerachResult); Mock.Get(fakeArtistSearchService).Verify(it => it.Serach(It.Is <string>(p => p == artistName)), Times.Once); }
public void EstablishContext() { this.OutstandingWorksOrdersReportFacade = Substitute.For <IOutstandingWorksOrdersReportFacade>(); this.LabelService = Substitute .For <IFacadeService <WorksOrderLabel, WorksOrderLabelKey, WorksOrderLabelResource, WorksOrderLabelResource> >(); this.WorksOrdersService = Substitute.For <IWorksOrdersService>(); this.WorksOrderLabelPack = Substitute.For <IWorksOrderLabelPack>(); var bootstrapper = new ConfigurableBootstrapper( with => { with.Dependency(this.OutstandingWorksOrdersReportFacade); with.Dependency(this.WorksOrdersService); with.Dependency(this.LabelService); with.Dependency(this.WorksOrderLabelPack); with.Dependency <IResourceBuilder <ResultsModel> >(new ResultsModelResourceBuilder()); with.Dependency <IResourceBuilder <WorksOrder> >(new WorksOrderResourceBuilder()); with.Dependency <IResourceBuilder <IEnumerable <WorksOrder> > >( new WorksOrdersResourceBuilder()); with.Dependency <IResourceBuilder <IEnumerable <WorksOrder> > >(new WorksOrdersResourceBuilder()); with.Dependency <IResourceBuilder <WorksOrderPartDetails> >(new WorksOrderPartDetailsResourceBuilder()); with.Dependency <IResourceBuilder <WorksOrderLabel> >(new WorksOrderLabelResourceBuilder()); with.Dependency <IResourceBuilder <IEnumerable <WorksOrderLabel> > >(new WorksOrderLabelsResourceBuilder()); with.Dependency <IResourceBuilder <Error> >(new ErrorResourceBuilder()); with.Module <WorksOrdersModule>(); with.ResponseProcessor <ResultsModelJsonResponseProcessor>(); with.ResponseProcessor <IEnumerableCsvResponseProcessor>(); with.ResponseProcessor <WorksOrderResponseProcessor>(); with.ResponseProcessor <WorksOrdersResponseProcessor>(); with.ResponseProcessor <WorksOrderPartDetailsResponseProcessor>(); with.ResponseProcessor <WorksOrderLabelResponseProcessor>(); with.ResponseProcessor <WorksOrderLabelsResponseProcessor>(); with.ResponseProcessor <ErrorResponseProcessor>(); with.RequestStartup( (container, pipelines, context) => { var claims = new List <Claim> { new Claim(ClaimTypes.Role, "employee"), new Claim(ClaimTypes.NameIdentifier, "test-user") }; var user = new ClaimsIdentity(claims, "jwt"); context.CurrentUser = new ClaimsPrincipal(user); }); }); this.Browser = new Browser(bootstrapper); }
public SwaggerAnnotationsConverterTests() { var bootstrapper = new ConfigurableBootstrapper(with => { with.ApplicationStartup((container, pipelines) => container.Register<ISwaggerMetadataConverter, SwaggerAnnotationsConverter>()); with.Module<SwaggerModule>(); with.Module<TestRoutesModule>(); }); _browser = new Browser(bootstrapper); }
public SwaggerAnnotationsConverterTests() { var bootstrapper = new ConfigurableBootstrapper(with => { with.ApplicationStartup((container, pipelines) => container.Register <ISwaggerMetadataConverter, SwaggerAnnotationsConverter>()); with.Module <SwaggerModule>(); with.Module <TestRoutesModule>(); }); _browser = new Browser(bootstrapper); }
protected override ConfigurableBootstrapper.ConfigurableBootstrapperConfigurator ConfigureBootstrapper( ConfigurableBootstrapper configurableBootstrapper, params Claim[] claims) { return(base.ConfigureBootstrapper(configurableBootstrapper, claims) .Dependency <RoleService>(typeof(RoleService)) .Dependency <PermissionService>(typeof(PermissionService)) .Dependency <ClientService>(typeof(ClientService)) .Dependency(_mockLogger.Object) .Dependency(MockClientStore.Object) .Dependency(MockPermissionStore.Object) .Dependency(MockRoleStore.Object)); }
public void Should_use_default_type_when_no_type_or_instance_overrides_have_been_configured() { // Given var bootstrapper = new ConfigurableBootstrapper(); bootstrapper.Initialise(); // When var engine = bootstrapper.GetEngine(); // Then engine.ShouldBeOfType <NancyEngine>(); }
public void Should_return_login_page_with_auth_cookie_with_incorrect_password() { var diagsConfig = new DiagnosticsConfiguration { Password = "******", CryptographyConfiguration = this.cryptoConfig }; var bootstrapper = new ConfigurableBootstrapper(b => b.DiagnosticsConfiguration(diagsConfig)); var browser = new Browser(bootstrapper); var result = browser.Get("/_Nancy", with => { with.Cookie(DiagsCookieName, this.GetSessionCookieValue("wrongPassword")); }); result.Body["#login"].ShouldExistOnce(); }
public async Task Deve_Retornar_Clientes_Pelo_ID_Com_Sucessp(long id) { // given var bootstrapper = new ConfigurableBootstrapper(with => { with.Dependency <ClientRepositoryFake>(); with.Module <ClientModule>(); }); var browser = new Browser(bootstrapper); BrowserResponse response = await RecuperarCliente(id, browser); Assert.Equal(HttpStatusCode.OK, response.StatusCode); }
public RootModuleTests() { _bootstrapper = new CustomTestBootstrapper(with => { with.Module <RootModule>() .Dependency(_loginHandler.Object) .Dependency(_userEventQueries.Object) .Dependency(_guestLoginHandler.Object) .Dependency(_userLoginHandler.Object) .Dependency(_guestValidator.Object) .Dependency(_userValidator.Object); }); _browser = new Browser(_bootstrapper); }
protected virtual ConfigurableBootstrapper.ConfigurableBootstrapperConfigurator ConfigureBootstrapper( ConfigurableBootstrapper configurableBootstrapper, params Claim[] claims) { var configurableBootstrapperConfigurator = new ConfigurableBootstrapper.ConfigurableBootstrapperConfigurator(configurableBootstrapper); configurableBootstrapperConfigurator.Module <T>(); configurableBootstrapperConfigurator.RequestStartup((container, pipeline, context) => { context.CurrentUser = new TestPrincipal(claims); pipeline.BeforeRequest += ctx => RequestHooks.SetDefaultVersionInUrl(ctx); }); return(configurableBootstrapperConfigurator); }
public void When_host_Nancy_via_IAppBuilder_then_should_handle_requests() { // Given var bootstrapper = new ConfigurableBootstrapper(config => config.Module <TestModule>()); using (var server = TestServer.Create(app => app.UseNancy(opts => opts.Bootstrapper = bootstrapper))) { // When var response = server.HttpClient.GetAsync(new Uri("http://localhost/")).Result; // Then Assert.Equal(response.StatusCode, System.Net.HttpStatusCode.OK); } }
public IdeaStrikeSpecBase() { ViewFactory = new Mock <IViewFactory>(); Bootstrapper = new ConfigurableBootstrapper(with => { with.Module <TModule>(); with.Dependencies(_Users.Object, _Ideas.Object, _Features.Object, _Activity.Object, _Settings.Object, _Images.Object); with.DisableAutoRegistration(); with.NancyEngine <NancyEngine>(); with.ViewFactory(ViewFactory.Object); with.RootPathProvider <CustomRootPathProvider>(); }); }
public void Should_not_accept_invalid_password() { var diagsConfig = new DiagnosticsConfiguration { Password = "******", CryptographyConfiguration = this.cryptoConfig }; var bootstrapper = new ConfigurableBootstrapper(b => b.DiagnosticsConfiguration(diagsConfig)); var browser = new Browser(bootstrapper); var result = browser.Post("/_Nancy", with => { with.FormValue("Password", "wrongpassword"); }); result.Body["#login"].ShouldExistOnce(); result.Cookies.Any(c => c.Name == DiagsCookieName && !string.IsNullOrEmpty(c.Value)).ShouldBeFalse(); }
public void EstablishContext() { this.AteFaultCodeService = Substitute.For <IFacadeService <AteFaultCode, string, AteFaultCodeResource, AteFaultCodeResource> >(); this.AteTestService = Substitute.For <IFacadeService <AteTest, int, AteTestResource, AteTestResource> >(); this.AteTestDetailService = Substitute.For <IFacadeService <AteTestDetail, AteTestDetailKey, AteTestDetailResource, AteTestDetailResource> >(); this.CountComponentsService = Substitute.For <ICountComponentsFacadeService>(); this.AteReportsFacadeService = Substitute.For <IAteReportsFacadeService>(); var bootstrapper = new ConfigurableBootstrapper( with => { with.Dependency(this.AteFaultCodeService); with.Dependency(this.AteTestService); with.Dependency(this.AteTestDetailService); with.Dependency(this.AteReportsFacadeService); with.Dependency(this.CountComponentsService); with.Dependency <IResourceBuilder <ResultsModel> >(new ResultsModelResourceBuilder()); with.Dependency <IResourceBuilder <AteFaultCode> >(new AteFaultCodeResourceBuilder()); with.Dependency <IResourceBuilder <IEnumerable <AteFaultCode> > >( new AteFaultCodesResourceBuilder()); with.Dependency <IResourceBuilder <AteTest> >(new AteTestResourceBuilder()); with.Dependency <IResourceBuilder <ComponentCount> >(new ComponentCountResourceBuilder()); with.Dependency <IResourceBuilder <IEnumerable <AteTest> > >(new AteTestsResourceBuilder()); with.Module <AteQualityModule>(); with.ResponseProcessor <AteFaultCodeResponseProcessor>(); with.ResponseProcessor <AteFaultCodesResponseProcessor>(); with.ResponseProcessor <ResultsModelJsonResponseProcessor>(); with.ResponseProcessor <AteTestResponseProcessor>(); with.ResponseProcessor <AteTestsResponseProcessor>(); with.ResponseProcessor <AteTestsResponseProcessor>(); with.ResponseProcessor <ComponentCountResponseProcessor>(); with.RequestStartup( (container, pipelines, context) => { var claims = new List <Claim> { new Claim(ClaimTypes.Role, "employee"), new Claim(ClaimTypes.NameIdentifier, "test-user") }; var user = new ClaimsIdentity(claims, "jwt"); context.CurrentUser = new ClaimsPrincipal(user); }); }); this.Browser = new Browser(bootstrapper); }
public void Should_return_status_ok_when_route_exists() { // Given var bootstrapper = new ConfigurableBootstrapper(config => config.Modules(typeof(DashingModule))); var browser = new Browser(bootstrapper); // When var result = browser.Get("/", with => { with.HttpRequest(); }); // Then Assert.Equal(HttpStatusCode.SeeOther, result.StatusCode); }
public void Should_use_rolling_expiry_for_auth_cookie() { var diagsConfig = new DiagnosticsConfiguration { Password = "******", CryptographyConfiguration = this.cryptoConfig }; var bootstrapper = new ConfigurableBootstrapper(b => b.DiagnosticsConfiguration(diagsConfig)); var browser = new Browser(bootstrapper); var expiryDate = DateTime.Now.AddMinutes(5); var result = browser.Get("/_Nancy", with => with.Cookie(DiagsCookieName, this.GetSessionCookieValue("password", expiryDate))); result.Cookies.Any(c => c.Name == DiagsCookieName).ShouldBeTrue(); this.DecodeCookie(result.Cookies.First(c => c.Name == DiagsCookieName)) .Expiry.ShouldNotEqual(expiryDate); }
public void Should_return_main_page_with_valid_auth_cookie() { var diagsConfig = new DiagnosticsConfiguration { Password = "******", CryptographyConfiguration = this.cryptoConfig }; var bootstrapper = new ConfigurableBootstrapper(b => b.DiagnosticsConfiguration(diagsConfig)); var browser = new Browser(bootstrapper); var result = browser.Get("/_Nancy", with => { with.Cookie(DiagsCookieName, this.GetSessionCookieValue("password")); }); result.Body["#infoBox"].ShouldExistOnce(); }
public void Should_return_login_page_with_expired_auth_cookie() { var diagsConfig = new DiagnosticsConfiguration { Password = "******", CryptographyConfiguration = this.cryptoConfig }; var bootstrapper = new ConfigurableBootstrapper(b => b.DiagnosticsConfiguration(diagsConfig)); var browser = new Browser(bootstrapper); var result = browser.Get("/_Nancy", with => { with.Cookie(DiagsCookieName, this.GetSessionCookieValue("password", DateTime.Now.AddMinutes(-10))); }); result.Body["#login"].ShouldExistOnce(); }