示例#1
0
        public void can_set_Implementation_on_instance_or_globally()
        {
            // global default
            Requestor.Global.Implementation = null;
            Requestor.DefaultIRequestor     = typeof(RequestorA);         // TODO move this to Requestor.Global, cause that's where everything else is ...
            new Requestor().Get("/").Body.ShouldEqual("RequestorA.GetResponse(GET, /)");

            // instance implementation
            var requestor = new Requestor();

            requestor.Implementation = new RequestorB();
            requestor.Get("/").Body.ShouldEqual("RequestorB.GetResponse(GET, /)");
            new Requestor().Get("/").Body.ShouldEqual("RequestorA.GetResponse(GET, /)");             // other instances still use A [the global default]

            // global implementation
            Requestor.Global.Implementation = new RequestorC();
            new Requestor().Get("/").Body.ShouldEqual("RequestorC.GetResponse(GET, /)");
            requestor = new Requestor();
            requestor.Get("/").Body.ShouldEqual("RequestorC.GetResponse(GET, /)");

            // override with instance implementation
            requestor.Implementation = new RequestorB();                                 // override global and set it back to B
            requestor.Get("/").Body.ShouldEqual("RequestorB.GetResponse(GET, /)");
            new Requestor().Get("/").Body.ShouldEqual("RequestorC.GetResponse(GET, /)"); // other instances still use C [the global implementation]
        }
示例#2
0
        public void can_FakeResponse_with_an_IResponse_globally()
        {
            var requestor = new Requestor(RootUrl);
            requestor.DisableRealRequests();
            Should.Throw<RealRequestsDisabledException>(() => requestor.Get("/"));

            Requestor.Global.FakeResponse("GET", "http://localhost:3000/", new Response {
                Status  = 400,
                Body    = "Something Global Blew Up",
                Headers = new Vars {{"Foo","Bar"}}
            });

            requestor.Get("/");
            requestor.LastResponse.Status.ShouldEqual(400);
            requestor.LastResponse.Body.ShouldEqual("Something Global Blew Up");
            requestor.LastResponse.Headers["Foo"].ShouldEqual("Bar");

            // works again, because no maximum number of requests was set ...
            requestor.Get("/");

            // blows up for any different url/path
            Should.Throw<RealRequestsDisabledException>("Real requests are disabled. GET http://localhost:3000/different", () => {
                requestor.Get("/different");
            });
        }
示例#3
0
        public void can_FakeResponse_with_an_IResponse_globally()
        {
            var requestor = new Requestor(RootUrl);

            requestor.DisableRealRequests();
            Should.Throw <RealRequestsDisabledException>(() => requestor.Get("/"));

            Requestor.Global.FakeResponse("GET", "http://localhost:3000/", new Response {
                Status  = 400,
                Body    = "Something Global Blew Up",
                Headers = new Vars {
                    { "Foo", "Bar" }
                }
            });

            requestor.Get("/");
            requestor.LastResponse.Status.ShouldEqual(400);
            requestor.LastResponse.Body.ShouldEqual("Something Global Blew Up");
            requestor.LastResponse.Headers["Foo"].ShouldEqual("Bar");

            // works again, because no maximum number of requests was set ...
            requestor.Get("/");

            // blows up for any different url/path
            Should.Throw <RealRequestsDisabledException>("Real requests are disabled. GET http://localhost:3000/different", () => {
                requestor.Get("/different");
            });
        }
示例#4
0
            public void can_override_for_an_instance()
            {
                new Requestor(RootUrl).Get("/").Body.ShouldEqual("Hello World");

                Requestor.Global.DisableRealRequests();
                var requestor = new Requestor(RootUrl);

                Should.Throw <RealRequestsDisabledException>("Real requests are disabled. GET http://localhost:3000/", () => {
                    requestor.Get("/");
                });

                requestor.EnableRealRequests();
                requestor.Get("/").Body.ShouldEqual("Hello World");
            }
        public virtual Account GetByTag(Connection connection = null, object userDefinedObjectForLogging = null)
        {
            connection = connection ?? Connection.CreateFromConfig();
            var rv = Requestor.Get <Account>(String.Format("account/getbytag/{0}/{1}", this.CustomerId, this.Tag), connection, userDefinedObjectForLogging);

            return(rv);
        }
        public virtual List <Account> List(Connection connection = null, object userDefinedObjectForLogging = null)
        {
            connection = connection ?? Connection.CreateFromConfig();
            var rv = Requestor.Get <List <Account> >(String.Format("account/list/{0}/{1}", this.CustomerId, this.AccountId), connection, userDefinedObjectForLogging);

            return(rv);
        }
示例#7
0
 /// <summary>
 /// Retrieves the details of an existing application. Supply the application ID and the API will return the corresponding application.
 /// </summary>
 /// <param name="id">Application id</param>
 public DividoGetApplicationResponse RetrieveApplication(string id)
 {
     return(Requestor.Get <DividoGetApplicationResponse>("applications", new Dictionary <string, string>()
     {
         { "id", id }
     }));
 }
示例#8
0
 /// <summary>
 /// Returns an array with all finance options available for merchant
 /// </summary>
 /// <param name="country">The country code</param>
 public DividoFinancesResponse Finances(string country = null)
 {
     return(Requestor.Get <DividoFinancesResponse>("finances", new Dictionary <string, string>()
     {
         { "country", country }
     }));
 }
示例#9
0
        public static List <Document> List(string cultureName, string documentType = null, Connection connection = null, object userDefinedObjectForLogging = null)
        {
            connection = connection ?? Connection.CreateFromConfig();
            var rv = Requestor.Get <List <Document> >(String.Format("document/list/{0}/{1}", cultureName, documentType), connection, userDefinedObjectForLogging);

            return(rv);
        }
        public virtual CustomerECode Get(Connection connection = null, object userDefinedObjectForLogging = null)
        {
            connection = connection ?? Connection.CreateFromConfig();
            var rv = Requestor.Get <CustomerECode>(String.Format("ecode/get/{0}/{1}", this.CustomerId, this.CustomerECodeId), connection, userDefinedObjectForLogging);

            return(rv);
        }
示例#11
0
        public static ExternalBank VerifyRoutingNumber(string routingNumber, Connection connection = null, object userDefinedObjectForLogging = null)
        {
            connection = connection ?? Connection.CreateFromConfig();
            var rv = Requestor.Get <ExternalBank>(String.Format("tools/verifyroutingnumber/{0}", routingNumber), connection, userDefinedObjectForLogging);

            return(rv);
        }
        public virtual ExternalAccount Get(Connection connection = null, object userDefinedObjectForLogging = null)
        {
            connection = connection ?? Connection.CreateFromConfig();
            var rv = Requestor.Get <ExternalAccount>(String.Format("externalaccount/get/{0}/{1}", this.CustomerId, this.ExternalAccountId), connection, userDefinedObjectForLogging);

            return(rv);
        }
示例#13
0
        public static Program Get(Connection connection = null, object userDefinedObjectForLogging = null)
        {
            connection = connection ?? Connection.CreateFromConfig();
            var rv = Requestor.Get <Program>("program/get", connection, userDefinedObjectForLogging);

            return(rv);
        }
示例#14
0
        public static FileContent Download(int customerId, int?statementId = null, Connection connection = null, object userDefinedObjectForLogging = null)
        {
            connection = connection ?? Connection.CreateFromConfig();
            var rv = Requestor.Get <FileContent>(String.Format("statement/download/{0}/{1}", customerId, statementId), connection, userDefinedObjectForLogging);

            return(rv);
        }
示例#15
0
        public static List <Statement> List(int customerId, Connection connection = null, object userDefinedObjectForLogging = null)
        {
            connection = connection ?? Connection.CreateFromConfig();
            var rv = Requestor.Get <List <Statement> >(String.Format("statement/list/{0}", customerId), connection, userDefinedObjectForLogging);

            return(rv);
        }
        public virtual List <CustomerBeneficiary> List(Connection connection = null, object userDefinedObjectForLogging = null)
        {
            connection = connection ?? Connection.CreateFromConfig();
            var rv = Requestor.Get <List <CustomerBeneficiary> >(String.Format("customerBeneficiary/list/{0}", this.CustomerId), connection, userDefinedObjectForLogging);

            return(rv);
        }
示例#17
0
        public void can_get_last_response()
        {
            var requestor = new Requestor(RootUrl);

            requestor.LastResponse.Should(Be.Null);

            requestor.Get("/");
            requestor.LastResponse.ShouldNot(Be.Null);
            requestor.LastResponse.Status.ShouldEqual(200);
            requestor.LastResponse.Body.ShouldEqual("Hello World");

            requestor.Get("/info");
            requestor.LastResponse.ShouldNot(Be.Null);
            requestor.LastResponse.Status.ShouldEqual(200);
            requestor.LastResponse.Body.ShouldContain("GET /info");
        }
        public static List <ECodeDocument> List(int?programECodeId, string documentType = null, string cultureName = null, Connection connection = null, object userDefinedObjectForLogging = null)
        {
            connection = connection ?? Connection.CreateFromConfig();
            var rv = Requestor.Get <List <ECodeDocument> >(String.Format("ecodedocument/list/{0}/{1}/{2}", programECodeId, documentType, cultureName), connection, userDefinedObjectForLogging);

            return(rv);
        }
        public virtual List <Customer> List(int?pageNumber, int?pageSize, Connection connection = null, object userDefinedObjectForLogging = null)
        {
            connection = connection ?? Connection.CreateFromConfig();
            var rv = Requestor.Get <List <Customer> >(String.Format("customer/list?pageNumber={0}&pageSize={1}", pageNumber, pageSize), connection, userDefinedObjectForLogging);

            return(rv);
        }
        public virtual List <SpacePayment> ListADocumentPayments(string documentId, string filter = null)
        {
            var filterObj = filter != null?JsonConvert.DeserializeObject(filter) : null;

            return(Mapper <SpacePayment> .MapCollectionFromJson(
                       Requestor.Get($"{Urls.Documents}/{documentId}/payments", filterObj)
                       ));
        }
示例#21
0
        public virtual List <SpaceCompany> Search(string term, string filter = null)
        {
            var filterObj = filter != null?JsonConvert.DeserializeObject(filter) : null;

            return(Mapper <SpaceCompany> .MapCollectionFromJson(
                       Requestor.Get($"{Urls.Companies}/search?term={term}", filterObj)
                       ));
        }
示例#22
0
        public virtual async Task <Account> Get(string id)
        {
            var url = string.Format(Urls.SpecificAccount, id);

            var response = await Requestor.Get(url);

            return(Mapper <Account> .MapFromJson(response));
        }
        // sync
        public virtual List <SpaceCountry> List(string filter = null)
        {
            var filterObj = filter != null?JsonConvert.DeserializeObject(filter) : null;

            return(Mapper <SpaceCountry> .MapCollectionFromJson(
                       Requestor.Get($"{Urls.Countries}", filterObj)
                       ));
        }
        public virtual List <SpaceOrganization> List(string accountId, string filter = null)
        {
            var filterObj = filter != null?JsonConvert.DeserializeObject(filter) : null;

            return(Mapper <SpaceOrganization> .MapCollectionFromJson(
                       Requestor.Get($"{Urls.Accounts}/{accountId}/organizations", filterObj)
                       ));
        }
示例#25
0
        public virtual async Task <Event> Get(string eventId)
        {
            var url = string.Format("{0}/{1}", Urls.Events, eventId);

            var response = await Requestor.Get(url);

            return(Mapper <Event> .MapFromJson(response));
        }
示例#26
0
        public ofOrganization GetDelegatee(string delegateeId, ofRequestOptions requestOptions)
        {
            requestOptions = SetupRequestOptions(requestOptions);

            var org = Requestor.Get <ofOrganization>(string.Format("{0}/{1}", Urls.Organizations, delegateeId), requestOptions);

            return(org);
        }
        public virtual SpaceDocument GetById(string documentId, string filter = null)
        {
            var filterObj = filter != null?JsonConvert.DeserializeObject(filter) : null;

            return(Mapper <SpaceDocument> .MapFromJson(
                       Requestor.Get($"{Urls.Documents}/{documentId}", filterObj)
                       ));
        }
示例#28
0
        public virtual ofOrganization Get(ofRequestOptions requestOptions = null)
        {
            requestOptions = SetupRequestOptions(requestOptions);

            var org = Requestor.Get <ofOrganization>(Urls.Organization, requestOptions);

            return(org);
        }
        public virtual Counter CountDocuments(string organizationId, string where = null)
        {
            var whereObj = where != null?JsonConvert.DeserializeObject(where) : null;

            return(Mapper <Counter> .MapFromJson(
                       Requestor.Get($"{Urls.Organizations}/{organizationId}/documents/count", whereObj)
                       ));
        }
        public virtual List <SpaceDocument> List(string organizationId, string filter = null)
        {
            var filterObj = filter != null?JsonConvert.DeserializeObject(filter) : null;

            return(Mapper <SpaceDocument> .MapCollectionFromJson(
                       Requestor.Get($"{Urls.Organizations}/{organizationId}/documents", filterObj)
                       ));
        }
        public virtual List <SpaceItem> Search(string organizationId, string term, string filter = null)
        {
            var filterObj = filter != null?JsonConvert.DeserializeObject(filter) : null;

            return(Mapper <SpaceItem> .MapCollectionFromJson(
                       Requestor.Get($"{Urls.Organizations}/{organizationId}/search-items?term={term}", filterObj)
                       ));
        }
示例#32
0
        public void can_specify_a_number_of_times_that_the_fake_response_should_be_returned()
        {
            var requestor = new Requestor(RootUrl);

            // once globally
            requestor.Get("/foo").Body.ShouldEqual("Not Found: GET /foo");
            Requestor.Global.FakeResponseOnce("GET", "http://localhost:3000/foo", new Response { Body = "Foo!" });
            requestor.Get("/foo").Body.ShouldEqual("Foo!");
            requestor.Get("/foo").Body.ShouldEqual("Not Found: GET /foo");

            // twice globally
            requestor.Get("/foo").Body.ShouldEqual("Not Found: GET /foo");
            Requestor.Global.FakeResponse(2, "GET", "http://localhost:3000/foo", new Response { Body = "Foo!" });
            requestor.Get("/foo").Body.ShouldEqual("Foo!");
            requestor.Get("/foo").Body.ShouldEqual("Foo!");
            requestor.Get("/foo").Body.ShouldEqual("Not Found: GET /foo");

            // once on instance
            requestor.Get("/foo").Body.ShouldEqual("Not Found: GET /foo");
            requestor.FakeResponseOnce("GET", "http://localhost:3000/foo", new Response { Body = "Foo!" });
            requestor.Get("/foo").Body.ShouldEqual("Foo!");
            requestor.Get("/foo").Body.ShouldEqual("Not Found: GET /foo");

            // 3 times on instance
            requestor.Get("/foo").Body.ShouldEqual("Not Found: GET /foo");
            requestor.FakeResponse(3, "GET", "http://localhost:3000/foo", new Response { Body = "Foo!" });
            requestor.Get("/foo").Body.ShouldEqual("Foo!");
            requestor.Get("/foo").Body.ShouldEqual("Foo!");
            requestor.Get("/foo").Body.ShouldEqual("Foo!");
            requestor.Get("/foo").Body.ShouldEqual("Not Found: GET /foo");

            // once globally, once on instance (both will happen)
            requestor.Get("/foo").Body.ShouldEqual("Not Found: GET /foo");
            Requestor.Global.FakeResponseOnce("GET", "http://localhost:3000/foo", new Response { Body = "Foo!" });
            requestor.FakeResponseOnce("GET", "http://localhost:3000/foo", new Response { Body = "Foo!" });
            requestor.Get("/foo").Body.ShouldEqual("Foo!");
            requestor.Get("/foo").Body.ShouldEqual("Foo!");
            requestor.Get("/foo").Body.ShouldEqual("Not Found: GET /foo");
        }
示例#33
0
        public void can_set_Implementation_on_instance_or_globally()
        {
            // global default
            Requestor.Global.Implementation = null;
            Requestor.DefaultIRequestor = typeof(RequestorA); // TODO move this to Requestor.Global, cause that's where everything else is ...
            new Requestor().Get("/").Body.ShouldEqual("RequestorA.GetResponse(GET, /)");

            // instance implementation
            var requestor = new Requestor();
            requestor.Implementation = new RequestorB();
            requestor.Get("/").Body.ShouldEqual("RequestorB.GetResponse(GET, /)");
            new Requestor().Get("/").Body.ShouldEqual("RequestorA.GetResponse(GET, /)"); // other instances still use A [the global default]

            // global implementation
            Requestor.Global.Implementation = new RequestorC();
            new Requestor().Get("/").Body.ShouldEqual("RequestorC.GetResponse(GET, /)");
            requestor = new Requestor();
            requestor.Get("/").Body.ShouldEqual("RequestorC.GetResponse(GET, /)");

            // override with instance implementation
            requestor.Implementation = new RequestorB(); // override global and set it back to B
            requestor.Get("/").Body.ShouldEqual("RequestorB.GetResponse(GET, /)");
            new Requestor().Get("/").Body.ShouldEqual("RequestorC.GetResponse(GET, /)"); // other instances still use C [the global implementation]
        }
示例#34
0
            public void can_override_for_an_instance()
            {
                new Requestor(RootUrl).Get("/").Body.ShouldEqual("Hello World");

                Requestor.Global.DisableRealRequests();
                var requestor = new Requestor(RootUrl);
                Should.Throw<RealRequestsDisabledException>("Real requests are disabled. GET http://localhost:3000/", () => {
                    requestor.Get("/");
                });

                requestor.EnableRealRequests();
                requestor.Get("/").Body.ShouldEqual("Hello World");
            }
示例#35
0
        public void FakeResponse_is_returned_even_if_real_requests_are_enabled()
        {
            var requestor = new Requestor(RootUrl);
            requestor.Get("/").Body.ShouldEqual("Hello World");
            requestor.Get("/foo").Body.ShouldEqual("Not Found: GET /foo");
            requestor.Get("/bar").Body.ShouldEqual("Not Found: GET /bar");

            // fake globally
            Requestor.Global.FakeResponse("GET", "http://localhost:3000/foo", new Response { Body = "Foo!" });
            requestor.Get("/").Body.ShouldEqual("Hello World");
            requestor.Get("/foo").Body.ShouldEqual("Foo!");
            requestor.Get("/bar").Body.ShouldEqual("Not Found: GET /bar");

            // override on instance
            requestor.FakeResponse("GET", "http://localhost:3000/foo", new Response { Body = "Foo via Instance" });
            requestor.Get("/").Body.ShouldEqual("Hello World");
            requestor.Get("/foo").Body.ShouldEqual("Foo via Instance");
            requestor.Get("/bar").Body.ShouldEqual("Not Found: GET /bar");
            new Requestor(RootUrl).Get("/foo").Body.ShouldEqual("Foo!"); // <--- new requestor uses the global fake response

            // fake another on instance
            requestor.FakeResponse("GET", "http://localhost:3000/bar", new Response { Body = "BAR" });
            requestor.Get("/").Body.ShouldEqual("Hello World");
            requestor.Get("/foo").Body.ShouldEqual("Foo via Instance");
            requestor.Get("/bar").Body.ShouldEqual("BAR");

            // if you disable real connections, the fake responses still work, but not the real ones ...
            requestor.DisableRealRequests();
            requestor.Get("/foo").Body.ShouldEqual("Foo via Instance");
            requestor.Get("/bar").Body.ShouldEqual("BAR");
            Should.Throw<RealRequestsDisabledException>("Real requests are disabled. GET http://localhost:3000/", () => {
                requestor.Get("/");
            });
        }
示例#36
0
        public void can_set_RootUrl_on_instance_or_globally()
        {
            var requestor = new Requestor();
            requestor.RootUrl.Should(Be.Null);

            // trying to do a GET to a relative path without a RootUrl will cause an exception
            var message = "HttpRequestor.GetResponse failed for: GET /foo.  This url generated a System.Net.FileWebRequest instead of a HttpWebRequest.";
            var response = requestor.Get("/foo"); // <--- this doesn't raise an exception, but returns null
            response.Should(Be.Null);
            requestor.LastException.Should(Be.AssignableFrom(typeof(Exception)));
            requestor.LastException.Message.ShouldContain(message);

            // if we switch to our SimpleRequestor, tho, we're OK
            Requestor.Global.Implementation = new SimpleRequestor();
            requestor.Get("/foo").Body.ShouldEqual("You requested: GET /foo"); // <-- no RootUrl

            // if we pass the full path, it works
            requestor.Get("http://localhost:3000/").Body.ShouldEqual("You requested: GET http://localhost:3000/");

            // set RootUrl globally
            Requestor.Global.RootUrl = "http://google.com";
            requestor.RootUrl.ShouldEqual("http://google.com");
            requestor.Get("/foo").Body.ShouldEqual("You requested: GET http://google.com/foo");

            // override on instance
            requestor.RootUrl = "http://yahoo.com";
            requestor.RootUrl.ShouldEqual("http://yahoo.com");
            requestor.Get("/foo").Body.ShouldEqual("You requested: GET http://yahoo.com/foo");
            new Requestor().Get("/foo").Body.ShouldEqual("You requested: GET http://google.com/foo"); // new still gets global

            // if we pass the full path, it still works, even with a RootUrl
            requestor.Get("http://localhost:3000/").Body.ShouldEqual("You requested: GET http://localhost:3000/");
        }
示例#37
0
        public void can_get_last_response()
        {
            var requestor = new Requestor(RootUrl);
            requestor.LastResponse.Should(Be.Null);

            requestor.Get("/");
            requestor.LastResponse.ShouldNot(Be.Null);
            requestor.LastResponse.Status.ShouldEqual(200);
            requestor.LastResponse.Body.ShouldEqual("Hello World");

            requestor.Get("/info");
            requestor.LastResponse.ShouldNot(Be.Null);
            requestor.LastResponse.Status.ShouldEqual(200);
            requestor.LastResponse.Body.ShouldContain("GET /info");
        }