public ActionResult OnGet()
        {
            var url = _api.Authorize(Strings.StateKey);

            _logger.LogInformation("Auth is redirecting to [{page}]", url);
            return(Redirect(url));
        }
        public void Authorize_Returns_Expected_Uri()
        {
            // Arrange
            var credentials         = MockInstagramCredentials();
            var options             = Options.Create(credentials);
            var logger              = Mock.Of <ILogger <InstagramApi> >();
            var mockFactory         = MockHttpClientFactory();
            var instagramHttpClient = new InstagramHttpClient(options, mockFactory.Object, logger);

            // Act
            const string state = "";
            var          api   = new InstagramApi(options, logger, instagramHttpClient);
            var          url   = api.Authorize(state);

            // Assert
            Assert.NotNull(api);
            Assert.NotNull(url);

            var uri = new Uri(url);

            Assert.NotNull(uri);

            Assert.Equal("api.instagram.com", uri.Authority);
            Assert.Equal("https", uri.Scheme);
            Assert.Equal("api.instagram.com", uri.Host);
            Assert.Equal($"?client_id={credentials.ClientId}&redirect_uri={credentials.RedirectUrl}&scope=user_profile,user_media&response_type=code&state={state}", uri.Query);
            Assert.Equal($"/oauth/authorize?client_id={credentials.ClientId}&redirect_uri={credentials.RedirectUrl}&scope=user_profile,user_media&response_type=code&state={state}", uri.PathAndQuery);
        }
        public void Authorize_Without_ClientId_In_InstagramSettings_ThrowsException()
        {
            // Arrange
            var credentials = MockInstagramCredentials();

            credentials.ClientId = null;

            var options             = Options.Create(credentials);
            var logger              = Mock.Of <ILogger <InstagramApi> >();
            var mockFactory         = MockHttpClientFactory();
            var instagramHttpClient = new InstagramHttpClient(options, mockFactory.Object, logger);

            // Act
            var api = new InstagramApi(options, logger, instagramHttpClient);
            var ex  = Assert.Throws <ArgumentNullException>(() => api.Authorize(""));

            // Assert
            const string expected = "The ClientId is either null or empty please check the InstagramCredentials section in your appsettings.json (Parameter 'ClientId')";
            var          actual   = ex.Message;

            Assert.NotNull(api);
            Assert.Equal(expected, actual);
        }