public async Task LoginWithIncompleteCredentials(string credentials) { // SETUP JObject credentialObject = JObject.Parse(credentials); ByteArrayContent content = HttpBody.GetBodyFromJSON(credentialObject); // ACT var response = await _testFixture.Client.PostAsync(LOGIN_ROUTE, content); // ASSERT response.StatusCode.Should().Be(HttpStatusCode.BadRequest); var jsonString = await response.Content.ReadAsStringAsync(); var jsonObject = JObject.Parse(jsonString); if (!credentialObject.ContainsKey("username")) { jsonObject.Should().HaveElement("Username"); } if (!credentialObject.ContainsKey("password")) { jsonObject.Should().HaveElement("Password"); } }
public async Task LoginWithNonJsonBody(string credentials) { // SETUP var credentialObject = new JObject(); ByteArrayContent content; try { credentialObject = JObject.Parse(credentials); content = HttpBody.GetBodyFromJSON(credentialObject); } catch (Newtonsoft.Json.JsonReaderException e) { content = HttpBody.GetBodyFromString(""); } // ACT var response = await _testFixture.Client.PostAsync(LOGIN_ROUTE, content); // ASSERT response.StatusCode.Should().Be(HttpStatusCode.BadRequest); var jsonString = await response.Content.ReadAsStringAsync(); var jsonObject = JObject.Parse(jsonString); jsonObject.Should().HaveElement(""); }