コード例 #1
0
        public void ShouldThrowWhenReturnedContentIsNotABoolean()
        {
            OkHttpResponse.Content = HttpContent.Create("not a bool");
            MockedHttpClientAdapter.Setup(hca => hca.GetHttpClient(It.IsAny <string>())).Returns(MockedHttpClient.Object);
            MockedHttpClient.Setup(hc => hc.Get(It.IsAny <string>())).Returns(OkHttpResponse);

            TestDelegate methodThatShouldThrow = () => PackageAuthenticator.EnsureKeyCanAccessPackage("key", "packageId", "packageVersion");

            Assert.Throws <PackageAuthorizationException>(methodThatShouldThrow, "Should have thrown when reponse returned non-boolean.");
        }
コード例 #2
0
        public void ShouldNotThrowWhenTrueReturnedFromResponse()
        {
            OkHttpResponse.Content = HttpContent.Create("true");
            MockedHttpClientAdapter.Setup(hca => hca.GetHttpClient(It.IsAny <string>())).Returns(MockedHttpClient.Object);
            MockedHttpClient.Setup(hc => hc.Get(It.IsAny <string>())).Returns(OkHttpResponse);

            TestDelegate methodThatShouldThrow = () => PackageAuthenticator.EnsureKeyCanAccessPackage("key", "packageId", "packageVersion");

            Assert.DoesNotThrow(methodThatShouldThrow, "Should not have thrown when reponse returned true.");
        }
コード例 #3
0
        public void ShouldThrowWhenGivenResponseReturnedBadRequest()
        {
            var response = new HttpResponseMessage {
                StatusCode = HttpStatusCode.BadRequest
            };

            MockedHttpClientAdapter.Setup(hca => hca.GetHttpClient(It.IsAny <string>())).Returns(MockedHttpClient.Object);
            MockedHttpClient.Setup(hc => hc.Get(It.IsAny <string>())).Returns(response);

            TestDelegate methodThatShouldThrow = () => PackageAuthenticator.EnsureKeyCanAccessPackage("key", "packageId", "packageVersion");

            Assert.Throws <Exception>(methodThatShouldThrow, "Should have thrown when reponse returned not-OK status code.");
        }
コード例 #4
0
        public void ShouldUseFrontEndWebSiteRootForHttpClient()
        {
            const string expectedWebSiteRoot = "web site root";

            MockedConfigSettings.SetupGet(cs => cs.FrontEndWebSiteRoot).Returns(expectedWebSiteRoot);
            MockedHttpClientAdapter.Setup(hca => hca.GetHttpClient(It.IsAny <string>())).Returns(MockedHttpClient.Object);
            MockedHttpClient.Setup(hc => hc.Get(It.IsAny <string>())).Returns(OkHttpResponse);

            PackageAuthenticator.EnsureKeyCanAccessPackage("key", "packageId", "packageVersion");

            MockedHttpClientAdapter.Verify(hca => hca.GetHttpClient(expectedWebSiteRoot), Times.Once(),
                                           "Should have called HttpClientAdpater's GetHttpClient() with expected web site root.");
        }
コード例 #5
0
        public void ShouldPutValidatePackageKeyUriAndParametersInRequestUri()
        {
            const string expectedValidatePackageKeyUri = "foo";
            const string key            = "asdf";
            const string packageId      = "packageId";
            const string packageVersion = "packageVersion";
            string       expectedUri    = string.Format("{0}/{1}/{2}/{3}", expectedValidatePackageKeyUri, key, packageId, packageVersion);

            MockedConfigSettings.SetupGet(cs => cs.ValidatePackageKeyUri).Returns(expectedValidatePackageKeyUri);
            MockedHttpClientAdapter.Setup(hca => hca.GetHttpClient(It.IsAny <string>())).Returns(MockedHttpClient.Object);
            MockedHttpClient.Setup(hc => hc.Get(It.IsAny <string>())).Returns(OkHttpResponse);

            PackageAuthenticator.EnsureKeyCanAccessPackage(key, packageId, packageVersion);

            MockedHttpClient.Verify(hc => hc.Get(expectedUri), Times.Once(),
                                    string.Format("Should have called HttpClient's Get() with expected URI '{0}'.", expectedUri));
        }