/// <exclude/>
        async protected Task <T> MakeApiGetRequestAsync <T>(Uri uri, ICompanyFileCredentials credentials, CancellationToken cancellationToken) where T : class
        {
            await RenewOAuthTokensAsync(cancellationToken);

            var api  = new ApiRequestHandler(Configuration, credentials, GetOAuthResponse());
            var data = await api.GetAsync <T>(this.WebRequestFactory.Create(uri), cancellationToken);

            return(data.Item2);
        }
        async public void DuringGetRequest_Async_ExpectedHeadersAreAttached(bool supplyCredentials, bool supplyOAuth)
        {
            // arrange
            var factory = new TestWebRequestFactory();
            factory.RegisterResultForUri("http://localhost", new UserContract() { Name = "David" }.ToJson());
            var request = factory.Create(new Uri("http://localhost"));

            var handler = new ApiRequestHandler(new ApiConfiguration("<<clientid>>", "<<clientsecret>>", "<<redirecturl>>"),
                supplyCredentials ? new CompanyFileCredentials("user", "pass") : null, supplyOAuth ? new OAuthTokens() : null);

            // act
            var res = await handler.GetAsync<UserContract>(request, null);

            // assert
            AssertStandardHeaders(supplyCredentials, supplyOAuth, request);
            Assert.IsNull(request.Headers[HttpRequestHeader.IfNoneMatch]);
        }
        async public Task DuringGetRequest_Async_IfNoneMatchHeaderAttached_IfSupplyETag()
        {
            // arrange
            var eTag    = "123456789";
            var factory = new TestWebRequestFactory();

            factory.RegisterResultForUri("http://localhost", new UserContract()
            {
                Name = "David"
            }.ToJson());
            var request = factory.Create(new Uri("http://localhost"));

            var handler = new ApiRequestHandler(new ApiConfiguration("<<clientid>>", "<<clientsecret>>", "<<redirecturl>>"), new CompanyFileCredentials("user", "pass"));

            // act
            var res = await handler.GetAsync <UserContract>(request, eTag);

            // assert
            Assert.AreEqual(eTag, request.Headers[HttpRequestHeader.IfNoneMatch]);
        }
        async public void DuringGetRequest_Async_ExpectedHeadersAreAttached()
        {
            // arrange
            var factory = new TestWebRequestFactory();
            factory.RegisterResultForUri("http://localhost", new UserContract() { Name = "David" }.ToJson());
            var request = factory.Create(new Uri("http://localhost"));

            var handler = new ApiRequestHandler(new ApiConfiguration("<<clientid>>", "<<clientsecret>>", "<<redirecturl>>"), new CompanyFileCredentials("user", "pass"));

            // act
            var res = await handler.GetAsync<UserContract>(request);

            // assert
            Assert.IsTrue(request.Headers[HttpRequestHeader.Authorization].StartsWith("Bearer"));
            Assert.IsTrue(request.Headers[HttpRequestHeader.AcceptEncoding].Split(new[] { ',' }).Contains("gzip"));

            Assert.AreEqual("<<clientid>>", request.Headers["x-myobapi-key"]);
            Assert.AreEqual("v2", request.Headers["x-myobapi-version"]);
            Assert.AreEqual(Convert.ToBase64String(Encoding.UTF8.GetBytes("user:pass")), request.Headers["x-myobapi-cftoken"]);
        }
        async public Task DuringGetRequest_Async_ExpectedHeadersAreAttached(bool supplyCredentials, bool supplyOAuth)
        {
            // arrange
            var factory = new TestWebRequestFactory();

            factory.RegisterResultForUri("http://localhost", new UserContract()
            {
                Name = "David"
            }.ToJson());
            var request = factory.Create(new Uri("http://localhost"));

            var handler = new ApiRequestHandler(new ApiConfiguration("<<clientid>>", "<<clientsecret>>", "<<redirecturl>>"),
                                                supplyCredentials ? new CompanyFileCredentials("user", "pass") : null, supplyOAuth ? new OAuthTokens() : null);

            // act
            var res = await handler.GetAsync <UserContract>(request, null);

            // assert
            AssertStandardHeaders(supplyCredentials, supplyOAuth, request);
            Assert.IsNull(request.Headers[HttpRequestHeader.IfNoneMatch]);
        }
예제 #6
0
        async public void DuringGetRequest_Async_ExpectedHeadersAreAttached()
        {
            // arrange
            var factory = new TestWebRequestFactory();

            factory.RegisterResultForUri("http://localhost", new UserContract()
            {
                Name = "David"
            }.ToJson());
            var request = factory.Create(new Uri("http://localhost"));

            var handler = new ApiRequestHandler(new ApiConfiguration("<<clientid>>", "<<clientsecret>>", "<<redirecturl>>"), new CompanyFileCredentials("user", "pass"));

            // act
            var res = await handler.GetAsync <UserContract>(request);

            // assert
            Assert.IsTrue(request.Headers[HttpRequestHeader.Authorization].StartsWith("Bearer"));
            Assert.IsTrue(request.Headers[HttpRequestHeader.AcceptEncoding].Split(new[] { ',' }).Contains("gzip"));

            Assert.AreEqual("<<clientid>>", request.Headers["x-myobapi-key"]);
            Assert.AreEqual("v2", request.Headers["x-myobapi-version"]);
            Assert.AreEqual(Convert.ToBase64String(Encoding.UTF8.GetBytes("user:pass")), request.Headers["x-myobapi-cftoken"]);
        }
        async public void DuringGetRequest_Async_IfNoneMatchHeaderAttached_IfSupplyETag()
        {
            // arrange
            var eTag = "123456789";
            var factory = new TestWebRequestFactory();
            factory.RegisterResultForUri("http://localhost", new UserContract() { Name = "David" }.ToJson());
            var request = factory.Create(new Uri("http://localhost"));

            var handler = new ApiRequestHandler(new ApiConfiguration("<<clientid>>", "<<clientsecret>>", "<<redirecturl>>"), new CompanyFileCredentials("user", "pass"));

            // act
            var res = await handler.GetAsync<UserContract>(request, eTag);

            // assert
            Assert.AreEqual(eTag, request.Headers[HttpRequestHeader.IfNoneMatch]);
        }