public IEnumerator GetUserInfoAsync_JsonParseFailed_ReturnsNull() { LearningLayersOidcProvider lloidc = new LearningLayersOidcProvider(); IRestConnector restConnector = A.Fake <IRestConnector>(); A.CallTo(() => restConnector.GetAsync(A <string> .Ignored)) .Returns(new WebResponse <string>("answer", null, 200)); lloidc.RestConnector = restConnector; LearningLayersUserInfo userInfo = new LearningLayersUserInfo("tester", "*****@*****.**", "Tester"); IJsonSerializer serializer = A.Fake <IJsonSerializer>(); A.CallTo(() => serializer.FromJson <LearningLayersUserInfo>(A <string> .Ignored)) .Returns(null); lloidc.JsonSerializer = serializer; LogAssert.Expect(LogType.Error, new Regex(@"\w*Could not parse user info\w*")); Task <IUserInfo> task = lloidc.GetUserInfoAsync(""); yield return(AsyncTest.WaitForTask(task)); IUserInfo res = task.Result; Assert.IsNull(res); }
public IEnumerator GetUserInfoAsync_WebResponseFailed_ReturnsNull() { LearningLayersOidcProvider lloidc = new LearningLayersOidcProvider(); IRestConnector restConnector = A.Fake <IRestConnector>(); A.CallTo(() => restConnector.GetAsync(A <string> .Ignored)) .Returns(new WebResponse <string>("This is a simulated error", 400)); lloidc.RestConnector = restConnector; LogAssert.Expect(LogType.Error, new Regex(@"\w*This is a simulated error\w*")); Task <IUserInfo> task = lloidc.GetUserInfoAsync(""); yield return(AsyncTest.WaitForTask(task)); IUserInfo res = task.Result; Assert.IsNull(res); }
public IEnumerator GetUserInfoAsync_WebResponseSuccessful_ReturnsUserInfo() { LearningLayersOidcProvider lloidc = new LearningLayersOidcProvider(); IRestConnector restConnector = A.Fake <IRestConnector>(); A.CallTo(() => restConnector.GetAsync(A <string> .Ignored)) .Returns(new WebResponse <string>("answer", null, 200)); lloidc.RestConnector = restConnector; LearningLayersUserInfo userInfo = new LearningLayersUserInfo("tester", "*****@*****.**", "Tester"); IJsonSerializer serializer = A.Fake <IJsonSerializer>(); A.CallTo(() => serializer.FromJson <LearningLayersUserInfo>(A <string> .Ignored)) .Returns(userInfo); lloidc.JsonSerializer = serializer; Task <IUserInfo> task = lloidc.GetUserInfoAsync(""); yield return(AsyncTest.WaitForTask(task)); IUserInfo res = task.Result; Assert.AreEqual(userInfo.Email, res.Email); }