public async Task GetDeliveryAsync_ShouldParseMinimalObjectCorrectly() { // Taken from documentation page 4; all nullable fields are not in the response/json var handler = new FakeResponseHandler() .AddJsonResponse(new Uri(PostcodeNL.DEFAULTURI, "subscription/deliveries/abc"), File.ReadAllText("responses/minimaldelivery.json")); var pcnl = new PostcodeNL("test", "test", handler); var delivery = await pcnl.GetDeliveryAsync("abc"); Assert.AreEqual("abc", delivery.Id); Assert.AreEqual(1, delivery.AccountId); Assert.AreEqual("X", delivery.ProductCode); Assert.AreEqual("Y", delivery.ProductName); Assert.AreEqual(DeliveryType.Mutation, delivery.DeliveryType); Assert.AreEqual(new DateTime(2015, 1, 1), delivery.DeliveryTarget); Assert.AreEqual(new Uri("https://retrieve.postcode.nl/abc"), delivery.DownloadUrl); Assert.AreEqual(5, delivery.DownloadCount); }
public async Task GetAccountsAsync_ShouldParseMinimalObjectCorrectly() { // Taken from documentation page 4; all nullable fields are not in the response/json var handler = new FakeResponseHandler() .AddJsonResponse(new Uri(PostcodeNL.DEFAULTURI, "subscription/accounts/123456789012"), File.ReadAllText("responses/minimalaccount.json")); var pcnl = new PostcodeNL("test", "test", handler); var account = await pcnl.GetAccountAsync(123456789012); Assert.AreEqual(123456789012, account.Id); Assert.AreEqual("X", account.ProductCode); Assert.AreEqual("Y", account.ProductName); Assert.AreEqual(new DateTime(2014, 3, 3), account.SubscriptionStart); Assert.AreEqual(new DateTime(2014, 3, 4), account.SubscriptionEnd); Assert.IsNull(account.LastDeliveryComplete); Assert.IsNull(account.LastDeliveryMutation); Assert.IsNull(account.NextDeliveryComplete); Assert.IsNull(account.NextDeliveryMutation); }
public async Task ErrorResponse_ShouldParse_AndBeThrown() { // Taken from documentation page 5 var handler = new FakeResponseHandler() .AddJsonResponse(new Uri(PostcodeNL.DEFAULTURI, "subscription/accounts/1234567"), File.ReadAllText("responses/error.json"), HttpStatusCode.NotFound); var pcnl = new PostcodeNL("test", "test", handler); try { var accounts = await pcnl.GetAccountAsync(1234567); Assert.Fail("Exception should have been thrown"); } catch (PostcodeNLException ex) { Assert.AreEqual("Cannot find subscription with id #1234567.", ex.Message); Assert.AreEqual("PostcodeNl_Controller_Subscription_UnknownSubscriptionException", ex.ExceptionId); Assert.AreEqual("EQJKVW", ex.RequestId); } }
public async Task ListDeliveriesAsync_ShouldParseCorrectly() { // Taken from documentation page 9 var handler = new FakeResponseHandler() .AddJsonResponse(new Uri(PostcodeNL.DEFAULTURI, "subscription/deliveries?deliveryType=mutation&after=20141229"), File.ReadAllText("responses/deliveries.json")); var pcnl = new PostcodeNL("test", "test", handler); var deliveries = (await pcnl.ListDeliveriesAsync(new DeliveriesQuery { DeliveryType = DeliveryType.Mutation, After = new DateTime(2014, 12, 29) })).ToArray(); Assert.AreEqual(2, deliveries.Length); Assert.AreEqual("aca76d844cbd999358475d9fe164d346", deliveries[0].Id); Assert.AreEqual("80e5b3f23d20fc0e237e61b644d1e891", deliveries[1].Id); Assert.AreEqual(12647, deliveries[0].AccountId); Assert.AreEqual(12647, deliveries[1].AccountId); Assert.AreEqual("PCTP-ACU-W", deliveries[0].ProductCode); Assert.AreEqual("PCTP-ACU-W", deliveries[1].ProductCode); Assert.AreEqual("PCTP-BAG \"ASCII-compatibel\" standard choice.", deliveries[0].ProductName); Assert.AreEqual("PCTP-BAG \"ASCII-compatibel\" standard choice.", deliveries[1].ProductName); Assert.AreEqual(DeliveryType.Mutation, deliveries[0].DeliveryType); Assert.AreEqual(DeliveryType.Mutation, deliveries[1].DeliveryType); Assert.AreEqual(new DateTime(2015, 1, 12), deliveries[0].DeliverySource); Assert.AreEqual(new DateTime(2015, 1, 5), deliveries[1].DeliverySource); Assert.AreEqual(new DateTime(2015, 1, 19), deliveries[0].DeliveryTarget); Assert.AreEqual(new DateTime(2015, 1, 12), deliveries[1].DeliveryTarget); Assert.AreEqual("https://retrieve.postcode.nl/aca76d844cbd999358475d9fe164d346", deliveries[0].DownloadUrl.AbsoluteUri); Assert.AreEqual("https://retrieve.postcode.nl/80e5b3f23d20fc0e237e61b644d1e891", deliveries[1].DownloadUrl.AbsoluteUri); Assert.AreEqual(0, deliveries[0].DownloadCount); Assert.AreEqual(1, deliveries[1].DownloadCount); }
public async Task ListAccountsAsync_ShouldParseCorrectly() { // Taken from documentation page 7 var handler = new FakeResponseHandler() .AddJsonResponse(new Uri(PostcodeNL.DEFAULTURI, "subscription/accounts"), File.ReadAllText("responses/accounts.json")); var pcnl = new PostcodeNL("test", "test", handler); var accounts = (await pcnl.ListAccountsAsync()).ToArray(); Assert.AreEqual(2, accounts.Length); Assert.AreEqual(12646, accounts[0].Id); Assert.AreEqual(12647, accounts[1].Id); Assert.AreEqual("GEO-4PP-Y", accounts[0].ProductCode); Assert.AreEqual("PCTP-ACU-W", accounts[1].ProductCode); Assert.AreEqual("Geographical wijkcode yearly updates.", accounts[0].ProductName); Assert.AreEqual("PCTP-BAG \"ASCII-compatibel\" standard choice.", accounts[1].ProductName); Assert.AreEqual(new DateTime(2014, 1, 1), accounts[0].SubscriptionStart); Assert.AreEqual(new DateTime(2014, 3, 3), accounts[1].SubscriptionStart); Assert.AreEqual(new DateTime(2016, 1, 1), accounts[0].SubscriptionEnd); Assert.AreEqual(new DateTime(2014, 3, 2), accounts[1].SubscriptionEnd); Assert.AreEqual(new DateTime(2014, 1, 1), accounts[0].LastDeliveryComplete); Assert.AreEqual(new DateTime(2014, 3, 3), accounts[1].LastDeliveryComplete); Assert.IsNull(accounts[0].LastDeliveryMutation); Assert.AreEqual(new DateTime(2015, 1, 19), accounts[1].LastDeliveryMutation); Assert.AreEqual(new DateTime(2015, 1, 1), accounts[0].NextDeliveryComplete); Assert.IsNull(accounts[1].NextDeliveryComplete); Assert.IsNull(accounts[0].NextDeliveryMutation); Assert.AreEqual(new DateTime(2015, 1, 26), accounts[1].NextDeliveryMutation); }