public void AddingEmbeddedItem_WithDuplicateKeyName_ThrowsException() { const string initialKey = "I-AM-THE-KEY-THE-FIRST-TIME"; const string secondKey = "I-AM-THE-KEY-THE-FIRST-TIME"; var model = new SimpleModel(); var parentGraph = new HalGraph(model); var childModel1 = new SimpleModel(); var childModel2 = new SimpleModel(); var childGraph1 = new HalGraph(childModel1); var childGraph2 = new HalGraph(childModel2); parentGraph.AddEmbeddedItem(initialKey, childGraph1); Assert.Throws <ArgumentException>(() => { parentGraph.AddEmbeddedItem(secondKey, childGraph2); }); }
public void AddingEmbeddedItem_WhichIsNull_ThrowsException() { const string embeddedItemName = "some-name"; var model = new SimpleModel(); var graph = new HalGraph(model); Assert.Throws <ArgumentNullException>(() => { graph.AddEmbeddedItem(embeddedItemName, null); }); }
public void AddingEmbeddedItem_WhenValid_ReturnsTheHalGraph() { const string embeddedItemName = "SOME-VALID-STRING"; var model = new SimpleModel(); var graph = new HalGraph(model); var expectedEmbeddedGraph = new HalGraph(model); var result = graph.AddEmbeddedItem(embeddedItemName, expectedEmbeddedGraph); Assert.Equal(expected: graph, actual: result); }
public void AddingEmbeddedItem_WithEmptyName_ThrowsException() { var embeddedItemName = string.Empty; var model = new SimpleModel(); var graph = new HalGraph(model); var embeddedGraph = new HalGraph(model); Assert.Throws <ArgumentException>(() => { graph.AddEmbeddedItem(embeddedItemName, embeddedGraph); }); }
public void AddingEmbeddedItem_WhenValid_AddsItToTheCollection() { const string embeddedItemName = "SOME-VALID-STRING"; var model = new SimpleModel(); var graph = new HalGraph(model); var expectedEmbeddedGraph = new HalGraph(model); graph.AddEmbeddedItem(embeddedItemName, expectedEmbeddedGraph); var storedHalGraph = (IHalGraph)((Dictionary <string, object>)graph["_embedded"])[embeddedItemName]; Assert.True(((Dictionary <string, object>)graph["_embedded"]).Count == 1); Assert.Equal(expected: expectedEmbeddedGraph, actual: storedHalGraph); }
public void AddingEmbeddedItem_WhenValid_MakesEmbeddedItemsTheLastKey() { const string embeddedItemName = "SOME-VALID-STRING"; var modelAtTopLevel = new SimpleModel(); var graph = new HalGraph(modelAtTopLevel); var modelForEmbedded = new SimpleModel(); var expectedEmbeddedGraph = new HalGraph(modelForEmbedded); var result = (HalGraph)graph.AddEmbeddedItem(embeddedItemName, expectedEmbeddedGraph); var lastKeyIndex = result.Count; Assert.IsType <Dictionary <string, object> >(result[lastKeyIndex - 1]); }