public static void TemplateCompiler_Compile_EnumQuery_NotEnum() { var template = RawUriTemplate.Parse("?f={Field.First}"); InvalidOperationException ex = Assert.Throws <InvalidOperationException>(() => TemplateCompiler.Compile <Values>(template)); Assert.Equal("An enum was expected for Field.", ex.Message); }
public static void RawUriTemplate_Parse_Empty() { var template = RawUriTemplate.Parse(""); Assert.Empty(template.Query); Assert.Empty(template.Path); }
public static void RawUriTemplate_Parse_LiteralValueLiteral() { var template = RawUriTemplate.Parse("/test/{test?}/test"); Assert.Empty(template.Query); Assert.Collection(template.Path, item => { Assert.Null(item.Name); Assert.Null(item.Format); Assert.Equal(UriTokenType.Literal, item.Type); Assert.Equal("/test/", item.Default); }, item => { Assert.Equal("test?", item.Name); Assert.Null(item.Format); Assert.Equal(UriTokenType.Value, item.Type); Assert.Null(item.Default); }, item => { Assert.Null(item.Name); Assert.Null(item.Format); Assert.Equal(UriTokenType.Literal, item.Type); Assert.Equal("/test", item.Default); }); }
public static void TemplateCompiler_Compile_Constant() { var template = RawUriTemplate.Parse("/test/url?some=value&foo=bar"); Func <object, string> compiled = TemplateCompiler.Compile <object>(template); string result = compiled(new object()); Assert.Equal("/test/url?some=value&foo=bar", result); }
public static void TemplateCompiler_Compile_EnumQuery_Nullable_Named_Null() { var values = new Values(); var template = RawUriTemplate.Parse("?f={NormalNullable.First=foo}&s={NormalNullable.Second=bar}"); Func <Values, string> compiled = TemplateCompiler.Compile <Values>(template); string result = compiled(values); Assert.Equal("", result); }
public static void TemplateCompiler_Compile_CollectionQuery_Empty() { var values = new Values(); var template = RawUriTemplate.Parse("?f={Collection[]}"); Func <Values, string> compiled = TemplateCompiler.Compile <Values>(template); string result = compiled(values); Assert.Equal("", result); }
public static void TemplateCompiler_Compile_DefaultPath() { var values = new Values(); var template = RawUriTemplate.Parse("/test/{NullableField=Default}"); Func <Values, string> compiled = TemplateCompiler.Compile <Values>(template); string result = compiled(values); Assert.Equal("/test/Default", result); }
public static void TemplateCompiler_Compile_Formattable_Default() { var values = new Values(); var template = RawUriTemplate.Parse("?f={Formattable=Value}"); Func <Values, string> compiled = TemplateCompiler.Compile <Values>(template); string result = compiled(values); Assert.Equal("?f=Value", result); }
public static void TemplateCompiler_Compile_NullableQuery_Null() { var values = new Values(); var template = RawUriTemplate.Parse("?f={NullableField:x}"); Func <Values, string> compiled = TemplateCompiler.Compile <Values>(template); string result = compiled(values); Assert.Equal("", result); }
public static void RawUriTemplate_Parse_Query_Empty() { var template = RawUriTemplate.Parse("/test?"); Assert.Empty(template.Query); UriToken item = Assert.Single(template.Path); Assert.Null(item.Name); Assert.Null(item.Format); Assert.Equal(UriTokenType.Literal, item.Type); Assert.Equal("/test", item.Default); }
public static void RawUriTemplate_Parse_Value_Format_Default() { var template = RawUriTemplate.Parse("{test:N?=ba?z}"); Assert.Empty(template.Query); UriToken item = Assert.Single(template.Path); Assert.Equal("test", item.Name); Assert.Equal("N?", item.Format); Assert.Equal(UriTokenType.Value, item.Type); Assert.Equal("ba?z", item.Default); }
public static void RawUriTemplate_Parse_Value() { var template = RawUriTemplate.Parse("{test?}"); Assert.Empty(template.Query); UriToken item = Assert.Single(template.Path); Assert.Equal("test?", item.Name); Assert.Null(item.Format); Assert.Equal(UriTokenType.Value, item.Type); Assert.Null(item.Default); }
public static void TemplateCompiler_Compile_Query() { var values = new Values() { Field = 100 }; var template = RawUriTemplate.Parse("?f={Field}"); Func <Values, string> compiled = TemplateCompiler.Compile <Values>(template); string result = compiled(values); Assert.Equal("?f=100", result); }
public static void TemplateCompiler_Compile_NotFormattable() { var values = new Values() { NotFormattable = new NotFormattable() }; var template = RawUriTemplate.Parse("?f={NotFormattable}"); Func <Values, string> compiled = TemplateCompiler.Compile <Values>(template); string result = compiled(values); Assert.Equal("?f=Foo%21", result); }
public static void TemplateCompiler_Compile_EnumQuery_Flags_Named() { var values = new Values() { Flags = FlagsEnum.First | FlagsEnum.Second }; var template = RawUriTemplate.Parse("?f={Flags.First=first}&s={Flags.Second=baz}"); Func <Values, string> compiled = TemplateCompiler.Compile <Values>(template); string result = compiled(values); Assert.Equal("?f=first&s=baz", result); }
public static void TemplateCompiler_Compile_EnumQuery_Named() { var values = new Values() { Normal = NormalEnum.Second }; var template = RawUriTemplate.Parse("?f={Normal.First}&s={Normal.Second=second}&t={Normal.Second}"); Func <Values, string> compiled = TemplateCompiler.Compile <Values>(template); string result = compiled(values); Assert.Equal("?s=second&t", result); }
public static void RawUriTemplate_Parse_Query_Name() { var template = RawUriTemplate.Parse("?test"); Assert.Empty(template.Path); UriQuery query = Assert.Single(template.Query); Assert.Empty(query.Value); UriToken name = Assert.Single(query.Name); Assert.Null(name.Name); Assert.Null(name.Format); Assert.Equal(UriTokenType.Literal, name.Type); Assert.Equal("test", name.Default); }
public static void TemplateCompiler_Compile_CollectionQuery() { var values = new Values() { Collection = new[] { "Test", null, "Foo" } }; var template = RawUriTemplate.Parse("?f={Collection[]}"); Func <Values, string> compiled = TemplateCompiler.Compile <Values>(template); string result = compiled(values); Assert.Equal("?f=Test&f&f=Foo", result); }
public static void RawUriTemplate_Parse_Query_NameToken_ValueToken() { var template = RawUriTemplate.Parse("?test{foo}={baz}bar"); Assert.Empty(template.Path); UriQuery query = Assert.Single(template.Query); Assert.Collection(query.Name, name => { Assert.Null(name.Name); Assert.Null(name.Format); Assert.Equal(UriTokenType.Literal, name.Type); Assert.Equal("test", name.Default); }, name => { Assert.Equal("foo", name.Name); Assert.Null(name.Format); Assert.Equal(UriTokenType.Value, name.Type); Assert.Null(name.Default); }); Assert.Collection(query.Value, value => { Assert.Equal("baz", value.Name); Assert.Null(value.Format); Assert.Equal(UriTokenType.Value, value.Type); Assert.Null(value.Default); }, value => { Assert.Null(value.Name); Assert.Null(value.Format); Assert.Equal(UriTokenType.Literal, value.Type); Assert.Equal("bar", value.Default); }); }
public static void RawUriTemplate_Parse_Query_Name_Value_Name_Value() { var template = RawUriTemplate.Parse("?test=bar&foo=baz"); Assert.Empty(template.Path); Assert.Collection(template.Query, query => { UriToken name = Assert.Single(query.Name); Assert.Null(name.Name); Assert.Null(name.Format); Assert.Equal(UriTokenType.Literal, name.Type); Assert.Equal("test", name.Default); UriToken value = Assert.Single(query.Value); Assert.Null(value.Name); Assert.Null(value.Format); Assert.Equal(UriTokenType.Literal, value.Type); Assert.Equal("bar", value.Default); }, query => { UriToken name = Assert.Single(query.Name); Assert.Null(name.Name); Assert.Null(name.Format); Assert.Equal(UriTokenType.Literal, name.Type); Assert.Equal("foo", name.Default); UriToken value = Assert.Single(query.Value); Assert.Null(value.Name); Assert.Null(value.Format); Assert.Equal(UriTokenType.Literal, value.Type); Assert.Equal("baz", value.Default); }); }
public static void RawUriTemplate_Parse_Value_InvalidRBrace2() { FormatException ex = Assert.Throws <FormatException>(() => RawUriTemplate.Parse("}test")); Assert.Equal("The URI template contains an invalid token.", ex.Message); }