Exemplo n.º 1
0
        public void formatter_withNestedEmbeddeds_embeddedsProperlyNested()
        {
            // arrange
            var outerResource = new RecursiveResource
            {
                Name = "Base"
            };

            var mid = new RecursiveResource
            {
                Name = "Middle"
            };

            var inner = new RecursiveResource
            {
                Name = "Inner"
            };

            mid.NestedResource           = inner;
            outerResource.NestedResource = mid;


            // act
            var result = TestHelpers.Format.FormatObject(outerResource, _formatter);

            var o             = JObject.Parse(result);
            var innerEmbedded = o["_embedded"]["nestedResource"]["_embedded"]["nestedResource"];

            // assert
            result.Should().Contain("_embedded");
            result.Should().Contain("Base");
            result.Should().Contain("Middle");
            result.Should().Contain("Inner");
            innerEmbedded["name"].ToString().Should().Be("Inner");
        }
        public void roundTrip_nestedEmbeds_structureRecursed()
        {
            // arrange
            var test = new RecursiveResource
            {
                Name           = "Outermost",
                NestedResource = new RecursiveResource
                {
                    Name           = "Mid Level",
                    NestedResource = new RecursiveResource
                    {
                        Name = "Innermost"
                    }
                }
            };

            // act
            var result = TestHelpers.Format.PerformRoundTrip <RecursiveResource>(test, _formatter);
            var mid    = result.NestedResource;
            var inner  = mid.NestedResource;

            // assert
            result.Should().BeOfType <RecursiveResource>();
            mid.Should().BeOfType <RecursiveResource>();
            inner.Should().BeOfType <RecursiveResource>();
            result.Name.Should().Be("Outermost");
            mid.Name.Should().Be("Mid Level");
            inner.Name.Should().Be("Innermost");
        }