public async Task AuthToken_Verify_Failed_missing_phone_and_Token()
        {
            //arrange
            _authTokenAPI = new AuthTokenController(new AuthTokenService(_authTokenRepositoryMock.Object, _personsRepositoryMock.Object))
            {
                Request       = new System.Net.Http.HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };

            var authTokenRequest = new VerifyAuthTokenRequest()
            {
                Phone = "",
                Token = ""
            };

            //act
            var response = await _authTokenAPI.VerifyAsync(authTokenRequest);

            var responseBody = await Task.FromResult(response.Content.ReadAsStringAsync()).Result;

            //assert
            Assert.AreEqual(System.Net.HttpStatusCode.BadRequest, response.StatusCode);
            Assert.IsTrue(responseBody.Contains("{\\\"MemberNames\\\":[\\\"Phone\\\"],\\\"ErrorMessage\\\":\\\"blank\\\"}"));
            Assert.IsTrue(responseBody.Contains("{\\\"MemberNames\\\":[\\\"Token\\\"],\\\"ErrorMessage\\\":\\\"blank\\\"}"));
        }
        public async Task AuthToken_Verify_Success()
        {
            //arrange
            _authTokenAPI = new AuthTokenController(new AuthTokenService(_authTokenRepositoryMock.Object, _personsRepositoryMock.Object))
            {
                Request       = new System.Net.Http.HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };

            var authTokenRequest = new VerifyAuthTokenRequest()
            {
                Phone = "123456789123",
                Token = "GNSaYTxnLWWlyeyOL9RCUiYI4MRm++18mTkIwTMHIpwfZSygAAUovW/fkVV+saGe0+XfMKzEKjtpdluNSjUlZ6TUQllSvh32zNHZRCbyBpglvcJwJKJqjH+wV95lpvPpYXj+SotD8vflPzAVD7x0q3NxxK50TJhUOYQm6VblWR4="
            };

            var authTokenRow = new DTO.AuthToken()
            {
                Phone    = "123456789123",
                Token    = "GNSaYTxnLWWlyeyOL9RCUiYI4MRm++18mTkIwTMHIpwfZSygAAUovW/fkVV+saGe0+XfMKzEKjtpdluNSjUlZ6TUQllSvh32zNHZRCbyBpglvcJwJKJqjH+wV95lpvPpYXj+SotD8vflPzAVD7x0q3NxxK50TJhUOYQm6VblWR4=",
                ExpireAt = DateTime.UtcNow.AddMinutes(10)
            };

            _personsRepositoryMock.Setup(x => x.IsPhoneExists(It.IsAny <string>())).Returns(true);
            _authTokenRepositoryMock.Setup(x => x.Get(It.IsAny <string>(), It.IsAny <string>())).Returns(authTokenRow);

            //act
            var response = await _authTokenAPI.VerifyAsync(authTokenRequest);

            var responseBody = await Task.FromResult(response.Content.ReadAsStringAsync()).Result;

            //assert
            Assert.AreEqual(System.Net.HttpStatusCode.Created, response.StatusCode);
            Assert.AreEqual(responseBody, "\"valid\"");
        }
        /// <summary>
        /// verify that phone and token are exists in databse
        /// + verify token status(valid, expired or not found)
        /// </summary>
        /// <param name="request"></param>
        /// <returns> return VerifyAuthTokenResponse(validation errors + status as string)</returns>
        public VerifyAuthTokenResponse VerifyAuthToken(VerifyAuthTokenRequest request)
        {
            var result = new VerifyAuthTokenResponse();

            var error = ValidateRequest(request);

            if (error.HasErrors)
            {
                result.Errors = error;
                return(result);
            }

            var authTokenRow = _authTokenRepository.Get(request.Phone, request.Token);

            if (authTokenRow == null)// not found..
            {
                result.Result = AuthTokenResult.NotFound;
            }
            else
            {
                if (authTokenRow.ExpireAt < DateTime.UtcNow)// expired tooken
                {
                    result.Result = AuthTokenResult.Expired;
                }
                else
                {
                    // handle valid token
                    result.Result = AuthTokenResult.Valid;
                }
            }
            return(result);
        }