Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public void TestCheckWithServerTimeout()
        {
            var errors = new LoginServiceException[] {
                TestCheckExpectError("expect-timeout", "valid-key", false)
            }.Where(x => x != null);

            Assert.AreEqual(errors.Count(), 1);
        }
Ejemplo n.º 3
0
        public void TestLoginProcessWithServerTimeout()
        {
            var errors = new LoginServiceException[] {
                TestLoginProcessExpectError("expect-timeout", "valid-data"),
            }.Where(x => x != null);

            Assert.AreEqual(errors.Count(), 1);
        }
Ejemplo n.º 4
0
        public void TestLoginProcessWithServerResponseError()
        {
            var errors = new LoginServiceException[] {
                TestLoginProcessExpectError("expect-invalid-json", "valid-data", "valid-iv"),
            }.Where(x => x != null);

            Assert.AreEqual(errors.Count(), 1);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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);
        }