public async Task AuthenticationTest() { using (var webserver = new WebServer(_defaultPort)) { var responseObj = new Dictionary <string, object> { { AuthorizationToken, "123" } }; webserver.RegisterModule(new FallbackModule((ctx, ct) => { if (ctx.RequestFormDataDictionary().ContainsKey("grant_type")) { ctx.JsonResponse(responseObj); } return(true); })); webserver.RunAsync(); var data = await JsonClient.Authenticate(_defaultHttp, "admin", "password"); Assert.IsNotNull(data); Assert.IsTrue(data.ContainsKey(AuthorizationToken)); Assert.AreEqual(responseObj[AuthorizationToken], data[AuthorizationToken]); } }
public async Task WithValidParams_ReturnsTrue() { var responseObj = new Dictionary <string, object> { { AuthorizationToken, "123" } }; var data = await JsonClient.Authenticate(new Uri($"{DefaultHttp}/Authenticate"), "admin", "password"); Assert.IsNotNull(data); Assert.IsTrue(data !.ContainsKey(AuthorizationToken)); Assert.AreEqual(responseObj[AuthorizationToken], data[AuthorizationToken]); }
public void WithNullUsername_ThrowsArgumentNullException() { Assert.ThrowsAsync <ArgumentNullException>(async() => await JsonClient.Authenticate(new Uri(DefaultHttp), null, "password")); }
public void WithInvalidParams_ThrowsSecurityException() { Assert.ThrowsAsync <SecurityException>(async() => await JsonClient.Authenticate(new Uri($"{DefaultHttp}/511"), "admin", "password")); }
public void WithNullUrl_ThrowsArgumentNullException() { Assert.ThrowsAsync <ArgumentNullException>(async() => await JsonClient.Authenticate(null, "admin", "password")); }