Exemplo n.º 1
0
            public void GivenAValidRequestToken_RedirectToAuthenticate_ReturnsARedirectResult()
            {
                // Arrange.
                var redirectUri =
                    new Uri(
                        "http://www.flickr.com/services/oauth/authorize?oauth_token=5rlgo7AwGJt67vSoHmF227QMSHXhvmOmhN5YJpRlEo");
                var mockRestResponse = new Mock<IRestResponse>();
                mockRestResponse.Setup(x => x.StatusCode).Returns(HttpStatusCode.OK);
                mockRestResponse
                    .Setup(x => x.Content)
                    .Returns("oauth_token=aaaaaaa&oauth_token_secret=asdasd");
                var mockRestClient = new Mock<IRestClient>();
                mockRestClient
                    .Setup(x => x.BuildUri(It.IsAny<IRestRequest>()))
                    .Returns(redirectUri);
                mockRestClient
                    .Setup(x => x.Execute(It.IsAny<IRestRequest>()))
                    .Returns(mockRestResponse.Object);
                var flickrProvider = new FlickrProvider("a", "b", null, new RestClientFactory(mockRestClient.Object));
                var flickrAuthenticationServiceSettings = new FlickrAuthenticationServiceSettings
                {
                    CallBackUri = new Uri("http://www.pewpew.com")
                };

                // Act.
                var result = flickrProvider.RedirectToAuthenticate(flickrAuthenticationServiceSettings);

                // Assert.
                Assert.NotNull(result);
                Assert.Equal(result.AbsoluteUri, redirectUri.AbsoluteUri);
            }
Exemplo n.º 2
0
            public void GivenAInvalidRequestToken_RedirectToAuthenticate_ThrowsAnAuthenticationException()
            {
                // Arrange.
                var mockRestResponse = new Mock<IRestResponse>();
                mockRestResponse.Setup(x => x.StatusCode).Returns(HttpStatusCode.OK);
                mockRestResponse.Setup(x => x.Content)
                                .Returns("oauth_token=aaaaaaa&missing_an_oauth_token_secret=asdasd");
                var mockRestClient = new Mock<IRestClient>();
                mockRestClient
                    .Setup(x => x.Execute(It.IsAny<IRestRequest>()))
                    .Returns(mockRestResponse.Object);
                var flickrProvider = new FlickrProvider("a", "b", null, new RestClientFactory(mockRestClient.Object));
                var flickrAuthenticationServiceSettings = new FlickrAuthenticationServiceSettings
                {
                    CallBackUri = new Uri("http://www.pewpew.com")
                };

                // Act.
                var result =
                    Assert.Throws<AuthenticationException>(
                        () => flickrProvider.RedirectToAuthenticate(flickrAuthenticationServiceSettings));

                // Assert.
                Assert.NotNull(result);
                Assert.Null(result.InnerException);
                Assert.Equal(
                    "Retrieved a Flickr Request Token but it doesn't contain both the oauth_token and oauth_token_secret parameters.",
                    result.Message);
            }
Exemplo n.º 3
0
            public void GivenARequestTokenError_RedirectToAuthenticate_ThrowsAnAuthenticationException()
            {
                // Arrange.
                var mockRestResponse = new Mock<IRestResponse>();
                mockRestResponse.Setup(x => x.StatusCode).Returns(HttpStatusCode.Unauthorized);
                mockRestResponse.Setup(x => x.StatusDescription).Returns("Unauthorized");
                var mockRestClient = new Mock<IRestClient>();
                mockRestClient
                    .Setup(x => x.Execute(It.IsAny<IRestRequest>()))
                    .Returns(mockRestResponse.Object);
                var flickrProvider = new FlickrProvider("a", "b", null, new RestClientFactory(mockRestClient.Object));
                var flickrAuthenticationServiceSettings = new FlickrAuthenticationServiceSettings
                {
                    CallBackUri = new Uri("http://www.pewpew.com")
                };

                // Act.
                var result =
                    Assert.Throws<AuthenticationException>(
                        () => flickrProvider.RedirectToAuthenticate(flickrAuthenticationServiceSettings));

                // Assert.
                Assert.NotNull(result);
                Assert.Null(result.InnerException);
                Assert.Equal(
                    "Failed to obtain a Request Token from Flickr OR the the response was not an HTTP Status 200 OK. Response Status: Unauthorized. Response Description: Unauthorized",
                    result.Message);
            }
Exemplo n.º 4
0
            public void GivenAExceptionWhileTryingToRetrieveRequestToken_RedirectToAuthenticate_ThrowsAnAuthenticationException()
            {
                // Arrange.
                var mockRestClient = new Mock<IRestClient>();
                mockRestClient
                    .Setup(x => x.Execute(It.IsAny<IRestRequest>()))
                    .Throws(new Exception("some mock exception"));
                var flickrProvider = new FlickrProvider("a", "b", null, new RestClientFactory(mockRestClient.Object));
                var flickrAuthenticationServiceSettings = new FlickrAuthenticationServiceSettings
                {
                    CallBackUri = new Uri("http://www.pewpew.com")
                };
                // Act.
                var result =
                    Assert.Throws<AuthenticationException>(
                        () => flickrProvider.RedirectToAuthenticate(flickrAuthenticationServiceSettings));

                // Assert.
                Assert.NotNull(result);
                Assert.Equal("Failed to obtain a Request Token from Flickr.", result.Message);
                Assert.NotNull(result.InnerException);
                Assert.Equal("some mock exception", result.InnerException.Message);
            }