Ejemplo n.º 1
0
        public void RenderEntity_HasRows_HasHeaders(Type paperType)
        {
            // Given
            var template = "/{id}";
            var path     = "/17";

            var renderer = new QueryRenderer(injector.Object, registry.Object);

            renderer.PathTemplate = template;
            renderer.PaperType    = paperType;

            // When
            httpRequest.Setup(x => x.Path).Returns(path);
            var entity  = renderer.RenderEntity(httpContext.Object, path);
            var headers = entity.Data?.Properties?.GetRowsHeaders();

            // Then
            var expected = new object[] {
                "Custom Id",
                "Custom Title",
                "Custom Group Id",
                "Custom Group Title"
            };
            var obtained = new object[] {
                headers?["Id"]?.Title,
                headers?["Title"]?.Title,
                headers?["GroupId"]?.Title,
                headers?["GroupTitle"]?.Title
            };

            Assert.Equal(expected, obtained);
        }
Ejemplo n.º 2
0
        public void RenderEntity_HasRows(Type paperType)
        {
            // Given
            var template    = "/{id}";
            var path        = "/17";
            var queryString = "?text=Hello, world!";

            var renderer = new QueryRenderer(injector.Object, registry.Object);

            renderer.PathTemplate = template;
            renderer.PaperType    = paperType;

            // When
            httpRequest.Setup(x => x.Path).Returns(path);
            httpRequest.Setup(x => x.QueryString).Returns(new QueryString(queryString));
            var entity   = renderer.RenderEntity(httpContext.Object, path);
            var firstRow = entity.Data?.Entities?.FirstOrDefault();

            // Then
            var expected = new object[] { 1, "ODD", 17, "Hello, world!" };
            var obtained = new object[] {
                firstRow?.Properties?["Id"]?.Value,
                firstRow?.Properties?["Title"]?.Value,
                firstRow?.Properties?["GroupId"]?.Value,
                firstRow?.Properties?["GroupTitle"]?.Value
            };

            Assert.Equal(expected, obtained);
        }
Ejemplo n.º 3
0
        public void RenderEntity_HasProperties(Type paperType)
        {
            // Given
            var template = "/";
            var path     = "/";

            var renderer = new QueryRenderer(injector.Object, registry.Object);

            renderer.PathTemplate = template;
            renderer.PaperType    = paperType;

            // When
            httpRequest.Setup(x => x.Path).Returns(path);
            var entity  = renderer.RenderEntity(httpContext.Object, path);
            var version = entity.Data?.Properties["Version"]?.Value as PropertyCollection;

            // Then
            var expected = new object[] { "TestApp", 1, 2, 3, null };
            var obtained = new object[] {
                entity.Data?.Properties["Name"]?.Value,
                version["Major"]?.Value,
                version["Minor"]?.Value,
                version["Revision"]?.Value,
                entity.Data?.Properties["Undefined"]?.Value
            };

            Assert.Equal(expected, obtained);
        }
Ejemplo n.º 4
0
        public void RenderEntity_HasTitle(Type paperType)
        {
            // Given
            var template = "/";
            var path     = "/";

            var renderer = new QueryRenderer(injector.Object, registry.Object);

            renderer.PathTemplate = template;
            renderer.PaperType    = paperType;

            // When
            httpRequest.Setup(x => x.Path).Returns(path);
            var entity = renderer.RenderEntity(httpContext.Object, path);

            // Then
            var expected = "Test Query";
            var obtained = entity.Data?.Title;

            Assert.Equal(expected, obtained);
        }
Ejemplo n.º 5
0
        public void RenderEntity_InferTitle(Type paperType)
        {
            // Given
            var template = "/";
            var path     = "/";

            var renderer = new QueryRenderer(injector.Object, registry.Object);

            renderer.PathTemplate = template;
            renderer.PaperType    = paperType;

            // When
            httpRequest.Setup(x => x.Path).Returns(path);
            var entity = renderer.RenderEntity(httpContext.Object, path);

            // Then
            var expected = paperType.Name.Replace("Query", "").ChangeCase(TextCase.ProperCase);
            var obtained = entity.Data?.Title;

            Assert.Equal(expected, obtained);
        }
Ejemplo n.º 6
0
        public void RenderEntity_HasCustomRel(Type paperType)
        {
            // Given
            var template = "/";
            var path     = "/";

            var renderer = new QueryRenderer(injector.Object, registry.Object);

            renderer.PathTemplate = template;
            renderer.PaperType    = paperType;

            // When
            httpRequest.Setup(x => x.Path).Returns(path);
            var entity = renderer.RenderEntity(httpContext.Object, path);

            // Then
            var expected   = "customRel";
            var collection = entity.Data?.Rel?.ToString();

            Assert.Contains(expected, collection);
        }
Ejemplo n.º 7
0
        public void RenderEntity_HasRowsLinks(Type paperType)
        {
            var template = "/{id}";
            var path     = "/17";

            var renderer = new QueryRenderer(injector.Object, registry.Object);

            renderer.PathTemplate = template;
            renderer.PaperType    = paperType;

            //... mock da classe link referenciada ...
            var linkedRenderer = new PaperRendererInfo
            {
                PaperRendererType = typeof(QueryRenderer),
                PaperType         = typeof(DataAndRowsQuery),
                PathTemplate      = "/{id}/RowLink"
            };

            registry
            .Setup(x => x.FindPaperRenderers(It.IsAny <Type>()))
            .Returns(linkedRenderer.AsSingle());

            // When
            httpRequest.Setup(x => x.Path).Returns(path);
            var entity    = renderer.RenderEntity(httpContext.Object, path);
            var secondRow = entity?.Data?.Entities?.Skip(1).FirstOrDefault();

            // Then
            var expected = new string[] {
                "rows.link.com?q=2",
                "http://localhost:90/Tests/2/RowLink?offset=1&limit=2&sort[]=id:desc"
            };
            var obtained =
                secondRow?.Links
                .Where(x => x.Class?.Contains("rowLink") == true)
                .Select(x => x.Href)
                .ToArray();

            Assert.Equal(expected, obtained);
        }
Ejemplo n.º 8
0
        public void RenderEntity_HasSelfLink(Type paperType)
        {
            // Given
            var template = "/{id}";
            var path     = "/17";

            var renderer = new QueryRenderer(injector.Object, registry.Object);

            renderer.PathTemplate = template;
            renderer.PaperType    = paperType;

            // When
            httpRequest.Setup(x => x.Path).Returns(path);
            var entity   = renderer.RenderEntity(httpContext.Object, path);
            var selfLink = entity.Data?.Links.FirstOrDefault(x => x.Rel.Contains("self"));

            // Then
            var expected = $"http://localhost:90/Tests/17";
            var obtained = selfLink?.Href;

            Assert.Equal(expected, obtained);
        }
Ejemplo n.º 9
0
        public void RenderEntity_Paginated(Type paperType)
        {
            // Given
            var template    = "/{id}";
            var path        = "/17";
            var queryString = "?offset=1&limit=2";

            var renderer = new QueryRenderer(injector.Object, registry.Object);

            renderer.PathTemplate = template;
            renderer.PaperType    = paperType;

            // When
            httpRequest.Setup(x => x.Path).Returns(path);
            httpRequest.Setup(x => x.QueryString).Returns(new QueryString(queryString));
            var entity = renderer.RenderEntity(httpContext.Object, path);

            // Then
            var expected = new object[] { 2, 3 };
            var obtained = entity?.Data?.Entities?.Select(x => x.Properties["Id"]?.Value).ToArray();

            Assert.Equal(expected, obtained);
        }
Ejemplo n.º 10
0
        public void RenderEntity_HasFilter(Type paperType)
        {
            // Given
            var template    = "/{id}";
            var path        = "/17";
            var queryString = "?offset=1&limit=2&sort[]=Title:desc&text=Olá, mundo!";

            var renderer = new QueryRenderer(injector.Object, registry.Object);

            renderer.PathTemplate = template;
            renderer.PaperType    = paperType;

            // When
            httpRequest.Setup(x => x.Path).Returns(path);
            httpRequest.Setup(x => x.QueryString).Returns(new QueryString(queryString));
            var entity = renderer.RenderEntity(httpContext.Object, path);
            var filter = entity?.Data?.Actions.FirstOrDefault(x => x.Name.EqualsIgnoreCase("Filter"));

            // Then
            var expected = new object[] {
                "http://localhost:90/Tests/17?sort[]=title:desc",
                "Text",
                "Some Text",
                "text",
                "Olá, mundo!"
            };
            var obtained = new[] {
                filter?.Href,
                filter?.Fields.Select(x => x.Name).FirstOrDefault(),
                filter?.Fields.Select(x => x.Title).FirstOrDefault(),
                filter?.Fields.Select(x => x.DataType).FirstOrDefault(),
                filter?.Fields.Select(x => x.Value).FirstOrDefault()
            };

            Assert.Equal(expected, obtained);
        }
Ejemplo n.º 11
0
        public void RenderEntity_HasData(Type paperType)
        {
            // Given
            var template = "/{id}";
            var path     = "/17";

            var renderer = new QueryRenderer(injector.Object, registry.Object);

            renderer.PathTemplate = template;
            renderer.PaperType    = paperType;

            // When
            httpRequest.Setup(x => x.Path).Returns(path);
            var entity = renderer.RenderEntity(httpContext.Object, path);

            // Then
            var expected = new object[] { 17, "Query17" };
            var obtained = new object[] {
                entity.Data?.Properties["Id"]?.Value,
                entity.Data?.Properties["ItemTitle"]?.Value
            };

            Assert.Equal(expected, obtained);
        }