Skip to content

Commit 4c21413

Browse files
authored
Merge pull request #763 from mikependon/repodb-immutable-constructor-integration-tests
#753 #761 - Integration Tests
2 parents 1df26fc + dca8bea commit 4c21413

File tree

2 files changed

+164
-1
lines changed

2 files changed

+164
-1
lines changed

RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/ImmutableTest.cs

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,5 +1665,168 @@ public void TestSqlConnectionUpdateAllForMappedPropertiesImmutable()
16651665

16661666
#endregion
16671667

1668+
#region Constructor/ExecuteQuery
1669+
1670+
#region ExecuteQuery (Matched CTOR Arguments)
1671+
1672+
private class ImmutableWithMatchedCtorArguments
1673+
{
1674+
public ImmutableWithMatchedCtorArguments(int id,
1675+
DateTime value)
1676+
{
1677+
Id = id;
1678+
Value = value;
1679+
}
1680+
1681+
public int Id { get; set; }
1682+
public DateTime Value { get; set; }
1683+
}
1684+
1685+
[TestMethod]
1686+
public void TestSqlConnectionExecuteQueryForImmutableWithMatchedCtorArguments()
1687+
{
1688+
using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
1689+
{
1690+
// Setup
1691+
var param = new { Value = DateTime.UtcNow.Date };
1692+
var sql = "SELECT 1 AS [Id], @Value AS [Value];";
1693+
1694+
// Act
1695+
var queryResult = connection.ExecuteQuery<ImmutableWithMatchedCtorArguments>(sql, param).FirstOrDefault();
1696+
1697+
// Assert
1698+
Assert.AreEqual(1, queryResult.Id);
1699+
Assert.AreEqual(param.Value, queryResult.Value);
1700+
}
1701+
}
1702+
1703+
[TestMethod]
1704+
public void TestSqlConnectionExecuteQueryAsyncForImmutableWithMatchedCtorArguments()
1705+
{
1706+
using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
1707+
{
1708+
// Setup
1709+
var param = new { Value = DateTime.UtcNow.Date };
1710+
var sql = "SELECT 1 AS [Id], @Value AS [Value];";
1711+
1712+
// Act
1713+
var queryResult = connection.ExecuteQueryAsync<ImmutableWithMatchedCtorArguments>(sql, param).Result.FirstOrDefault();
1714+
1715+
// Assert
1716+
Assert.AreEqual(1, queryResult.Id);
1717+
Assert.AreEqual(param.Value, queryResult.Value);
1718+
}
1719+
}
1720+
1721+
#endregion
1722+
1723+
#region ExecuteQuery (Matched CTOR Arguments From Multiple CTORs)
1724+
1725+
private class ImmutableWithMatchedCtorArgumentsFromMultipleCtors
1726+
{
1727+
public ImmutableWithMatchedCtorArgumentsFromMultipleCtors()
1728+
{ }
1729+
1730+
public ImmutableWithMatchedCtorArgumentsFromMultipleCtors(int id,
1731+
DateTime value)
1732+
{
1733+
Id = id;
1734+
Value = value;
1735+
}
1736+
1737+
public int Id { get; set; }
1738+
public DateTime Value { get; set; }
1739+
}
1740+
1741+
[TestMethod]
1742+
public void TestSqlConnectionExecuteQueryForImmutableWithMatchedCtorArgumentsFromMultipleCtors()
1743+
{
1744+
using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
1745+
{
1746+
// Setup
1747+
var param = new { Value = DateTime.UtcNow.Date };
1748+
var sql = "SELECT 1 AS [Id], @Value AS [Value];";
1749+
1750+
// Act
1751+
var queryResult = connection.ExecuteQuery<ImmutableWithMatchedCtorArgumentsFromMultipleCtors>(sql, param).FirstOrDefault();
1752+
1753+
// Assert
1754+
Assert.AreEqual(1, queryResult.Id);
1755+
Assert.AreEqual(param.Value, queryResult.Value);
1756+
}
1757+
}
1758+
1759+
[TestMethod]
1760+
public void TestSqlConnectionExecuteQueryAsyncForImmutableWithMatchedCtorArgumentsFromMultipleCtors()
1761+
{
1762+
using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
1763+
{
1764+
// Setup
1765+
var param = new { Value = DateTime.UtcNow.Date };
1766+
var sql = "SELECT 1 AS [Id], @Value AS [Value];";
1767+
1768+
// Act
1769+
var queryResult = connection.ExecuteQueryAsync<ImmutableWithMatchedCtorArgumentsFromMultipleCtors>(sql, param).Result.FirstOrDefault();
1770+
1771+
// Assert
1772+
Assert.AreEqual(1, queryResult.Id);
1773+
Assert.AreEqual(param.Value, queryResult.Value);
1774+
}
1775+
}
1776+
1777+
#endregion
1778+
1779+
#region ExecuteQuery (Unmatched CTOR Arguments From Multiple CTORs)
1780+
1781+
private class ImmutableWithUnmatchedCtorArgumentsFromMultipleCtors
1782+
{
1783+
public ImmutableWithUnmatchedCtorArgumentsFromMultipleCtors()
1784+
{ }
1785+
1786+
public ImmutableWithUnmatchedCtorArgumentsFromMultipleCtors(int id,
1787+
DateTime value,
1788+
string extra)
1789+
{
1790+
Id = id;
1791+
Value = value;
1792+
Extra = extra;
1793+
}
1794+
1795+
public int Id { get; set; }
1796+
public DateTime Value { get; set; }
1797+
public string Extra { get; set; }
1798+
}
1799+
1800+
[TestMethod, ExpectedException(typeof(MissingMemberException))]
1801+
public void ThrowExceptionOnSqlConnectionExecuteQueryForImmutableWithUnmatchedCtorArgumentsFromMultipleCtors()
1802+
{
1803+
using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
1804+
{
1805+
// Setup
1806+
var param = new { Value = DateTime.UtcNow.Date };
1807+
var sql = "SELECT 1 AS [Id], @Value AS [Value];";
1808+
1809+
// Act
1810+
connection.ExecuteQuery<ImmutableWithUnmatchedCtorArgumentsFromMultipleCtors>(sql, param);
1811+
}
1812+
}
1813+
1814+
[TestMethod, ExpectedException(typeof(AggregateException))]
1815+
public void ThrowExceptionOnSqlConnectionExecuteQueryAsyncForImmutableWithUnmatchedCtorArgumentsFromMultipleCtors()
1816+
{
1817+
using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
1818+
{
1819+
// Setup
1820+
var param = new { Value = DateTime.UtcNow.Date };
1821+
var sql = "SELECT 1 AS [Id], @Value AS [Value];";
1822+
1823+
// Act
1824+
connection.ExecuteQueryAsync<ImmutableWithUnmatchedCtorArgumentsFromMultipleCtors>(sql, param).Wait();
1825+
}
1826+
}
1827+
1828+
#endregion
1829+
1830+
#endregion
16681831
}
16691832
}

RepoDb.Core/RepoDb.Tests/RepoDb.UnitTests/RepoDb.UnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<ItemGroup>
2121
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
22-
<PackageReference Include="Moq" Version="4.15.2" />
22+
<PackageReference Include="Moq" Version="4.16.0" />
2323
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
2424
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
2525
<PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" />

0 commit comments

Comments
 (0)