Esempio n. 1
0
        public void CredentialVerificationRespondsCorrectly(bool validResult, HttpStatusCode statusCode)
        {
            // arrange
            const string user    = "******";
            const string pass    = "******";
            var          fixture = new RequestProcessorFixture();

            var path        = AppDomain.CurrentDomain.BaseDirectory;
            var examplePath = Path.Combine(path, "PageExamples", "ValidUser.xml");
            var data        = File.ReadAllText(examplePath);

            if (validResult)
            {
                fixture.PageRetrieverMock.Setup(
                    t => t.RetrieveDocumentAsStringAsync(MalRouteBuilder.VerifyCredentialsUrl(), user, pass))
                .ReturnsAsync(new StringRetrievalWrapper(HttpStatusCode.OK, true, data));
            }
            else
            {
                fixture.PageRetrieverMock.Setup(
                    t => t.RetrieveDocumentAsStringAsync(MalRouteBuilder.VerifyCredentialsUrl(), user, pass))
                .ReturnsAsync(new StringRetrievalWrapper(HttpStatusCode.Unauthorized, false,
                                                         "Invalid credentials"));
            }

            var sut = fixture.Instance;

            // act
            var result = sut.VerifyCredentials(user, pass).Result;

            // assert
            result.ResponseStatusCode.Should().Be(statusCode);
            result.Success.Should().Be(validResult);
        }
Esempio n. 2
0
        /// <summary>
        /// Verify user credentials
        /// </summary>
        /// <param name="username">Username</param>
        /// <param name="password">Password</param>
        /// <returns>True - Credentials are valid, otherwise false</returns>
        public async Task <DataPushResponseWrapper> VerifyCredentials(string username, string password)
        {
            var page = await _pageRetriever.RetrieveDocumentAsStringAsync(MalRouteBuilder.VerifyCredentialsUrl(),
                                                                          username, password);

            if (page.ResponseStatusCode == null)
            {
                return(new DataPushResponseWrapper(page.Exception));
            }

            return(new DataPushResponseWrapper(page.ResponseStatusCode.Value, page.Success));
        }