コード例 #1
0
ファイル: HalGraphTests.cs プロジェクト: AndyBrennan1/CoreHal
        public void AddingEmbeddedItemCollection_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.AddEmbeddedItemCollection(
                initialKey,
                new List <IHalGraph> {
                childGraph1, childGraph2
            });

            Assert.Throws <ArgumentException>(() =>
            {
                parentGraph.AddEmbeddedItemCollection(
                    secondKey,
                    new List <IHalGraph> {
                    childGraph1, childGraph2
                });
            });
        }
コード例 #2
0
ファイル: HalGraphTests.cs プロジェクト: AndyBrennan1/CoreHal
        public void AddingEmbeddedItemCollection_WithVaryingModelType_ThrowsException()
        {
            const string embeddedItemName = "SOME-VALID-STRING";

            var modelParent = new SimpleModel {
                StringProperty = "Some string value"
            };
            var modelChild1 = new ExampleModel {
                Id = Guid.NewGuid(), Name = "SOME NAME"
            };
            var modelChild2IsOfDifferentType = new SimpleModelWithDateField {
                SomeDateField = DateTime.Now
            };

            var graph          = new HalGraph(modelParent);
            var embeddedGraph1 = new HalGraph(modelChild1);
            var embeddedGraph2 = new HalGraph(modelChild2IsOfDifferentType);

            Assert.Throws <ArgumentException>(() =>
            {
                graph.AddEmbeddedItemCollection(
                    embeddedItemName,
                    new List <IHalGraph> {
                    embeddedGraph1, embeddedGraph2
                });
            });
        }
コード例 #3
0
ファイル: HalGraphTests.cs プロジェクト: AndyBrennan1/CoreHal
        public void AddingEmbeddedItemCollection_WhenValid_AddsItToTheCollection()
        {
            const string embeddedItemName = "SOME-VALID-STRING";

            var modelParent = new SimpleModel {
                StringProperty = "Some string value"
            };
            var modelChild1 = new ExampleModel {
                Id = Guid.NewGuid(), Name = "SOME NAME"
            };
            var modelChild2 = new ExampleModel {
                Id = Guid.NewGuid(), Name = "ANOTHER NAME"
            };
            var graph = new HalGraph(modelParent);

            var embeddedGraph1 = new HalGraph(modelChild1);
            var embeddedGraph2 = new HalGraph(modelChild2);

            graph.AddEmbeddedItemCollection(
                embeddedItemName,
                new List <IHalGraph> {
                embeddedGraph1, embeddedGraph2
            });

            var storedHalGraph = (List <IHalGraph>)((Dictionary <string, object>)graph["_embedded"])[embeddedItemName];

            Assert.True(((Dictionary <string, object>)graph["_embedded"]).Count == 1);
            Assert.True(storedHalGraph.Count == 2);
            Assert.Equal(expected: embeddedGraph1, actual: storedHalGraph[0]);
            Assert.Equal(expected: embeddedGraph2, actual: storedHalGraph[1]);
        }
コード例 #4
0
ファイル: HalGraphTests.cs プロジェクト: AndyBrennan1/CoreHal
        public void AddingEmbeddedItemCollection_WhichIsNull_ThrowsException()
        {
            const string embeddedItemName = "some-name";

            var model = new SimpleModel();
            var graph = new HalGraph(model);

            Assert.Throws <ArgumentNullException>(() =>
            {
                graph.AddEmbeddedItemCollection(embeddedItemName, null);
            });
        }
コード例 #5
0
ファイル: HalGraphTests.cs プロジェクト: AndyBrennan1/CoreHal
        public void AddingEmbeddedItemCollection_WhenValid_ReturnsTheHalGraph()
        {
            const string embeddedItemName = "SOME-VALID-STRING";

            var model = new SimpleModel();
            var graph = new HalGraph(model);

            var embeddedGraph1 = new HalGraph(model);
            var embeddedGraph2 = new HalGraph(model);

            var result = graph.AddEmbeddedItemCollection(
                embeddedItemName,
                new List <IHalGraph> {
                embeddedGraph1, embeddedGraph2
            });

            Assert.Equal(expected: graph, actual: result);
        }
コード例 #6
0
ファイル: HalGraphTests.cs プロジェクト: AndyBrennan1/CoreHal
        public void AddingEmbeddedItemCollection_WithEmptyName_ThrowsException()
        {
            var embeddedItemName = string.Empty;

            var model = new SimpleModel();
            var graph = new HalGraph(model);

            var embeddedGraph1 = new HalGraph(model);
            var embeddedGraph2 = new HalGraph(model);

            Assert.Throws <ArgumentException>(() =>
            {
                graph.AddEmbeddedItemCollection(
                    embeddedItemName,
                    new List <IHalGraph> {
                    embeddedGraph1, embeddedGraph2
                });
            });
        }