Example #1
0
        public async Task Test_FacebookController_NoUserToken_Fail()
        {
            //Arrange

            //Facebook User Token absent
            FacebookAuthModel facebookAuthModel = new FacebookAuthModel();

            FacebookAuthenticator authenticator = new FacebookAuthenticator(this.MockFacebookClient.Object);

            var securityService = new SecurityService <FacebookAuthModel>(this.SecuritySettings);

            var controller = new FacebookController(securityService, authenticator);

            try
            {
                //Act
                var result = await controller.Create(facebookAuthModel);
            }
            catch (SecurityException ex)
            {
                //Assert
                Assert.IsType <SecurityException>(ex);
                this.MockFacebookClient.Verify(x => x.PostSecurityRequest(facebookAuthModel), Times.Never);
            }
        }
Example #2
0
        public async Task Test_FacebookController_Pass()
        {
            //Arrange
            FacebookAuthModel facebookAuthModel = new FacebookAuthModel
            {
                UserAccessToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
            };

            var client = new FacebookClient(this.SecuritySettings, this.MockHttpClient.Object);

            FacebookAuthenticator authenticator = new FacebookAuthenticator(client);

            var securityService = new SecurityService <FacebookAuthModel>(this.SecuritySettings);

            var controller = new FacebookController(securityService, authenticator);

            //Act
            var result = await controller.Create(facebookAuthModel);

            //Assert
            Assert.IsType <ObjectResult>(result);
            Assert.True((result as ObjectResult).Value.ToString().IsValidJwtToken());
            this.MockHttpClient.Verify(x => x.GetStringAsync <FacebookAppAccessToken>(It.IsAny <string>()), Times.Once);
            this.MockHttpClient.Verify(x => x.GetStringAsync <FacebookUserAccessTokenValidation>(It.IsAny <string>()), Times.Once);
        }
Example #3
0
        public async Task Test_FacebookController_FacebookAuth_Fail()
        {
            //Arrange

            //Facebook Client returns IsAuthenticated false
            this.MockFacebookClient = this.InitMockFacebookClient(this.SecuritySettings, false);

            FacebookAuthModel facebookAuthModel = new FacebookAuthModel
            {
                UserAccessToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
            };

            FacebookAuthenticator authenticator = new FacebookAuthenticator(this.MockFacebookClient.Object);

            var securityService = new SecurityService <FacebookAuthModel>(this.SecuritySettings);

            var controller = new FacebookController(securityService, authenticator);

            //Act
            var result = await controller.Create(facebookAuthModel);

            //Assert
            Assert.IsType <BadRequestResult>(result);
            this.MockFacebookClient.Verify(x => x.PostSecurityRequest(facebookAuthModel), Times.Once);
        }