private LoginServiceException TestLoginProcessExpectError(string code, string encryptData) { var mock = helper.CreateLoginHttpMock(code, encryptData); var loginService = new LoginService(mock.Object.Request, mock.Object.Response); LoginServiceException errorShouldThrow = null; try { UserInfo userInfo = loginService.Login(); } catch (LoginServiceException error) { errorShouldThrow = error; } Func <string, bool> bodyMatch = (string body) => { JObject result = JObject.Parse(body); return(helper.CheckBodyHasMagicId(result) && result["error"] != null); }; mock.Verify(x => x.Response.Write(It.Is((string body) => bodyMatch(body))), Times.Once()); return(errorShouldThrow); }
public void TestCheckWithServerTimeout() { var errors = new LoginServiceException[] { TestCheckExpectError("expect-timeout", "valid-key", false) }.Where(x => x != null); Assert.AreEqual(errors.Count(), 1); }
public void TestLoginProcessWithServerTimeout() { var errors = new LoginServiceException[] { TestLoginProcessExpectError("expect-timeout", "valid-data"), }.Where(x => x != null); Assert.AreEqual(errors.Count(), 1); }
public void TestLoginProcessWithServerResponseError() { var errors = new LoginServiceException[] { TestLoginProcessExpectError("expect-invalid-json", "valid-data", "valid-iv"), }.Where(x => x != null); Assert.AreEqual(errors.Count(), 1); }
public void TestCheckWithInvalidSession() { var errors = new LoginServiceException[] { TestCheckExpectError("expect-60011", "valid-key", true), TestCheckExpectError("expect-60012", "valid-key", true) }.Where(x => x != null); Assert.AreEqual(errors.Count(), 2); }
public void TestCheckWithInvalidIdOrSkey() { var errors = new LoginServiceException[] { TestCheckExpectError("invalid-id", "valid-key", false), TestCheckExpectError("valid-id", "invalid-key", false) }.Where(x => x != null); Assert.AreEqual(errors.Count(), 2); }
public void TestLoginProcessWithInvalidCodeOrData() { var errors = new LoginServiceException[] { TestLoginProcessExpectError("invalid-code", "valid-data"), TestLoginProcessExpectError("valid-code", "invalid-data") }.Where(x => x != null); Assert.AreEqual(errors.Count(), 2); }
private LoginServiceException TestCheckExpectError(string id, string skey, bool?expectInvalidSession = null) { var mock = helper.CreateCheckHttpMock(id, skey); var loginService = new LoginService(mock.Object.Request, mock.Object.Response); LoginServiceException errorShouldThrow = null; try { UserInfo userInfo = loginService.Check(); } catch (LoginServiceException error) { errorShouldThrow = error; } Func <string, bool> bodyMatch = (string body) => { Console.WriteLine("=======Response========"); Console.WriteLine(body); JObject result = JObject.Parse(body); if (!helper.CheckBodyHasMagicId(result)) { return(false); } if (expectInvalidSession == null) { return(true); } return(result["error"].Value <string>() == "ERR_INVALID_SESSION" ^ !expectInvalidSession.Value); }; mock.Verify(x => x.Response.Write(It.Is((string body) => bodyMatch(body))), Times.Once()); return(errorShouldThrow); }