Exemplo n.º 1
0
        public void GivenBaseTemplate_WhichDoesNotIncludeTheVariables_CreateOneWithAllVariables()
        {
            // given
            this.path = "/people";
            var expectedTemplate = "/people{?t,Name,Age}";

            // when
            var template = this.factory.CreateIriTemplate <MixedProperties, object>();

            // then
            var actualTemplate = new UriTemplateString.UriTemplateString(template.Template);

            actualTemplate.ToString().Should().Be(expectedTemplate);
        }
Exemplo n.º 2
0
        public void GivenBaseTemplate_WhichIncludeAVariable_DoesNotAppendThatQueryParam()
        {
            // given
            this.path = "/people{/t}";
            var expectedTemplate = "/people{/t}{?Name,Age}";

            // when
            var template = this.factory.CreateIriTemplate <MixedProperties, object>();

            // then
            var actualTemplate = new UriTemplateString.UriTemplateString(template.Template);

            actualTemplate.ToString().Should().Be(expectedTemplate);
        }
Exemplo n.º 3
0
        private string BuildTemplate(string path, IEnumerable <IriTemplateMapping> mappings)
        {
            var template          = new UriTemplateString.UriTemplateString(path);
            var existingVariables = template.Parts
                                    .OfType <Expression>()
                                    .SelectMany(ex => ex.VariableList)
                                    .Select(vs => vs.Name)
                                    .Distinct()
                                    .ToArray();

            foreach (var mapping in mappings)
            {
                if (existingVariables.Contains(mapping.Variable))
                {
                    continue;
                }

                template = template.AppendQueryParam(mapping.Variable);
            }

            return(template.ToString());
        }