Skip to content

Commit

Permalink
Crankshaft[BU00000492E746] .NET client @ 2017-08-23 14:15:16 UTC
Browse files Browse the repository at this point in the history
  • Loading branch information
Crankshaft Robot committed Aug 23, 2017
1 parent 5251e2a commit e4fd3b9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
39 changes: 34 additions & 5 deletions GoCardless.Tests/MandateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,39 @@ public async Task ShouldListMandatesForACustomer()
Assert.AreEqual("MD00001P57AN84", mandates[1].Id);
Assert.AreEqual("CR000035EME9H5", mandates[1].Links.Creditor);
mockHttp.AssertRequestMade("GET",
"/mandates?created_at[gt]=2017-05-02T11:12:13.0000000-05:00&customer=CU00003068FG73");
"/mandates?created_at%5Bgt%5D=2017-05-02T11%3A12%3A13.0000000-05%3A00&customer=CU00003068FG73");
}

[Test]
public async Task ShouldListMandatesForAUtcDateTimeFilter()
{
var responseFixture = "fixtures/client/list_mandates_for_a_customer.json";
mockHttp.EnqueueResponse(200, responseFixture);
var mandateListRequest = new MandateListRequest()
{
CreatedAt = new MandateListRequest.CreatedAtParam
{
LessThan = DateTime.SpecifyKind(new DateTime(2017, 8, 23, 11, 09, 07), DateTimeKind.Utc)
}
};
var listResponse = await client.Mandates.ListAsync(mandateListRequest);
mockHttp.AssertRequestMade("GET", "/mandates?created_at%5Blt%5D=2017-08-23T11%3A09%3A07.0000000%2B00%3A00");
}

[Test]
public async Task ShouldListMandatesForADateTimeFilterWithPositiveOffset()
{
var responseFixture = "fixtures/client/list_mandates_for_a_customer.json";
mockHttp.EnqueueResponse(200, responseFixture);
var mandateListRequest = new MandateListRequest()
{
CreatedAt = new MandateListRequest.CreatedAtParam
{
LessThan = new DateTimeOffset(2017, 8, 23, 11, 09, 07, TimeSpan.FromHours(1))
}
};
var listResponse = await client.Mandates.ListAsync(mandateListRequest);
mockHttp.AssertRequestMade("GET", "/mandates?created_at%5Blt%5D=2017-08-23T11%3A09%3A07.0000000%2B01%3A00");
}

[Test]
Expand All @@ -64,10 +96,9 @@ public void ShouldListMandatesByCustomerAndStatus()

Assert.AreEqual(mandates.Count, 1);
Assert.AreEqual(mandates[0].Id, "MD00001PEYCSQF");
mockHttp.AssertRequestMade("GET", "/mandates?customer=CU00003068FG73&status=active,failed");
mockHttp.AssertRequestMade("GET", "/mandates?customer=CU00003068FG73&status=active%2Cfailed");
}


[Test]
public void ShouldPageThroughMandates()
{
Expand Down Expand Up @@ -150,7 +181,5 @@ public async Task ShouldCreateAMandate()
var mandate = mandateResponse.Mandate;
mockHttp.AssertRequestMade("POST", "/mandates", "fixtures/client/create_a_mandate_request.json");
}


}
}
11 changes: 7 additions & 4 deletions GoCardless/GoCardlessClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,7 @@ private HttpRequestMessage BuildHttpRequestMessage<T>(string method, string path
var requestArguments = Helpers.ExtractQueryStringValuesFromObject(requestParams);
if (requestArguments.Count > 0)
{
var queryString = String.Join("&",
requestArguments.Select(a => a.Key + "=" + Helpers.Stringify(a.Value))
);

var queryString = String.Join("&", requestArguments.Select(Helpers.QueryStringArgument));
path += "?" + queryString;
}
}
Expand Down Expand Up @@ -321,6 +318,12 @@ internal static List<KeyValuePair<string, object>> ExtractQueryStringValuesFromO
return args;
}

internal static string QueryStringArgument(KeyValuePair<string, object> argument)
{
var urlEncodedValue = WebUtility.UrlEncode(Helpers.Stringify(argument.Value));
var urlEncodedKey = WebUtility.UrlEncode(argument.Key);
return $"{urlEncodedKey}={urlEncodedValue}";
}
}
}
}

0 comments on commit e4fd3b9

Please sign in to comment.