Skip to content

Commit 3354f76

Browse files
committed
Unit test: DapperResult_GetAllForProperty_UsesOuterTemplate
1 parent cf3cfa2 commit 3354f76

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Griddly.Tests/GriddlyResultTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Griddly.Mvc.Results;
22
using System.Data.SQLite;
33
using Dapper;
4+
using Griddly.Mvc.Exceptions;
45

56
namespace Griddly.Tests
67
{
@@ -57,6 +58,37 @@ public void QueryableResult_GetAllForProperty_Filters()
5758
Assert.IsTrue(results.Contains(3));
5859
}
5960

61+
[TestMethod]
62+
public void DapperResult_GetAllForProperty_CteWithoutOuterTemplate_Throws()
63+
{
64+
using (var conn = CreateTestDatabase("DapperResult_GetAllForProperty_CteWithoutOuterTemplate_Throws"))
65+
{
66+
//Arrange
67+
var dapperResult = new DapperSql2012Result<object>(() => conn, ";with proj as (select * from TestTable) select * from proj where id=@id", new { id = 2 }, null);
68+
69+
//Act/Assert
70+
Assert.ThrowsException<DapperGriddlyException>(() => dapperResult.GetAllForProperty<int>("Id", []));
71+
}
72+
}
73+
74+
75+
[TestMethod]
76+
public void DapperResult_GetAllForProperty_UsesOuterTemplate()
77+
{
78+
using (var conn = CreateTestDatabase("DapperResult_GetAllForProperty_UsesOuterTemplate"))
79+
{
80+
//Arrange
81+
var dapperResult = new DapperSql2012Result<object>(() => conn, "select * from proj where id=@id", new { id = 2 }, null, outerSqlTemplate: ";with proj as (select * from TestTable) {0}");
82+
83+
//Act
84+
var results = dapperResult.GetAllForProperty<int>("Id", []);
85+
86+
//Assert
87+
Assert.AreEqual(1, results.Count());
88+
Assert.AreEqual(2, results.First());
89+
}
90+
}
91+
6092
private class Model
6193
{
6294
public long Id { get; set; }

0 commit comments

Comments
 (0)