AdventureWorks.WebServices.Tests.Controllers.IdentityControllerFixture.ValidateUserNameInvalidUser C# (CSharp) Method

ValidateUserNameInvalidUser() private method

private ValidateUserNameInvalidUser ( ) : void
return void
        public void ValidateUserNameInvalidUser()
        {
            var sawException = false;
            var controller = new IdentityController();

            // 1- Get a random password challenge string from the web service.
            const string requestId = "ec609a4f";
            var challengeString = controller.GetPasswordChallenge(requestId);
            Assert.IsFalse(string.IsNullOrEmpty(challengeString));

            try
            {
                // 2 - Ask the web service to validate an invalid user id.
                var result = controller.GetIsValid("UnknownUser", requestId, CreatePasswordHash("pwd", challengeString));

            }
            catch (HttpResponseException ex)
            {
                // 3- Verify that a 401 Status code was returned through the exception (handled by ASP.NET)
                Assert.AreEqual(HttpStatusCode.Unauthorized, ex.Response.StatusCode);
                sawException = true;
            }
            // Verify that authentication failed for unknown user
            Assert.IsTrue(sawException);
        }
    }