public void GivenAFacebookCallback_CheckCallback_RetrievesAnAccessTokenAnUserData() { // Arrange. const string state = "blah"; var mockWebClientWrapper = MoqUtilities.MockedIWebClientWrapper(); var facebookProvider = new FacebookProvider("a", "b", new Uri("http://www.google.com"), mockWebClientWrapper.Object); var authenticationService = new AuthenticationService(facebookProvider); var mockRequestBase = new Mock<HttpRequestBase>(); mockRequestBase.Setup(x => x.Params).Returns(new NameValueCollection { {"code", "aaa"}, {"state", state} }); // Act. var facebookClient = authenticationService.CheckCallback(mockRequestBase.Object, state) as FacebookClient; // Assert. Assert.NotNull(facebookClient); Assert.NotNull(facebookClient.AccessToken); Assert.NotNull(facebookClient.UserInformation); Assert.NotNull(facebookClient.UserInformation.Id); }
public void GiveAMissingProviderKeyQuerystringValue_CheckCallback_ThrowsAnException() { // Arrange. var authenticationService = new AuthenticationService(); // Act. var result = Assert.Throws<ArgumentNullException>(() => authenticationService.CheckCallback(null, null, null)); // Assert. Assert.NotNull(result); Assert.Equal("value should not be null or an empty string.\r\nParameter name: value", result.Message); }
public void GivenAnInvalidProviderKey_CheckCallback_ThrowsAnException() { // Arrange. const string providerKey = "aaa"; const string state = "asd"; var querystringParams = new NameValueCollection(); var authenticationService = new AuthenticationService(); // Act and Assert. var result = Assert.Throws<AuthenticationException>( () => authenticationService.CheckCallback(providerKey, querystringParams, state)); Assert.NotNull(result); Assert.Equal("No 'aaa' provider has been added.", result.Message); }