本文整理汇总了C#中MacroExpansion.Walk方法的典型用法代码示例。如果您正苦于以下问题:C# MacroExpansion.Walk方法的具体用法?C# MacroExpansion.Walk怎么用?C# MacroExpansion.Walk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MacroExpansion
的用法示例。
在下文中一共展示了MacroExpansion.Walk方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExpectSpecToExist
public void ExpectSpecToExist()
{
var justAnId = new List<FieldConfig>
{
new FieldConfig("Id", null)
};
var tables = new List<OracularTable>
{
new OracularTable("Foobar", null, null, justAnId)
};
var specs = new List<OracularSpec>();
var config = new OracularConfig (tables, specs);
var checker = new RefChecker (config);
var reference = new Reference (new [] { "Foobar" });
var fn = new Reference (new [] { "isBaz" });
var call = new MacroExpansion (fn, new [] { reference });
var initial = new []{ "Foobar" };
var ex = Assert.Throws<RefCheckException>(() => call.Walk (checker, initial));
Assert.That (REFERENCE_RE.IsMatch (ex.Message));
}
示例2: CheckJoinTables
public void CheckJoinTables()
{
var justAnId = new List<FieldConfig>
{
new FieldConfig("Id", null)
};
var potatoFields = new List<FieldConfig>
{
new FieldConfig("Id", null),
new FieldConfig("FoobarId", null),
new FieldConfig("Type", null)
};
var foobarRelationship = new ParentConfig ("Foobar", null, null);
var tables = new List<OracularTable>
{
new OracularTable("Foobar", null, null, justAnId),
new OracularTable("Potato", null, new List<ParentConfig>{foobarRelationship}, potatoFields)
};
var specs = new List<OracularSpec>();
var config = new OracularConfig (tables, specs);
var checker = new RefChecker (config);
var fingerlingPotatoes = new BinaryOperation("=",
new Reference(new [] { "Potato", "Type" }),
new StringLiteral("Fingerling")
);
var call = new MacroExpansion(
new Reference(new [] { "ANY" }),
new AstNode[] {
new Reference(new [] { "Potato" }),
fingerlingPotatoes
}
);
var initial = new []{ "Foobar" };
var result = call.Walk (checker, initial);
Assert.AreEqual (2, result.Length);
Assert.Contains ("Foobar", result);
Assert.Contains ("Potato", result);
}
示例3: ExpectJoinTableToExist
public void ExpectJoinTableToExist()
{
var justAnId = new List<FieldConfig>
{
new FieldConfig("Id", null)
};
var tables = new List<OracularTable>
{
new OracularTable("Foobar", null, null, justAnId)
};
var specs = new List<OracularSpec>();
var config = new OracularConfig (tables, specs);
var checker = new RefChecker (config);
var fingerlingPotatoes = new BinaryOperation("=",
new Reference(new [] { "Potato", "Type" }),
new StringLiteral("Fingerling")
);
var call = new MacroExpansion(
new Reference(new [] { "ANY" }),
new [] { fingerlingPotatoes }
);
var initial = new []{ "Foobar" };
var ex = Assert.Throws<RefCheckException> (() => call.Walk (checker, initial));
Assert.That (REFERENCE_RE.IsMatch (ex.Message));
}
示例4: ExpectNestedSpecToRefcheck
public void ExpectNestedSpecToRefcheck()
{
var justAnId = new List<FieldConfig>
{
new FieldConfig("Id", null)
};
var potatoFields = new List<FieldConfig>
{
new FieldConfig("Id", null),
new FieldConfig("FoobarId", null)
};
var foobarRelationship = new ParentConfig ("Foobar", null, null);
var tables = new List<OracularTable>
{
new OracularTable("Foobar", null, null, justAnId),
new OracularTable("Potato", null, new List<ParentConfig>{foobarRelationship}, potatoFields)
};
var specs = new List<OracularSpec>();
var config = new OracularConfig (tables, specs);
var checker = new RefChecker (config);
var fingerlingPotatoes = new MacroExpansion(
new Reference(new [] { "isFingerling" }),
new [] { new Reference(new [] { "Potato" }) }
);
var call = new MacroExpansion(
new Reference(new [] { "ANY" }),
new AstNode[] {
new Reference(new [] { "Potato" }),
fingerlingPotatoes
}
);
var initial = new []{ "Foobar" };
var ex = Assert.Throws<RefCheckException> (() => call.Walk (checker, initial));
Assert.That (REFERENCE_RE.IsMatch (ex.Message));
}
示例5: SerializeSpecReferences
public void SerializeSpecReferences()
{
var justAnId = new List<FieldConfig>
{
new FieldConfig("Id", null)
};
var idAndBarId = new List<FieldConfig>
{
new FieldConfig("Id", null),
new FieldConfig("BarId", null)
};
var barRelationship = new List<ParentConfig>
{
new ParentConfig("Bar", null, null)
};
var foo = new OracularTable ("Foo", null, barRelationship, idAndBarId);
var tables = new List<OracularTable>
{
foo,
new OracularTable("Bar", null, null, justAnId)
};
var specs = new List<OracularSpec>
{
new OracularSpec("barHasId", "Bar", "Bar.Id != null")
};
var config = new OracularConfig (tables, specs);
var foobarReference = new Reference (new [] { "Foo", "Bar" });
var specReference = new Reference (new [] { "barHasId" });
var macroExpansion = new MacroExpansion (specReference, new [] { foobarReference });
var builder = new Sqlizer (foo, config);
var sql = macroExpansion.Walk (builder);
Assert.AreEqual ("([Foo.Bar].[Id] != NULL)", sql);
Assert.AreEqual (1, builder.JoinTables.Count ());
var joinClause = builder.JoinTables.First();
Assert.AreEqual ("INNER JOIN [Bar] [Foo.Bar] ON [Foo.Bar].[Id] = [Foo].[BarId]", joinClause);
}
示例6: CheckSpecReferences
public void CheckSpecReferences()
{
var justAnId = new List<FieldConfig>
{
new FieldConfig("Id", null)
};
var tables = new List<OracularTable>
{
new OracularTable("Foobar", null, null, justAnId)
};
var specs = new List<OracularSpec>
{
new OracularSpec("isBaz", "Foobar", "Foobar.Id != null")
};
var config = new OracularConfig (tables, specs);
var checker = new RefChecker (config);
var reference = new Reference (new [] { "Foobar" });
var fn = new Reference (new [] { "isBaz" });
var call = new MacroExpansion (fn, new [] { reference });
var initial = new []{ "Foobar" };
var result = call.Walk (checker, initial);
Assert.AreEqual (1, result.Length);
Assert.Contains ("Foobar", result);
}
示例7: SerializeReducer
public void SerializeReducer(string macro, string prefix, string suffix, string value, string equality)
{
var justAnId = new List<FieldConfig>
{
new FieldConfig("Id", null)
};
var idAndBarId = new List<FieldConfig>
{
new FieldConfig("Id", null),
new FieldConfig("BarId", null)
};
var barRelationship = new List<ParentConfig>
{
new ParentConfig("Bar", null, null)
};
var foo = new OracularTable ("Foo", null, barRelationship, idAndBarId);
var bar = new OracularTable("Bar", null, null, justAnId);
var tables = new List<OracularTable>{ foo, bar };
var specs = new List<OracularSpec> ();
var config = new OracularConfig (tables, specs);
var macroReference = new Reference (new[]{ macro });
var fooReference = new Reference (new[]{ "Foo" });
var idNotNull = new BinaryOperation ("!=",
new Reference (new[]{ "Foo", "Id" }),
new NullLiteral ()
);
var macroExpansion = new MacroExpansion (macroReference, new AstNode[] { fooReference, idNotNull });
var builder = new Sqlizer (bar, config);
var sql = macroExpansion.Walk (builder);
var expected = String.Format ("[AnnotatedBar{0}].[{1}Foo{0}]{2}", idNotNull.Id, prefix, suffix);
Assert.AreEqual (expected, sql);
Assert.AreEqual (1, builder.JoinTables.Count ());
var join = builder.JoinTables.First ();
expected = String.Format ("LEFT JOIN [AnnotatedBar{0}] ON [AnnotatedBar{0}].[Id] = [Bar].[Id]", idNotNull.Id);
Assert.AreEqual (expected, join);
Assert.AreEqual (1, builder.CommonTableExpressions.Count ());
var annotated = builder.CommonTableExpressions.First ();
expected = String.Format (@"[AnnotatedBar{0}] AS (
SELECT DISTINCT [Bar].[Id], {2} [{1}Foo{0}]
FROM [Bar]
LEFT JOIN [Foo] ON [Foo].[BarId] = [Bar].[Id]
WHERE ([Foo].[Id] {3} NULL)
)", idNotNull.Id, prefix, value, equality);
Assert.AreEqual (expected, annotated);
}
示例8: SerializeNestedReducers
public void SerializeNestedReducers()
{
var bazFields = new List<FieldConfig>
{
new FieldConfig("Id", null)
};
var barFields = new List<FieldConfig>
{
new FieldConfig("Id", null),
new FieldConfig("BazId", null)
};
var barbazRelationship = new List<ParentConfig>
{
new ParentConfig("Baz", null, null)
};
var fooFields = new List<FieldConfig>
{
new FieldConfig("Id", null),
new FieldConfig("BarId", null),
new FieldConfig("IsQux", FieldType.Boolean)
};
var foobarRelationship = new List<ParentConfig>
{
new ParentConfig("Bar", null, null)
};
var baz = new OracularTable ("Baz", null, null, bazFields);
var tables = new List<OracularTable>
{
new OracularTable ("Foo", null, foobarRelationship, fooFields),
new OracularTable("Bar", null, barbazRelationship, barFields),
baz
};
var specs = new List<OracularSpec> ();
var config = new OracularConfig (tables, specs);
var fooIsQuxNode = new Reference (new [] { "Foo", "IsQux" });
var anyFooNode = new MacroExpansion (
new Reference (new [] { "ANY" }),
new [] {
new Reference(new [] { "Foo" }),
fooIsQuxNode
}
);
var anyBarNode = new MacroExpansion (
new Reference(new [] { "ANY" }),
new AstNode[] {
new Reference(new [] { "Bar" }),
anyFooNode
}
);
var builder = new Sqlizer (baz, config);
var whereClause = anyBarNode.Walk (builder);
var expected = String.Format ("[AnnotatedBaz{0}].[AnyBar{0}] = 1", anyFooNode.Id);
Assert.AreEqual (expected, whereClause);
Assert.AreEqual (1, builder.JoinTables.Count ());
var join = builder.JoinTables.First ();
expected = String.Format ("LEFT JOIN [AnnotatedBaz{0}] ON [AnnotatedBaz{0}].[Id] = [Baz].[Id]", anyFooNode.Id);
Assert.AreEqual (expected, join);
Assert.AreEqual (2, builder.CommonTableExpressions.Count ());
var annotatedBar = builder.CommonTableExpressions.First ();
expected = String.Format (@"[AnnotatedBar{0}] AS (
SELECT DISTINCT [Bar].[Id], 1 [AnyFoo{0}]
FROM [Bar]
LEFT JOIN [Foo] ON [Foo].[BarId] = [Bar].[Id]
WHERE [Foo].[IsQux] = 1
)", fooIsQuxNode.Id);
Assert.AreEqual (expected, annotatedBar);
var annotatedBaz = builder.CommonTableExpressions.Last ();
expected = String.Format(@"[AnnotatedBaz{0}] AS (
SELECT DISTINCT [Baz].[Id], 1 [AnyBar{0}]
FROM [Baz]
LEFT JOIN [Bar] ON [Bar].[BazId] = [Baz].[Id]
LEFT JOIN [AnnotatedBar{1}] ON [AnnotatedBar{1}].[Id] = [Bar].[Id]
WHERE [AnnotatedBar{1}].[AnyFoo{1}] = 1
)", anyFooNode.Id, fooIsQuxNode.Id);
Assert.AreEqual (expected, annotatedBaz);
}
示例9: ExpectSpecToExist
public void ExpectSpecToExist()
{
var justAnId = new List<FieldConfig>
{
new FieldConfig("Id", null)
};
var tables = new List<OracularTable>
{
new OracularTable("Foobar", null, null, justAnId)
};
var config = new OracularConfig (tables, new List<OracularSpec> ());
var fnRef = new Reference (new string[]{ "isBaz" });
var foobarRef = new Reference (new string[]{ "Foobar" });
var isFoobarBaz = new MacroExpansion (fnRef, new AstNode[]{ foobarRef });
var ex = Assert.Throws<TypeCheckException> (() => isFoobarBaz.Walk (new TypeChecker (config)));
Assert.That (ex.Message, Is.StringContaining ("name"));
}
示例10: ExpectSpecTableToMatchInput
public void ExpectSpecTableToMatchInput()
{
var justAnId = new List<FieldConfig>
{
new FieldConfig("Id", null)
};
var tables = new List<OracularTable>
{
new OracularTable("Foobar", null, null, justAnId),
new OracularTable("SomethingElse", null, null, justAnId)
};
var specs = new List<OracularSpec>
{
new OracularSpec("isBaz", "SomethingElse", "SomethingElse.Id = null")
};
var config = new OracularConfig (tables, specs);
var fnRef = new Reference (new string[]{ "isBaz" });
var foobarRef = new Reference (new string[]{ "Foobar" });
var isFoobarBaz = new MacroExpansion (fnRef, new AstNode[]{ foobarRef });
var ex = Assert.Throws<TypeCheckException> (() => isFoobarBaz.Walk (new TypeChecker (config)));
Assert.That (ex.Message, Is.StringContaining ("mismatch"));
}
示例11: CheckSpecAgainstTable
public void CheckSpecAgainstTable()
{
var justAnId = new List<FieldConfig>
{
new FieldConfig("Id", null)
};
var tables = new List<OracularTable>
{
new OracularTable("Foobar", null, null, justAnId)
};
var specs = new List<OracularSpec>
{
new OracularSpec("isBaz", "Foobar", "Foobar.Id = null")
};
var config = new OracularConfig (tables, specs);
var fnRef = new Reference (new string[]{ "isBaz" });
var foobarRef = new Reference (new string[]{ "Foobar" });
var isFoobarBaz = new MacroExpansion (fnRef, new AstNode[]{ foobarRef });
var type = isFoobarBaz.Walk (new TypeChecker (config));
Assert.AreEqual (SpecType.Boolean, type.Type);
}