public void AddingLink_WhenRelAlreadyExists_AddsLinkToExistingRelCollection() { 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"); graph.AddLink(rel, firstLink); graph.AddLink(rel, secondLink); var linksCollection = (List <Link>)((Dictionary <string, object>)graph["_links"])[rel]; Assert.True(((Dictionary <string, object>)graph["_links"]).Count == 1); Assert.True(linksCollection.Count == 2); Assert.Equal(expected: firstLink, actual: linksCollection[0]); Assert.Equal(expected: secondLink, actual: linksCollection[1]); }
public void AddingLink_WhichIsNull_ThrowsException() { const string rel = "myrel"; var model = new SimpleModel(); var graph = new HalGraph(model); Assert.Throws <ArgumentNullException>(() => { graph.AddLink(rel, null); }); }
public void AddingLink_WhenValid_MakesLinksTheFirstKey() { const string rel = "myrel"; var model = new SimpleModel(); var graph = new HalGraph(model); var expectedLink = new Link("/api/some-resource"); var result = (HalGraph)graph.AddLink(rel, expectedLink); Assert.IsType <Dictionary <string, object> >(result[0]); }
public void AddingLink_WhenValid_ReturnsTheHalGraph() { const string rel = "myrel"; var model = new SimpleModel(); var graph = new HalGraph(model); var expectedLink = new Link("/api/some-resource"); var result = graph.AddLink(rel, expectedLink); Assert.Equal(expected: graph, actual: result); }
public void AddingLink_WithEmptyRel_ThrowsException() { string rel = ""; var model = new SimpleModel(); var graph = new HalGraph(model); var linkToAdd = new Link("/api/some-resource"); Assert.Throws <ArgumentException>(() => { graph.AddLink(rel, linkToAdd); }); }
public void AddingLink_WhenValid_GetsAddedToTheLinkCollection() { const string rel = "myrel"; var model = new SimpleModel(); var graph = new HalGraph(model); var expectedLink = new Link("/api/some-resource"); graph.AddLink(rel, expectedLink); Assert.True(((Dictionary <string, object>)graph["_links"]).Count == 1); Assert.Equal( expected: expectedLink, actual: ((Dictionary <string, object>)graph["_links"])[rel]); }