Skip to content
Browse files

Updated QueryWith tests

  • Loading branch information...
1 parent 24b35f7 commit b9da6117cebd3ff82587524758c90813151b6da4 @markrendle committed
View
3 .gitignore
@@ -37,4 +37,5 @@ packages/Microsoft.Web.Infrastructure.1.0.0.0/
packages/Modernizr.2.5.3/
packages/jQuery.1.7.1.1/
packages/jQuery.UI.Combined.1.8.20.1/
-packages/jQuery.Validation.1.9.0.1/
+packages/jQuery.Validation.1.9.0.1/
+Simple.Data.sln.ide
View
1 Simple.Data.Ado/Simple.Data.Ado.csproj
@@ -87,6 +87,7 @@
<Compile Include="DeleteHelper.cs" />
<Compile Include="DictionaryExtensions.cs" />
<Compile Include="EagerLoadingEnumerable.cs" />
+ <Compile Include="EventHandlerEx.cs" />
<Compile Include="ExpressionFormatter.cs" />
<Compile Include="ExpressionFormatterBase.cs" />
<Compile Include="ExpressionHasher.cs" />
View
22 Simple.Data.BehaviourTest/Query/WithTest.cs
@@ -14,6 +14,7 @@ protected override void SetSchema(MockSchemaProvider schemaProvider)
new[] { "dbo", "Activity", "BASE TABLE" },
new[] { "dbo", "Customer", "BASE TABLE" },
new[] { "dbo", "Order", "BASE TABLE" },
+ new[] { "dbo", "Item", "BASE TABLE" },
new[] { "dbo", "Note", "BASE TABLE" },
new[] { "dbo", "Activity_Join", "BASE TABLE" },
new[] { "dbo", "Location", "BASE_TABLE" });
@@ -29,6 +30,9 @@ protected override void SetSchema(MockSchemaProvider schemaProvider)
new[] { "dbo", "Order", "Id" },
new[] { "dbo", "Order", "CustomerId" },
new[] { "dbo", "Order", "Description" },
+ new[] { "dbo", "Item", "Id" },
+ new[] { "dbo", "Item", "OrderId" },
+ new[] { "dbo", "Item", "Description" },
new[] { "dbo", "Note", "Id" },
new[] { "dbo", "Note", "CustomerId" },
new[] { "dbo", "Note", "Text" },
@@ -44,6 +48,7 @@ protected override void SetSchema(MockSchemaProvider schemaProvider)
new object[] {"dbo", "Department", "Id", 0},
new object[] {"dbo", "Customer", "Id", 0},
new object[] {"dbo", "Order", "Id", 0},
+ new object[] {"dbo", "Item", "Id", 0},
new object[] {"dbo", "Note", "Id", 0}
);
@@ -52,6 +57,7 @@ protected override void SetSchema(MockSchemaProvider schemaProvider)
new object[] { "FK_Activity_Join_Activity", "dbo", "Activity_Join", "ID_Activity", "dbo", "Activity", "ID", 0 },
new object[] { "FK_Activity_Join_Location", "dbo", "Activity_Join", "ID_Location", "dbo", "Location", "ID", 0 },
new object[] { "FK_Order_Customer", "dbo", "Order", "CustomerId", "dbo", "Customer", "Id", 0 },
+ new object[] { "FK_Item_Order", "dbo", "Item", "OrderId", "dbo", "Order", "Id", 0 },
new object[] { "FK_Note_Customer", "dbo", "Note", "CustomerId", "dbo", "Customer", "Id", 0 }
);
// ReSharper restore CoVariantArrayConversion
@@ -232,6 +238,22 @@ public void CustomerWithOrdersAndNotes()
GeneratedSqlIs(expectedSql);
}
+ [Test]
+ public void CustomerWithOrdersWithItems()
+ {
+ const string expectedSql = "select [dbo].[Customer].[Id],[dbo].[Customer].[Name]," +
+ "[dbo].[Order].[Id] AS [__withn__Orders__Id],[dbo].[Order].[CustomerId] AS [__withn__Orders__CustomerId]," +
+ "[dbo].[Order].[Description] AS [__withn__Orders__Description],[dbo].[Item].[Id] AS [__withn__Items__Id]," +
+ "[dbo].[Item].[OrderId] AS [__withn__Items__OrderId],[dbo].[Item].[Description] AS [__withn__Items__Description]" +
+ " from [dbo].[Customer] LEFT JOIN [dbo].[Order] ON ([dbo].[Customer].[Id] = [dbo].[Order].[CustomerId])" +
+ " LEFT JOIN [dbo].[Item] ON ([dbo].[Order].[Id] = [dbo].[Item].[OrderId])";
+
+ var q = _db.Customers.All().With(_db.Customers.Orders).With(_db.Customers.Orders.Items);
+ EatException(() => q.ToList());
+
+ GeneratedSqlIs(expectedSql);
+ }
+
/// <summary>
/// Test for issue #157
/// </summary>
View
14 Simple.Data.SqlTest/QueryTest.cs
@@ -347,6 +347,20 @@ public void FindAllWithClauseWithJoinCriteriaShouldPreselectDetailTableAsCollect
}
[Test]
+ public void FindAllWithClauseWithNestedDetailTable()
+ {
+ var db = DatabaseHelper.Open();
+ var result = db.Customers.FindAllByCustomerId(1).With(db.Customers.Orders).With(db.Customers.Orders.OrderItems).FirstOrDefault() as IDictionary<string, object>;
+ Assert.IsNotNull(result);
+ Assert.Contains("Orders", (ICollection)result.Keys);
+ var orders = result["Orders"] as IList<IDictionary<string, object>>;
+ Assert.IsNotNull(orders);
+ Assert.AreEqual(1, orders.Count);
+ var order = orders[0];
+ Assert.Contains("OrderItems", (ICollection)order.Keys);
+ }
+
+ [Test]
public void GetWithClauseWithJoinCriteriaShouldPreselectDetailTableAsCollection()
{
var db = DatabaseHelper.Open();

0 comments on commit b9da611

Please sign in to comment.
Something went wrong with that request. Please try again.