public void Should_fail_to_create_xdocument_from_non_xml_body() { var context = new NancyContext() { Response = "hello" }; sut = new BrowserResponse(context, A.Fake<Browser>()); Assert.Throws<XmlException>(() => sut.BodyAsXml()); }
public void Should_create_xdocument_from_xml_body() { var context = new NancyContext() { Response = "<tag />" }; sut = new BrowserResponse(context, A.Fake<Browser>()); var bodyAsXml = sut.BodyAsXml(); Assert.NotNull(bodyAsXml.Element("tag")); }
private void DeleteDoctorById(long id) { Browser browser = CreateBrowser(); BrowserResponse result = browser.Delete("/person/" + id, with => { with.HttpRequest(); }); Assert.Equal(HttpStatusCode.OK, result.StatusCode); }
private dynamic CreateDoctorToBeDeleted(Browser browser) { BrowserResponse result = browser.Post("/person/", with => { with.HttpRequest(); }); dynamic actual = XUnitPersonsHelper.ToDynamic(result.Body.AsString()); return(actual); }
public static void ThrowIfNotSuccessful(this BrowserResponse response, string fileName) { var body = response.Body.AsString(); //if (result.StatusCode != HttpStatusCode.OK) //Crappy check because Nancy returns 200 on a compilation error :( if (body.Contains("<title>Razor Compilation Error</title>") && body.Contains("<p>We tried, we really did, but we just can't compile your view.</p>")) { throw new FileProcessingException("Processing failed composing " + fileName); } }
public When_an_invalid_region_id_is_specified() { _Browser = Testing.CreateBrowser <SecuredPagesModule>(with => { with.LoggedInUser(); }); _Response = _Browser.Post("/Deploy/jabbr", with => { with.FormValue("application_name", "foo"); with.FormValue("region_id", "foo"); }); }
// ITestClient GivenTestClient(string hostname, string username) // , int testRunId) // { // return TestFactory.GivenTestClient(hostname, username); // , testRunId); // } ITestClient GivenRegisteredClient(string hostname, string username) { var testClient = new TestClient { Hostname = hostname, Username = username }; _response = _browser.Post(UrlList.TestClientRegistrationPoint_absPath, with => { with.JsonBody(testClient); with.Accept("application/json"); }); return(_response.Body.DeserializeJson <TestClient>()); }
public void Should_create_xdocument_from_xml_body() { var context = new NancyContext() { Response = "<tag />" }; sut = new BrowserResponse(context, A.Fake <Browser>()); var bodyAsXml = sut.BodyAsXml(); Assert.NotNull(bodyAsXml.Element("tag")); }
public void ShouldAccessLoginAfterSuccessfulLogin() { var bootstrapper = new CustomTestBootstrapper(); var browser = new Browser(bootstrapper); BrowserResponse response = browser.Post("/login", (with) => { with.HttpRequest(); with.FormValue("Username", "admin"); with.FormValue("Password", "password"); }); response.ShouldHaveRedirectedTo("/admin"); }
public When_oauth_callback_is_received() { _OAuth = new Mock <IOAuth>(MockBehavior.Strict); _OAuth.Setup(d => d.GetAccessToken(It.IsAny <string>())).Returns("12345"); _Browser = Testing.CreateBrowser <OAuthModule>(with => { with.OAuth(_OAuth); }); _Response = _Browser.Get("/callback", with => { with.Query("code", "testcode"); }); }
public When_code_can_not_be_exchanged_for_access_token() { _OAuth = new Mock <IOAuth>(MockBehavior.Strict); _OAuth.Setup(d => d.GetAccessToken(It.IsAny <string>())).Returns((string)null); _Browser = Testing.CreateBrowser <OAuthModule>(with => { with.OAuth(_OAuth); }); _Response = _Browser.Get("/callback", with => { with.Query("code", "testcode"); }); }
public void WhenBodyCorrectOkResponse() { BrowserResponse response = Post(with => { with.Header("Accept", "application/json"); with.JsonBody(new LanguageDetectRequest() { TextForLanguageClassification = "some words" }); }); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); }
public void When_put_Then_response_is_OK() { // Act BrowserResponse post = _browser.Put("/testAsync/1", with => { with.HttpRequest(); with.Query("value", "3"); }); // Assert post.StatusCode.Should().Be(HttpStatusCode.OK); post.ContentType.Should().Be("application/json"); }
public void When_get_Then_response_is_OK() { // Act BrowserResponse response = _browser.Get("/testAsync/0", with => { with.HttpRequest(); with.Header("Accept", "application/json"); }); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); response.ContentType.Should().Be("application/json"); }
public void When_put_letter_instead_of_int_Then_Exception_is_thrown() { // Act BrowserResponse post = _browser.Put("/test/a", with => { with.HttpRequest(); with.Query("value", "3"); }); // Assert //TODO: mapping exceptions to responses post.StatusCode.Should().Be(HttpStatusCode.InternalServerError); }
private static string GetContextValue(BrowserResponse response, string key) { object val; if (!response.Context.Items.TryGetValue(key, out val)) { return(string.Empty); } var value = (string)val; return(string.IsNullOrEmpty(value) ? string.Empty : value); }
private async Task Given_the_user_creates_team_and_is_admin() { team = DataGenerator.GenerateSingleTeam(config.Context); createTeamResult = await helper.CreateTeamResponse(team, loginResult.BodyJson <LoginResponse>().Token); role = DataGenerator.GenerateSigleRole(config.Context, "Admin"); createRoleResult = await helper.CreateRoleResponse(role, loginResult.BodyJson <LoginResponse>().Token); assignRoleResult = await helper.AssignRoleResponse(createRoleResult.BodyJson <Role>().Id, createTeamResult.BodyJson <Team>().Id, loginResult.BodyJson <LoginResponse>().User.Id, loginResult.BodyJson <LoginResponse>().Token); }
public When_a_redirect_url_is_specified() { _OAuth = new Mock <IOAuth>(MockBehavior.Strict); _OAuth.Setup(d => d.GetAuthUrl()).Returns("http://www.test.com"); _Browser = Testing.CreateBrowser <OAuthModule>(with => { with.OAuth(_OAuth); }); _Response = _Browser.Get("/SignIn", with => { with.Query("redirect", "/Test"); }); }
private async Task Given_the_user_is_logged_in() { registerResult = await helper.RegisterResponse(user); loginResult = await helper.LoginResponse(user); Assert.Equal(HttpStatusCode.OK, loginResult.StatusCode); var body = loginResult.BodyJson <LoginResponse>(); Assert.Equal(body.User.Username, user.Username); Assert.NotNull(body.Token); Assert.NotEmpty(body.Token); }
private void DeleteDayById(int dayId) { Browser browser = CreateBrowser(); BrowserResponse result = browser.Delete("/days/" + dayId, with => { with.HttpRequest(); }); Assert.Equal(HttpStatusCode.OK, result.StatusCode); }
public void TestBadURLs() { Browser browser = m_fixture.B; BrowserResponse response = browser.Get("/bogusurl"); Assert.NotNull(response); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); // Valid method (processhistory), but invalid params (the // first param should be an integer). response = browser.Get("/processhistory/x/2"); Assert.NotNull(response); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); }
public void When_retrieving_home() { _result = _browser.Get("/", with => { with.HttpRequest(); with.Header("accept", "text/html"); }) .Result; //should_return_200_OK Assert.AreEqual(_result.StatusCode, HttpStatusCode.OK); //should_return_text_html Assert.AreEqual(_result.ContentType, "text/html"); }
public When_a_redirect_was_specified() { _OAuth = new Mock <IOAuth>(MockBehavior.Strict); _OAuth.Setup(d => d.GetAccessToken(It.IsAny <string>())).Returns("12345"); _Browser = Testing.CreateBrowser <OAuthModule>(with => { with.OAuth(_OAuth); with.Session(SessionKeys.SIGN_IN_REDIRECT, "/Test"); }); _Response = _Browser.Get("/callback", with => { with.Query("code", "testcode"); }); }
public void Should_fail_to_create_xdocument_from_non_xml_body() { // Given var context = new NancyContext() { Response = "hello" }; // When sut = new BrowserResponse(context, A.Fake <Browser>(), A.Dummy <BrowserContext>()); // Then Assert.Throws <XmlException>(() => sut.BodyAsXml()); }
public void WhenIRequestTheChordFromTheApi(string p0) { var browser = new Browser(with => { with.Module <ChordModule>(); var instance = new ChordRepository(); with.Dependency <IChordRepository>(instance); }); // Act var path = string.Format("/chord/{0}/", p0); _apiResponse = browser.Get(path, with => with.Accept("application/json")); }
public void Instance() { var obj = new CreateFabInstance(); obj.Name = "instance test"; BrowserResponse br = PostCreate("mod/instances", obj); FabInstance result = AssertFabResponseData <FabInstance>(br); Assert.AreEqual(obj.Name, result.Name, "Incorrect result."); NewVertexCount = 1; NewEdgeCount = 2; }
public void Class() { var obj = new CreateFabClass(); obj.Name = "class test"; BrowserResponse br = PostCreate("mod/classes", obj); FabClass result = AssertFabResponseData <FabClass>(br); Assert.AreEqual(obj.Name, result.Name, "Incorrect result."); NewVertexCount = 1; NewEdgeCount = 2; }
public void EstablishContext() { var resource = new CreateSerialisedProductResource { productName = ProductName }; this.response = this.Browser.Post( "/serial-numbers", with => { with.Accept("application/json"); with.JsonBody(resource); }); }
public void TestNetworkStatus() { Browser browser = m_fixture.B; BrowserResponse response = browser.Get("/networkstatus/null/null"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); string s = response.Body.AsString(); Assert.False(string.IsNullOrEmpty(s)); List <NetworkStatus> status = JsonConvert.DeserializeObject <List <NetworkStatus> >(s); Assert.NotNull(status); Assert.Equal(3, status.Count); NetworkStatus ns = status[0]; Assert.NotNull(ns); Assert.Equal("Status A1", ns.name); Assert.Equal(2, ns.deviceID); Assert.True(ns.successfulPing); Assert.NotNull(ns.dateSuccessfulPingOccurred); Assert.Equal(23, ns.dateSuccessfulPingOccurred.Value.Day); Assert.Equal(23, ns.datePingAttempted.Day); Assert.Equal("1.2.3.4", ns.ipAddress); Assert.True(ns.hasBeenPinged); Assert.Empty(ns.attempts); ns = status[1]; Assert.NotNull(ns); Assert.Equal("Status A2", ns.name); Assert.Equal(15, ns.deviceID); Assert.False(ns.successfulPing); Assert.NotNull(ns.dateSuccessfulPingOccurred); Assert.Equal(23, ns.dateSuccessfulPingOccurred.Value.Day); Assert.Equal(23, ns.datePingAttempted.Day); Assert.Equal("2.3.4.5", ns.ipAddress); Assert.True(ns.hasBeenPinged); Assert.Empty(ns.attempts); ns = status[2]; Assert.NotNull(ns); Assert.Equal("Status A3", ns.name); Assert.Equal(11, ns.deviceID); Assert.False(ns.successfulPing); Assert.Null(ns.dateSuccessfulPingOccurred); Assert.Equal(23, ns.datePingAttempted.Day); Assert.Equal("3.4.5.6", ns.ipAddress); Assert.False(ns.hasBeenPinged); Assert.Empty(ns.attempts); }
public void When_retrieving_home() { _result = _browser.Get("/", with => { with.HttpRequest(); with.Header("accept", "text/html"); }) .Result; //should_return_200_OK HttpStatusCode.OK.Should().Be(_result.StatusCode); //should_return_text_html _result.ContentType.Should().Be("text/html"); }
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); }
private dynamic CreateDayToBeDeleted(Browser browser) { IDayForResponse model = CreateModelForPutTest(); BrowserResponse result = browser.Post("/days/", with => { with.JsonBody(model); }); dynamic actual = ToDynamic(result.Body.AsString()); return(actual); }