public void TestBadHostLoginHandlesException() { using (var httpTest = new HttpTest()) { httpTest.RespondWith("Call failed. No such host is known POST https://badhost/api/V2/login", 404); try { TraditionalClient traditionalClientBad = new TraditionalClient("badhost"); traditionalClientBad.TryLogin("username", "password"); httpTest.ShouldHaveCalled($"https://badhost/api/V2/login") .WithVerb(HttpMethod.Post) .WithContentType("application/json") .WithRequestBody("{\"username\":\"username\",\"password\":\"password\"") .Times(1); } catch { Assert.Fail(); } } }
public void TestLogin() { using (var httpTest = new HttpTest()) { httpTest.RespondWithJson(new { accessToken = "faketoken", expires = "2030-01-01T00:00:00Z" }); traditionalClient.TryLogin("username", "password"); httpTest.ShouldHaveCalled($"https://hostname/api/V2/login") .WithVerb(HttpMethod.Post) .WithContentType("application/json") .WithRequestBody("{\"username\":\"username\",\"password\":\"password\"") .Times(1); } }