async public Task TheEntityIsPlacedOnTheOutgoingStreamInJsonFormatDuringPostAsync()
        {
            // arrange
            var factory = new TestWebRequestFactory();

            factory.RegisterResultForUri("http://localhost", "");
            var request = factory.Create(new Uri("http://localhost"));

            var stream = new MemoryStream();

#pragma warning disable 1998
            request.GetRequestStreamAsync().Returns(async c => (Stream)stream);
#pragma warning restore 1998

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

            // act
            await handler.PostAsync(request, new UserContract()
            {
                Name = "Paul"
            });

            // assert
            var reader = new StreamReader(new MemoryStream(stream.ToArray()));
            var data   = reader.ReadToEnd().FromJson <UserContract>();

            Assert.AreEqual("Paul", data.Name);
        }
        public void DuringGetRequestExpectedHeadersAreAttached(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
            handler.Get <UserContract>(request, (code, response) => { }, (uri, exception) => Assert.Fail(exception.Message), null);

            // assert
            AssertStandardHeaders(supplyCredentials, supplyOAuth, request);

            var version   = typeof(ApiRequestHandler).Assembly.GetName().Version.ToString(3);
            var userAgent = request.Headers[HttpRequestHeader.UserAgent];

            Assert.IsTrue(userAgent.Contains(string.Format("MYOB-ARL-SDK/{0}", version)));
            Assert.IsNull(request.Headers[HttpRequestHeader.IfNoneMatch]);
        }
        public void TheLocationIsReturnedAfterASuccesfulPut()
        {
            // arrange
            var factory = new TestWebRequestFactory();

            factory.RegisterResultForUri("http://localhost", "", HttpStatusCode.OK, "http://localhost/ABC");
            var request = factory.Create(new Uri("http://localhost"));

            var stream = new MemoryStream();

            request.EndGetRequestStream(Arg.Any <IAsyncResult>()).Returns(c => stream);

            var    handler       = new ApiRequestHandler(new ApiConfiguration("<<clientid>>", "<<clientsecret>>", "<<redirecturl>>"), null);
            string savedLocation = null;

            // act
            handler.Put(request, new UserContract()
            {
                Name = "Paul"
            }, (code, location) =>
                        { savedLocation = location; }, (uri, exception) => Assert.Fail(exception.Message));

            // assert
            Assert.AreEqual("http://localhost/ABC", savedLocation);
        }
Esempio n. 4
0
        async public void DuringPostRequest_Async_ExpectedHeadersAreAttached()
        {
            // arrange
            var factory = new TestWebRequestFactory();

            factory.RegisterResultForUri("http://localhost", "");
            var request = factory.Create(new Uri("http://localhost"));

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

            // act
            await handler.PostAsync(request, new UserContract()
            {
                Name = "Paul"
            });

            // assert
            Assert.AreEqual("POST", request.Method);
            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"]);
        }
        public void TheEntityIsPlacedOnTheOutgoingStreamInJsonFormatDuringPost()
        {
            // arrange
            var factory = new TestWebRequestFactory();

            factory.RegisterResultForUri("http://localhost", "");
            var request = factory.Create(new Uri("http://localhost"));

            var stream = new MemoryStream();

            request.EndGetRequestStream(Arg.Any <IAsyncResult>()).Returns(c => stream);

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

            // act
            handler.Post(request, new UserContract()
            {
                Name = "Paul"
            }, (code, location) => { }, (uri, exception) => Assert.Fail(exception.Message));

            // assert
            var reader = new StreamReader(new MemoryStream(stream.ToArray()));
            var data   = reader.ReadToEnd().FromJson <UserContract>();

            Assert.AreEqual("Paul", data.Name);
        }
        public void SetUp()
        {
            var uri = OAuthRequestHandler.OAuthRequestUri;
            var factory = new TestWebRequestFactory();
            factory.RegisterResultForUri(uri.AbsoluteUri, "null");
            _request = factory.Create(uri);

            _stream = new MemoryStream();
            _request.EndGetRequestStream(Arg.Any<IAsyncResult>()).Returns(c => _stream);
            _request.GetRequestStreamAsync().Returns(async c => (Stream)_stream);

            _handler = new OAuthRequestHandler(new ApiConfiguration("<<clientid>>", "<<clientsecret>>", "http://desktop/"));

        }
Esempio n. 7
0
        public void SetUp()
        {
            var uri     = OAuthRequestHandler.OAuthRequestUri;
            var factory = new TestWebRequestFactory();

            factory.RegisterResultForUri(uri.AbsoluteUri, "null");
            _request = factory.Create(uri);

            _stream = new MemoryStream();
            _request.EndGetRequestStream(Arg.Any <IAsyncResult>()).Returns(c => _stream);
            _request.GetRequestStreamAsync().Returns(async c => (Stream)_stream);

            _handler = new OAuthRequestHandler(new ApiConfiguration("<<clientid>>", "<<clientsecret>>", "http://desktop/"));
        }
        public void DuringGetRequest_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
            handler.Get<UserContract>(request, (code, response) => { }, (uri, exception) => Assert.Fail(exception.Message), eTag);

            // assert
            Assert.AreEqual(eTag, request.Headers[HttpRequestHeader.IfNoneMatch]);
        }
        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 DuringDeleteRequest_Async_ExpectedHeadersAreAttached(bool supplyCredentials, bool supplyOAuth)
        {
            // arrange
            var factory = new TestWebRequestFactory();

            factory.RegisterResultForUri("http://localhost", "");
            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
            await handler.DeleteAsync(request);

            // assert
            Assert.AreEqual("DELETE", request.Method);
            AssertStandardHeaders(supplyCredentials, supplyOAuth, request);
        }
        public void PutAsyncRequest_Return_Response()
        {
            // arrange
            var expected = new ExpectedResult {
                UID = Guid.NewGuid()
            };
            var factory = new TestWebRequestFactory();

            factory.RegisterResultForUri("http://localhost", expected.ToJson());
            var request = factory.Create(new Uri("http://localhost"));

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

            // act
            var receivedEntity = handler.PutAsync <Parameter, ExpectedResult>(request, new Parameter()).Result;

            // assert
            Assert.AreEqual(expected.UID, receivedEntity.UID);
        }
        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_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]);
        }
        public void DuringDeleteRequestExpectedHeadersAreAttached()
        {
            // arrange
            var factory = new TestWebRequestFactory();
            factory.RegisterResultForUri("http://localhost", "");
            var request = factory.Create(new Uri("http://localhost"));

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

            // act
            handler.Delete(request, (code) => { }, (uri, exception) => Assert.Fail(exception.Message));

            // assert
            Assert.AreEqual("DELETE", request.Method);
            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]);
        }
        public void AuthorizationHeaderNotAppliedWhenClientCertificateAttached()
        {
            // arrange
            var factory = new TestWebRequestFactory();

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

            (request as HttpWebRequest).ClientCertificates.Add(new X509Certificate());

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

            // act
            handler.Get <UserContract>(request, (code, response) => { }, (uri, exception) => Assert.Fail(exception.Message), null);

            // assert
            Assert.IsNull(request.Headers[HttpRequestHeader.Authorization]);
        }
        public void PostRequest_Return_Response()
        {
            // arrange
            var expected = new ExpectedResult {
                UID = Guid.NewGuid()
            };
            var factory = new TestWebRequestFactory();

            factory.RegisterResultForUri("http://localhost", expected.ToJson());
            var request = factory.Create(new Uri("http://localhost"));

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

            // act
            ExpectedResult receivedEntity = null;

            handler.Post <Parameter, ExpectedResult>(request, new Parameter(), (code, location, response) => { receivedEntity = response; }, (uri, exception) => Assert.Fail(exception.Message));

            // assert
            Assert.AreEqual(expected.UID, receivedEntity.UID);
        }
        public void DuringPostRequestExpectedHeadersAreAttached(bool supplyCredentials, bool supplyOAuth)
        {
            // arrange
            var factory = new TestWebRequestFactory();

            factory.RegisterResultForUri("http://localhost", "");
            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
            handler.Post(request, new UserContract()
            {
                Name = "Paul"
            }, (code, location) => { }, (uri, exception) => Assert.Fail(exception.Message));

            // assert
            Assert.AreEqual("POST", request.Method);
            AssertStandardHeaders(supplyCredentials, supplyOAuth, request);
        }
        public void DuringGetRequestExpectedHeadersAreAttached(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
            handler.Get<UserContract>(request, (code, response) => { }, (uri, exception) => Assert.Fail(exception.Message), null);

            // assert
            AssertStandardHeaders(supplyCredentials, supplyOAuth, request);

            var version = typeof (ApiRequestHandler).Assembly.GetName().Version.ToString(3);
            var userAgent = request.Headers[HttpRequestHeader.UserAgent];
            Assert.IsTrue(userAgent.Contains(string.Format("MYOB-ARL-SDK/{0}", version)));
            Assert.IsNull(request.Headers[HttpRequestHeader.IfNoneMatch]);
        }
Esempio n. 20
0
        public void DuringDeleteRequestExpectedHeadersAreAttached()
        {
            // arrange
            var factory = new TestWebRequestFactory();

            factory.RegisterResultForUri("http://localhost", "");
            var request = factory.Create(new Uri("http://localhost"));

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

            // act
            handler.Delete(request, (code) => { }, (uri, exception) => Assert.Fail(exception.Message));

            // assert
            Assert.AreEqual("DELETE", request.Method);
            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 TheLocationIsReturnedAfterASuccesfulPutAsync()
        {
            // arrange
            var factory = new TestWebRequestFactory();

            factory.RegisterResultForUri("http://localhost", "", HttpStatusCode.OK, "http://localhost/ABC");
            var request = factory.Create(new Uri("http://localhost"));

            var stream = new MemoryStream();

            request.EndGetRequestStream(Arg.Any <IAsyncResult>()).Returns(c => stream);

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

            // act
            var res = await handler.PutAsync(request, new UserContract()
            {
                Name = "Paul"
            });

            // assert
            Assert.AreEqual("http://localhost/ABC", res);
        }
        public void PostRequest_Return_Response()
        {
            // arrange
            var expected = new ExpectedResult { UID = Guid.NewGuid() };
            var factory = new TestWebRequestFactory();
            factory.RegisterResultForUri("http://localhost", expected.ToJson());
            var request = factory.Create(new Uri("http://localhost"));

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

            // act
            ExpectedResult receivedEntity = null;
            handler.Post<Parameter, ExpectedResult>(request, new Parameter(), (code, location, response) => { receivedEntity = response; }, (uri, exception) => Assert.Fail(exception.Message));

            // assert
            Assert.AreEqual(expected.UID, receivedEntity.UID);
        }
        public void AuthorizationHeaderNotAppliedWhenClientCertificateAttached()
        {
            // arrange
            var factory = new TestWebRequestFactory();
            factory.RegisterResultForUri("http://localhost", new UserContract() { Name = "David" }.ToJson());
            var request = factory.Create(new Uri("http://localhost"));
            (request as HttpWebRequest).ClientCertificates.Add(new X509Certificate());

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

            // act
            handler.Get<UserContract>(request, (code, response) => { }, (uri, exception) => Assert.Fail(exception.Message), null);

            // assert
            Assert.IsNull(request.Headers[HttpRequestHeader.Authorization]);
        }
        async public void TheLocationIsReturnedAfterASuccesfulPutAsync()
        {
            // arrange
            var factory = new TestWebRequestFactory();
            factory.RegisterResultForUri("http://localhost", "", HttpStatusCode.OK, "http://localhost/ABC");
            var request = factory.Create(new Uri("http://localhost"));

            var stream = new MemoryStream();
            request.EndGetRequestStream(Arg.Any<IAsyncResult>()).Returns(c => stream);

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

            // act
            var res = await handler.PutAsync(request, new UserContract() { Name = "Paul" });

            // assert
            Assert.AreEqual("http://localhost/ABC", res);
        }
Esempio n. 25
0
        public void GetPdf_UsesCorrectMimeType_ToCreate_WebRequestObject(
            [ValueSource("_getFormPdfActions")] Tuple <string, Func <TestInvoiceService, CompanyFile, Stream> > action)
        {
            // arrange
            var cf = new CompanyFile {
                Uri = new Uri("https://dc1.api.myob.com/accountright/7D5F5516-AF68-4C5B-844A-3F054E00DF10")
            };
            var stream = new MemoryStream(new byte[] { 0, 1, 2, 3 });
            var uri    = cf.Uri.AbsoluteUri + "/" + Route + "/" + _uid + "?templatename=tn";

            _webFactory.RegisterResultForUri(uri, stream);

            var webRequestFactory = Substitute.For <IWebRequestFactory>();

            webRequestFactory.Create(Arg.Any <Uri>(), Arg.Any <string>()).Returns(x => _webFactory.Create((Uri)x[0], (string)x[1]));

            var iis = new TestInvoiceService(_configuration, webRequestFactory, null);

            // Act
            action.Item2(iis, cf);

            // assert
            webRequestFactory.Received(1).Create(Arg.Any <Uri>(), "application/pdf");
        }
        public void TheLocationIsReturnedAfterASuccesfulPut()
        {
            // arrange
            var factory = new TestWebRequestFactory();
            factory.RegisterResultForUri("http://localhost", "", HttpStatusCode.OK, "http://localhost/ABC");
            var request = factory.Create(new Uri("http://localhost"));

            var stream = new MemoryStream();
            request.EndGetRequestStream(Arg.Any<IAsyncResult>()).Returns(c => stream);

            var handler = new ApiRequestHandler(new ApiConfiguration("<<clientid>>", "<<clientsecret>>", "<<redirecturl>>"), null);
            string savedLocation = null;

            // act
            handler.Put(request, new UserContract() { Name = "Paul" }, (code, location) =>
            { savedLocation = location; }, (uri, exception) => Assert.Fail(exception.Message));

            // assert
            Assert.AreEqual("http://localhost/ABC", savedLocation);
        }
        async public void TheEntityIsPlacedOnTheOutgoingStreamInJsonFormatDuringPostAsync()
        {
            // arrange
            var factory = new TestWebRequestFactory();
            factory.RegisterResultForUri("http://localhost", "");
            var request = factory.Create(new Uri("http://localhost"));

            var stream = new MemoryStream();
            request.GetRequestStreamAsync().Returns(async c => (Stream)stream);

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

            // act
            await handler.PostAsync(request, new UserContract() { Name = "Paul" });

            // assert
            var reader = new StreamReader(new MemoryStream(stream.ToArray()));
            var data = reader.ReadToEnd().FromJson<UserContract>();

            Assert.AreEqual("Paul", data.Name);
        }
        public void TheEntityIsPlacedOnTheOutgoingStreamInJsonFormatDuringPost()
        {
            // arrange
            var factory = new TestWebRequestFactory();
            factory.RegisterResultForUri("http://localhost", "");
            var request = factory.Create(new Uri("http://localhost"));

            var stream = new MemoryStream();
            request.EndGetRequestStream(Arg.Any<IAsyncResult>()).Returns(c => stream);

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

            // act
            handler.Post(request, new UserContract() { Name = "Paul" }, (code, location) => { }, (uri, exception) => Assert.Fail(exception.Message));

            // assert
            var reader = new StreamReader(new MemoryStream(stream.ToArray()));
            var data = reader.ReadToEnd().FromJson<UserContract>();

            Assert.AreEqual("Paul", data.Name);
        }
        public void PutAsyncRequest_Return_Response()
        {
            // arrange
            var expected = new ExpectedResult { UID = Guid.NewGuid() };
            var factory = new TestWebRequestFactory();
            factory.RegisterResultForUri("http://localhost", expected.ToJson());
            var request = factory.Create(new Uri("http://localhost"));

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

            // act
            var receivedEntity = handler.PutAsync<Parameter, ExpectedResult>(request, new Parameter()).Result;

            // assert
            Assert.AreEqual(expected.UID, receivedEntity.UID);
        }
        async public void DuringPostRequest_Async_ExpectedHeadersAreAttached(bool supplyCredentials, bool supplyOAuth)
        {
            // arrange
            var factory = new TestWebRequestFactory();
            factory.RegisterResultForUri("http://localhost", "");
            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
            await handler.PostAsync(request, new UserContract() { Name = "Paul" });

            // assert
            Assert.AreEqual("POST", request.Method);
            AssertStandardHeaders(supplyCredentials, supplyOAuth, request);
        }
        public void DuringDeleteRequestExpectedHeadersAreAttached(bool supplyCredentials, bool supplyOAuth)
        {
            // arrange
            var factory = new TestWebRequestFactory();
            factory.RegisterResultForUri("http://localhost", "");
            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
            handler.Delete(request, (code) => { }, (uri, exception) => Assert.Fail(exception.Message));

            // assert
            Assert.AreEqual("DELETE", request.Method);
            AssertStandardHeaders(supplyCredentials, supplyOAuth, request);
        }