Exemplo n.º 1
0
        public void AddingCurie_WhichIsNull_ThrowsException()
        {
            var model = new SimpleModel();
            var graph = new HalGraph(model);

            Assert.Throws <ArgumentNullException>(() =>
            {
                graph.AddCurie(null);
            });
        }
Exemplo n.º 2
0
        public void AddingCurie_WhenValid_MakesLinksTheFirstKey()
        {
            var model = new SimpleModel();
            var graph = new HalGraph(model);

            var curieToCreate = new Curie("xx", "http://www.myapi.com/api/{placeholder}");

            var result = (HalGraph)graph.AddCurie(curieToCreate);

            Assert.IsType <Dictionary <string, object> >(result[0]);
        }
Exemplo n.º 3
0
        public void AddingCurie_WhenValid_ReturnsTheHalGraph()
        {
            var model = new SimpleModel();
            var graph = new HalGraph(model);

            var expectedCurie = new Curie("xx", "http://www.myapi.com/api/{placeholder}");

            var result = graph.AddCurie(expectedCurie);

            Assert.Equal(expected: graph, actual: result);
        }
Exemplo n.º 4
0
        public void AddingCurie_WhenValid_CreatesCurieCollection()
        {
            var model = new SimpleModel();
            var graph = new HalGraph(model);

            var curieToCreate = new Curie("xx", "http://www.myapi.com/api/{something}");

            graph.AddCurie(curieToCreate);

            var actualLink = ((Dictionary <string, object>)graph["_links"])["curies"];

            Assert.IsAssignableFrom <IEnumerable <Link> >(actualLink);
        }
Exemplo n.º 5
0
        public void AddingCurie_WhenValid_CreateLinkWithNameCurie()
        {
            var model = new SimpleModel();
            var graph = new HalGraph(model);

            var curieToCreate = new Curie("xx", "http://www.myapi.com/api/{something}");

            var expectedLink = new CurieLink("xx", "http://www.myapi.com/api/{something}");

            graph.AddCurie(curieToCreate);

            var curiesCollection = (List <CurieLink>)((Dictionary <string, object>)graph["_links"])["curies"];

            Assert.True(((Dictionary <string, object>)graph["_links"]).Count == 1);
            Assert.True(curiesCollection.Count == 1);
            expectedLink.ShouldDeepEqual(curiesCollection[0]);
        }
Exemplo n.º 6
0
        public void AddingCurie_WhenOneAlreadyAdded_AddsTheCurieToTheExistingCurieCollection()
        {
            var model = new SimpleModel();
            var graph = new HalGraph(model);

            var firstCurieToCreate  = new Curie("aa", "http://www.myapi.com/api/orders/{order-id}");
            var secondCurieToCreate = new Curie("bb", "http://www.myapi.com/api/customers/{customer-id}");

            //var expectedLink = new CurieLink("http://www.myapi.com/api/{something}");

            graph
            .AddCurie(firstCurieToCreate)
            .AddCurie(secondCurieToCreate);

            var curiesCollection = (List <CurieLink>)((Dictionary <string, object>)graph["_links"])["curies"];

            Assert.True(((Dictionary <string, object>)graph["_links"]).Count == 1);
            Assert.True(curiesCollection.Count == 2);
        }