예제 #1
0
        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]);
            }
        }
예제 #2
0
        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]);
        }
예제 #3
0
 public void WithNullUsername_ThrowsArgumentNullException()
 {
     Assert.ThrowsAsync <ArgumentNullException>(async() =>
                                                await JsonClient.Authenticate(new Uri(DefaultHttp), null, "password"));
 }
예제 #4
0
 public void WithInvalidParams_ThrowsSecurityException()
 {
     Assert.ThrowsAsync <SecurityException>(async() =>
                                            await JsonClient.Authenticate(new Uri($"{DefaultHttp}/511"), "admin", "password"));
 }
예제 #5
0
 public void WithNullUrl_ThrowsArgumentNullException()
 {
     Assert.ThrowsAsync <ArgumentNullException>(async() =>
                                                await JsonClient.Authenticate(null, "admin", "password"));
 }