Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[24] Retrieve embedded resources #25

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
86 changes: 71 additions & 15 deletions Src/HoneyBear.HalClient.Unit.Tests/HalClientAsyncUnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using HoneyBear.HalClient.Unit.Tests.ProxyResources;
using NUnit.Framework;
Expand Down Expand Up @@ -52,7 +51,7 @@ public void Navigate_to_single_embedded_resource()
Task<IHalClient> Act(IHalClient sut) => sut
.RootAsync(RootUri)
.GetAsync("order", new {orderRef = _context.OrderRef}, Curie)
.GetAsync("orderitem", Curie);
.GetAsync("orderitem-query", Curie);

_context.ActAsync(Act);

Expand Down Expand Up @@ -85,13 +84,60 @@ public void Navigate_to_paged_embedded_resource()
Task<IHalClient> Act(IHalClient sut) => sut
.RootAsync(RootUri)
.GetAsync("order-queryby-user", new {userRef = HalClientTestContext.UserRef}, Curie)
.GetAsync("order", Curie);
.GetAsync("order", new {orderRef = _context.OrderRef}, Curie);

_context.ActAsync(Act);

_context.AssertThatEmbeddedPagedResourceIsPresent();
}

[Test]
public void Navigate_to_paged_embedded_resource_and_navigate_to_embedded_resource_via_parent()
{
_context
.ArrangeHomeResource()
.ArrangePagedResource();

Task<IHalClient> Act(IHalClient sut)
{
var resource =
sut
.RootAsync(RootUri)
.GetAsync("order-queryby-user", new {userRef = HalClientTestContext.UserRef}, Curie)
.Item<PagedList>();

return sut.GetAsync(resource, "order", new {orderRef = _context.OrderRef}, Curie);
}

_context.ActAsync(Act);

_context.AssertThatSingleResourceIsPresent();
}

[Test]
public void Navigate_to_paged_linked_resource_and_navigate_to_linked_resource_via_parent()
{
_context
.ArrangeHomeResource()
.ArrangePagedResourceWithLinkedResources()
.ArrangeSingleResource();

Task<IHalClient> Act(IHalClient sut)
{
var resource =
sut
.RootAsync(RootUri)
.GetAsync("order-queryby-user", new {userRef = HalClientTestContext.UserRef}, Curie)
.Item<PagedList>();

return sut.GetAsync(resource, "order", new {orderRef = _context.OrderRef}, Curie);
}

_context.ActAsync(Act);

_context.AssertThatSingleResourceIsPresent();
}

[Test]
public void Navigate_to_paged_embedded_resource_and_navigate_to_embedded_resource_array()
{
Expand All @@ -107,15 +153,12 @@ Task<IHalClient> Act(IHalClient sut)
.GetAsync("order-queryby-user", new {userRef = HalClientTestContext.UserRef}, Curie)
.GetAsync("order", Curie);

var order =
nav
.Items<Order>()
.First();
var order = nav.Item<Order>();

return
nav
.GetAsync(order, "orderitem-query", Curie)
.GetAsync("orderitem", Curie);
.GetAsync("orderitem", new {orderItemRef = _context.OrderItemRef}, Curie);
}

_context.ActAsync(Act);
Expand All @@ -136,17 +179,14 @@ Task<IHalClient> Act(IHalClient sut)
sut
.RootAsync(RootUri)
.GetAsync("order-queryby-user", new {userRef = HalClientTestContext.UserRef}, Curie)
.GetAsync("order", Curie);
.GetAsync("order", new {orderRef = _context.OrderRef}, Curie);

var order =
nav
.Items<Order>()
.First();
var order = nav.Item<Order>();

return
nav
.GetAsync(order, "orderitem-query", Curie)
.GetAsync("orderitem", Curie);
.GetAsync("orderitem", new {orderItemRef = _context.OrderItemRef}, Curie);
}

_context.ActAsync(Act);
Expand Down Expand Up @@ -560,7 +600,7 @@ Task<IHalClient> Act(IHalClient sut) => sut
}

[Test]
public void HalClientAsync_can_be_created_with_specifed_HttpClient() =>
public void HalClientAsync_can_be_created_with_specified_HttpClient() =>
_context.AssertThatHttpClientCanBeProvided();

[Test]
Expand Down Expand Up @@ -624,5 +664,21 @@ public void Throws_exception_when_HTTP_request_is_unsuccessful()

Assert.Throws<AggregateException>(() => _context.ActAsync(Act));
}

[Test]
public void Throws_exception_when_resource_does_not_exist()
{
_context
.ArrangeHomeResource()
.ArrangePagedResource()
.ArrangeFailedOrderRequest();

Task<IHalClient> Act(IHalClient sut) => sut
.RootAsync(RootUri)
.GetAsync("order-queryby-user", new { userRef = HalClientTestContext.UserRef }, Curie)
.GetAsync("order", new { orderRef = HalClientTestContext.NonExistentOrderRef }, Curie);

Assert.Throws<AggregateException>(() => _context.ActAsync(Act));
}
}
}
Loading