public void QueryContextOfT_Add_AlreadyAddedType() { var context = new QueryContext <Item>(_kernel.Object); context.Add(new QueryComponent(SyntaxComponent.Command, "")); Assert.Throws <InvalidOperationException>(() => context.Add(new QueryComponent(SyntaxComponent.Command, ""))); }
public void QueryContextOfT_Select_AnonymOutput() { var item = new { IDs = 5, N = "n" }; var data = new[] { item }; var executor = new Mock <IExecutionContext>(); executor.Setup(exp => exp.Execute(It.IsAny <CompiledQuery>())).Returns(() => new DataReaderContext(new MockedDataReader(data, item.GetType()))); var compiler = new Mock <IQueryCompiler>(); compiler.Setup(exp => exp.Compile(It.IsAny <ComponentContainer>())).Returns(() => new CompiledQuery()); var kernel = new ExecutionKernel(compiler.Object, executor.Object); // Execute var context = new QueryContext <Item>(kernel); context.Add(new QueryComponent(SyntaxComponent.Keytable, "Item")); var items = context.Select(a => new { IDs = a.ID, N = a.Name }); Assert.IsNotNull(context.Components.Single(c => c.Type == SyntaxComponent.Command && c.Expression == "SELECT")); Assert.IsNotNull(context.Components.Single(c => c.Type == SyntaxComponent.Keyword && c.Expression == "FROM")); Assert.IsNotNull(context.Components.Single(c => c.Type == SyntaxComponent.FieldList && c.Expression == "Item.ID AS IDs, Item.Name AS N")); Assert.That(items.Any()); Assert.That(items.First().IDs == 5); Assert.That(items.First().N == "n"); }
public void QueryContextOfT_Add() { var context = new QueryContext <Item>(_kernel.Object); context.Add(new QueryComponent(SyntaxComponent.Command, "")); Assert.That(context.Components.All(c => c.Type == SyntaxComponent.Command)); }
public void QueryContextOfT_Select() { _kernel.Setup(exp => exp.Execute <Item>(It.IsAny <ComponentContainer>())).Returns(() => new List <Item>()); var context = new QueryContext <Item>(_kernel.Object); context.Add(new QueryComponent(SyntaxComponent.Keytable, "Item")); var items = context.Select(); Assert.IsNotNull(context.Components.Single(c => c.Type == SyntaxComponent.Command && c.Expression == "SELECT")); Assert.IsNotNull(context.Components.Single(c => c.Type == SyntaxComponent.Keyword && c.Expression == "FROM")); Assert.IsNotNull(context.Components.Single(c => c.Type == SyntaxComponent.FieldList && c.Expression == "ID, Name")); _kernel.Verify(exp => exp.Execute <Item>(It.IsAny <ComponentContainer>()), Times.Once); Assert.IsNotNull(items); }