public void HttpClientAuthorizeConfiguratorInstantiation_CreatesNewInstance_ShouldPass()
            {
                // Arrange
                var mockBase64Codec = new Mock <IBase64Codec>();

                // Act
                var newCfgratorInst = new HttpClientAuthorizeConfigurator(mockBase64Codec.Object);

                // Assert
                Assert.IsNotNull(newCfgratorInst);
                Assert.IsInstanceOfType(newCfgratorInst, typeof(HttpClientAuthorizeConfigurator));
            }
            public void HttpClientAuthCfg_IfReceivesNullHttpClient_ShouldThrow()
            {
                // Arrange
                var mockBase64Codec = new Mock <IBase64Codec>();
                var newCfgratorInst = new HttpClientAuthorizeConfigurator(mockBase64Codec.Object);

                // Act
                var result = newCfgratorInst.AddBasicAuthorizationHeaderValue(
                    null, "userName", "password");

                // Assert
                // should have thrown
            }
            public void HttpClientAuthCfg_AddBasicAuthHeaders_ReturnsTrue_ShouldPass()
            {
                // Arrange
                var httpClient      = new HttpClient();
                var base64codec     = new Base64Codec();
                var newCfgratorInst = new HttpClientAuthorizeConfigurator(base64codec);

                // Act
                var result = newCfgratorInst.AddBasicAuthorizationHeaderValue(
                    httpClient, "userName", "password");

                // Assert
                Assert.IsTrue(result);
            }
            public void HttpClientAuthCfg_IfReceivesNullOrWsPasswordParam_ShouldThrow()
            {
                // Arrange
                var mockBase64Codec = new Mock <IBase64Codec>();

                // HttpClient doesn't have an interface, so using a real instance
                var httpClient = new HttpClient();

                var newCfgratorInst = new HttpClientAuthorizeConfigurator(mockBase64Codec.Object);

                // Act
                var result = newCfgratorInst.AddBasicAuthorizationHeaderValue(
                    httpClient, "userName", " ");

                // Assert
                // should have thrown
            }
            public void HttpClientAuthCfg_AddBasicAuthHeaders_HasAddedBasicAuthorizationHdrs_ShouldPass()
            {
                // Arrange
                var httpClient      = new HttpClient();
                var base64codec     = new Base64Codec();
                var newCfgratorInst = new HttpClientAuthorizeConfigurator(base64codec);

                // Act
                var result = newCfgratorInst.AddBasicAuthorizationHeaderValue(
                    httpClient, "userName", "password");

                var encodedAuthValue = httpClient.DefaultRequestHeaders.Authorization;
                var decodedAuthKey   = base64codec.Decode(encodedAuthValue.Parameter);
                var scheme           = encodedAuthValue.Scheme;

                // Assert
                Assert.IsTrue(result);
                Assert.AreEqual("userName:password", decodedAuthKey);
                Assert.AreEqual("Basic", scheme);
            }
示例#6
0
        public void InstantiationOf_GitHubApiCallServices_WithAnyNullParameter_ShouldThrow()
        {
            // Arrange
            var mockHttpClientProvider = new Mock <IHttpClientProvider>();
            HttpClientAuthorizeConfigurator mockHCAuthConfigr = null;
            var mockGHReposSvc = new Mock <IGitHubRepos>();
            var mockGHPRsSvc   = new Mock <IGitHubPullReqs>();

            // Act
            GitHubApiCallServices apiCallServices = new GitHubApiCallServices(
                mockHttpClientProvider.Object,
                // ReSharper disable once ExpressionIsAlwaysNull
                mockHCAuthConfigr,
                mockGHReposSvc.Object,
                mockGHPRsSvc.Object,
                mockCredentialsReader.Object);

            // Assert
            // Should throw, so nothing here.
        }