Example #1
0
        public void InvalidUserCredentialsReturnsUnAuthorized()
        {
            var userRepository    = new Mock <IRepository <InsideUser> >();
            var contactRepository = new Mock <IRepository <Contact> >();

            var userManager          = new Mock <IIdentityMembershipProvider>();
            var tokenGenerator       = new Mock <IAccessTokenProvider>();
            var budgetRepositoryMock = new Mock <IRepository <Budget> >();
            var clientRepositoryMock = new Mock <IRepository <Client> >();
            var serverTimeMock       = new Mock <IServerTime>();

            var username = "******";
            var password = "******";

            userManager.Setup(mp => mp.ValidateAndReturnUser(username, password)).Returns(null as InsideUser);

            var controller = new ExternalController(
                userRepository.Object,
                contactRepository.Object,
                tokenGenerator.Object,
                userManager.Object,
                budgetRepositoryMock.Object,
                clientRepositoryMock.Object,
                serverTimeMock.Object);

            Assert.IsInstanceOfType(controller.GetAccessToken(username, password), typeof(UnauthorizedResult));
        }
Example #2
0
        public void CanGetAccessToken()
        {
            var userRepository    = new LocalRepository <InsideUser>();
            var contactRepository = new Mock <IRepository <Contact> >();

            var userManager          = new Mock <IIdentityMembershipProvider>();
            var tokenGenerator       = new Mock <IAccessTokenProvider>();
            var budgetRepositoryMock = new Mock <IRepository <Budget> >();
            var clientRepositoryMock = new Mock <IRepository <Client> >();
            var serverTimeMock       = new Mock <IServerTime>();

            var username = "******";
            var password = "******";

            var membershipProviderId = new Guid();
            var memebershipUser      = new Mock <MembershipUser>();

            memebershipUser.Setup(mu => mu.ProviderUserKey).Returns(membershipProviderId);
            var userInRepository = new InsideUser()
            {
                UserId   = 1,
                ClientId = 1,
                Id       = membershipProviderId.ToString()
            };

            userRepository.Add(userInRepository);
            userManager.Setup(mp => mp.ValidateAndReturnUser(username, password)).Returns(userInRepository);

            tokenGenerator.Setup(tg => tg.GetToken(It.IsAny <string>())).Returns(new Token()
            {
                AccessToken = "TokenGenerated"
            });

            var controller = new ExternalController(
                userRepository,
                contactRepository.Object,
                tokenGenerator.Object,
                userManager.Object,
                budgetRepositoryMock.Object,
                clientRepositoryMock.Object,
                serverTimeMock.Object);

            var result = controller.GetAccessToken(username, password) as OkNegotiatedContentResult <AcccessTokenForClient>;

            Assert.AreEqual("TokenGenerated", result.Content.AccessToken);
        }