<commit_before>﻿using System;
using System.Collections.Specialized;
using System.Net;
using Moq;
using RestSharp;
using WorldDomination.Web.Authentication.Twitter;
using Xunit;

namespace WorldDomination.Web.Authentication.Tests
{
    // ReSharper disable InconsistentNaming

    public class TwitterProviderFacts
    {
        public class AuthenticateClientFacts
        {
            [Fact]
            public void GivenAUserDeniesAcceptingTheAppAuthorization_AuthenticateClient_ThrowsAnAuthenticationException()
            {
                // Arrange.
                var mockRestClient = new Mock<IRestClient>();
                var twitterProvider = new TwitterProvider("a", "b", mockRestClient.Object);
                var nameValueCollection = new NameValueCollection
                {
                    {"denied", "JpQ7ZTt1nMeAhIypiOxLrkS3LreHwihKjsJcIJDf4To"}
                };
                // Act.
                var result =
                    Assert.Throws<AuthenticationException>(
                        () => twitterProvider.AuthenticateClient(nameValueCollection, null));

                // Assert.
                Assert.NotNull(result);
                Assert.Equal(
                    "Failed to accept the Twitter App Authorization. Therefore, authentication didn't proceed.",
                    result.Message);
            }

            [Fact]
            public void GivenTheCallbackParamtersAreInvalid_AuthenticateClient_ThrowsAnAuthenticationException()
            {
                // Arrange.
                var mockRestClient = new Mock<IRestClient>();
                mockRestClient
                    .Setup(x => x.Execute(It.IsAny<IRestRequest>()))
                    .Throws<Exception>();
                var twitterProvider = new TwitterProvider("a", "b", mockRestClient.Object);
                var nameValueCollection = new NameValueCollection(); // Missing 2x required params.

                // Act.
                var result =
                    Assert.Throws<AuthenticationException>(
                        () => twitterProvider.AuthenticateClient(nameValueCollection, "aa"));

                // Assert.
                Assert.NotNull(result);
                Assert.Equal(
                    "Failed to retrieve an oauth_token and an oauth_token_secret after the client has signed and approved via Twitter.",
                    result.Message);
            }

            [Fact]
            public void
                GivenExecutingARequestToRetrieveARequestTokenThrowsAnException_AuthenticateClient_ThrowsAnAuthenticationException
                ()<commit_msg>- Removed CuttingEdge.Conditions dependency from Core project.<commit_after>﻿using System;
using System.Collections.Specialized;
using System.Net;
using Moq;
using RestSharp;
using WorldDomination.Web.Authentication.Twitter;
using Xunit;

namespace WorldDomination.Web.Authentication.Tests
{
    // ReSharper disable InconsistentNaming

    public class TwitterProviderFacts
    {
        public class AuthenticateClientFacts
        {
            [Fact]
            public void GivenAUserDeniesAcceptingTheAppAuthorization_AuthenticateClient_ThrowsAnAuthenticationException()
            {
                // Arrange.
                var mockRestClient = new Mock<IRestClient>();
                var twitterProvider = new TwitterProvider("a", "b", mockRestClient.Object);
                var nameValueCollection = new NameValueCollection
                {
                    {"denied", "JpQ7ZTt1nMeAhIypiOxLrkS3LreHwihKjsJcIJDf4To"}
                };
                // Act.
                var result =
                    Assert.Throws<AuthenticationException>(
                        () => twitterProvider.AuthenticateClient(nameValueCollection, null));

                // Assert.
                Assert.NotNull(result);
                Assert.Equal(
                    "Failed to accept the Twitter App Authorization. Therefore, authentication didn't proceed.",
                    result.Message);
            }

            [Fact]
            public void GivenTheCallbackParamtersAreInvalid_AuthenticateClient_ThrowsAnAuthenticationException()
            {
                // Arrange.
                var mockRestClient = new Mock<IRestClient>();
                mockRestClient
                    .Setup(x => x.Execute(It.IsAny<IRestRequest>()))
                    .Throws<Exception>();
                var twitterProvider = new TwitterProvider("a", "b", mockRestClient.Object);
                var nameValueCollection = new NameValueCollection(); // Missing 2x required params.

                // Act.
                var result =
                    Assert.Throws<ArgumentOutOfRangeException>(
                        () => twitterProvider.AuthenticateClient(nameValueCollection, "aa"));

                // Assert.
                Assert.NotNull(result);
                Assert.Equal("Specified argument was out of the range of valid values.\r\nParameter name: parameters",
                    result.Message);
            }

            [Fact]
            public void
                GivenExecutingARequestToRetrieveARequestTokenThrowsAnException_AuthenticateClient_ThrowsAnAuthenticationException
                ()
{'fraction_non_alphanumeric': 0.07366622365673059, 'fraction_numerical': 0.0018986140117714068, 'mean_word_length': 1.7726315789473683, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1793453', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1177, 'n_words': 250}