public void AddingMultipleLink_WhenValid_AddsThemAllToTheSameRelCollection() { const string rel = "myrel"; var model = new SimpleModel(); var graph = new HalGraph(model); var firstLink = new Link("/api/some-resource1"); var secondLink = new Link("/api/some-resource2"); var thirdLink = new Link("/api/some-resource3"); var fourthLink = new Link("/api/some-resource4"); graph.AddLinks(rel, new List <Link> { firstLink, secondLink, thirdLink, fourthLink }); var linksCollection = (List <Link>)((Dictionary <string, object>)graph["_links"])[rel]; Assert.True(((Dictionary <string, object>)graph["_links"]).Count == 1); Assert.True(linksCollection.Count == 4); Assert.Equal(expected: firstLink, actual: linksCollection[0]); Assert.Equal(expected: secondLink, actual: linksCollection[1]); Assert.Equal(expected: thirdLink, actual: linksCollection[2]); Assert.Equal(expected: fourthLink, actual: linksCollection[3]); }
public void AddingMultipleLinks_WithEmptyLinksCollection_ThrowsException() { string rel = "my-rel"; var model = new SimpleModel(); var graph = new HalGraph(model); var linksToAdd = new List <Link>(); Assert.Throws <ArgumentException>(() => { graph.AddLinks(rel, linksToAdd); }); }
public void AddingMultipleLinks_WithEmptyRel_ThrowsException() { string rel = string.Empty; var model = new SimpleModel(); var graph = new HalGraph(model); var linksToAdd = new List <Link> { new Link("/api/some-resource1"), new Link("/api/some-resource2") }; Assert.Throws <ArgumentException>(() => { graph.AddLinks(rel, linksToAdd); }); }
public void AddingMultipleLink_WhenValid_ReturnsTheHalGraph() { const string rel = "myrel"; var model = new SimpleModel(); var graph = new HalGraph(model); var firstLink = new Link("/api/some-resource1"); var secondLink = new Link("/api/some-resource2"); var thirdLink = new Link("/api/some-resource3"); var fourthLink = new Link("/api/some-resource4"); var result = graph.AddLinks(rel, new List <Link> { firstLink, secondLink, thirdLink, fourthLink }); Assert.Equal(expected: graph, actual: result); }