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 ExecutionKernel_Execute() { var container = new ComponentContainer() .Add(new QueryComponent(SyntaxComponent.Keytable, "Item")) .Add(new QueryComponent(SyntaxComponent.Command, "SELECT")) .Add(new QueryComponent(SyntaxComponent.Keyword, "FROM")) .Add(new QueryComponent(SyntaxComponent.FieldList, "ID, Name")); var compiledQuery = new CompiledQuery { Query = "SELECT ID, Name FROM Item" }; var items = new List <Item> { new Item { ID = 1, Name = "name" } }; var compiler = new Mock <IQueryCompiler>(); compiler.Setup(exp => exp.Compile(It.Is <ComponentContainer>(c => c == container))).Returns(() => compiledQuery); var executor = new Mock <IExecutionContext>(); executor.Setup(exp => exp.Execute(It.Is <CompiledQuery>(c => c == compiledQuery))).Returns(() => new DataReaderContext(new MockedDataReader(items, typeof(Item)))); // Execute var kernel = new ExecutionKernel(compiler.Object, executor.Object); var result = kernel.Execute <Item>(container); compiler.Verify(exp => exp.Compile(It.Is <ComponentContainer>(c => c == container)), Times.Once); executor.Verify(exp => exp.Execute(It.Is <CompiledQuery>(c => c == compiledQuery)), Times.Once); Assert.That(result.Count() == 1); }
public void ExecutionKernel_ExecuteNonQuery() { var kernel = new ExecutionKernel(new Mock <IQueryCompiler>().Object, new Mock <IExecutionContext>().Object); kernel.ExecuteNonQuery(new ComponentContainer()); Assert.Fail("assert is not implemented correctly"); }