Beispiel #1
0
        public IEnumerator GetAccessCodeFromTokenAsync_WebResponseSuccess_ReturnsToken()
        {
            LearningLayersOidcProvider lloidc        = new LearningLayersOidcProvider();
            IRestConnector             restConnector = A.Fake <IRestConnector>();

            A.CallTo(() => restConnector.PostAsync(A <string> .Ignored, A <string> .Ignored))
            .Returns(Task.FromResult(new WebResponse <string>("json string", null, 200)));
            lloidc.RestConnector = restConnector;
            lloidc.ClientData    = A.Fake <ClientData>();
            LearningLayersAuthorizationFlowAnswer answer = new LearningLayersAuthorizationFlowAnswer();

            answer.access_token = "myAccessToken";
            IJsonSerializer serializer = A.Fake <IJsonSerializer>();

            A.CallTo(() => serializer.FromJson <LearningLayersAuthorizationFlowAnswer>(A <string> .Ignored))
            .Returns(answer);
            lloidc.JsonSerializer = serializer;

            Task <string> task = lloidc.GetAccessTokenFromCodeAsync("", "");

            yield return(AsyncTest.WaitForTask(task));

            string res = task.Result;

            Assert.AreEqual(answer.access_token, res);
        }
Beispiel #2
0
        public IEnumerator GetAccessCodeFromTokenAsync_NoClientData_ReturnsEmptyString()
        {
            LearningLayersOidcProvider lloidc = new LearningLayersOidcProvider();

            lloidc.RestConnector = A.Fake <IRestConnector>();

            LogAssert.Expect(LogType.Error,
                             new Regex(@"\w*No client data supplied for the OpenID Connect Client\w*"));

            Task <string> task = lloidc.GetAccessTokenFromCodeAsync("", "");

            yield return(AsyncTest.WaitForTask(task));

            string res = task.Result;

            Assert.IsEmpty(res);
        }
Beispiel #3
0
        public IEnumerator GetAccessCodeFromTokenAsync_WebResponseFailed_ReturnsEmptyToken()
        {
            LearningLayersOidcProvider lloidc        = new LearningLayersOidcProvider();
            IRestConnector             restConnector = A.Fake <IRestConnector>();

            A.CallTo(() => restConnector.PostAsync(A <string> .Ignored, A <string> .Ignored))
            .Returns(Task.FromResult(new WebResponse <string>("my error", 400)));
            lloidc.RestConnector  = restConnector;
            lloidc.ClientData     = A.Fake <ClientData>();
            lloidc.JsonSerializer = A.Fake <IJsonSerializer>();

            LogAssert.Expect(LogType.Error,
                             new Regex(@"\w*my error\w*"));

            Task <string> task = lloidc.GetAccessTokenFromCodeAsync("", "");

            yield return(AsyncTest.WaitForTask(task));

            string res = task.Result;

            Assert.IsEmpty(res);
        }