Skip to content

Commit

Permalink
Merge branch 'master' into cancellation-token
Browse files Browse the repository at this point in the history
  • Loading branch information
mikependon committed Oct 3, 2020
2 parents 7618e89 + 6e2d985 commit 8ee47c4
Show file tree
Hide file tree
Showing 11 changed files with 324 additions and 138 deletions.
124 changes: 76 additions & 48 deletions RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ public static List<ImmutableWithWritablePropertiesIdentityTable> CreateImmutable
ColumnBit = false,
ColumnDateTime = EpocDate.AddDays(index),
ColumnDateTime2 = DateTime.UtcNow.AddDays(index),
ColumnDecimal = index+1,
ColumnDecimal = index + 1,
ColumnFloat = index + 1,
ColumnInt = index + 1,
ColumnNVarChar = $"NVARCHAR{index}-Property"
Expand Down Expand Up @@ -901,6 +901,42 @@ public static List<DottedTable> CreateDottedTables(int count)

#endregion

#region NonKeyedTable

/// <summary>
/// Creates a list of <see cref="NonKeyedTable"/> objects.
/// </summary>
/// <param name="count">The number of rows.</param>
/// <returns>A list of <see cref="NonKeyedTable"/> objects.</returns>
public static IEnumerable<NonKeyedTable> CreateNonKeyedTables(int count = 10)
{
for (var index = 0; index < count; index++)
{
yield return new NonKeyedTable
{
ColumnDateTime2 = DateTime.UtcNow,
ColumnInt = index,
ColumnNVarChar = $"NVARCHAR{index}"
};
}
}

/// <summary>
/// Creates an instance of <see cref="NonKeyedTable"/> object.
/// </summary>
/// <returns>A new created instance of <see cref="NonKeyedTable"/> object.</returns>
public static NonKeyedTable CreateNonKeyedTable()
{
return new NonKeyedTable
{
ColumnDateTime2 = DateTime.UtcNow,
ColumnInt = new Random().Next(int.MinValue, int.MaxValue),
ColumnNVarChar = Guid.NewGuid().ToString()
};
}

#endregion

#region Dynamics

#region IdentityTable
Expand Down Expand Up @@ -983,53 +1019,6 @@ public static Tuple<List<dynamic>, IEnumerable<Field>> CreateDynamicIdentityTabl
return new Tuple<List<dynamic>, IEnumerable<Field>>(tables, fields);
}

/// <summary>
/// Creates a list of dynamic objects for [sc].[IdentityTable] without an identity.
/// </summary>
/// <param name="count">The number of rows.</param>
/// <returns>A list of dynamic objects.</returns>
public static List<dynamic> CreateDynamicIdentityTablesWithoutIdentity(int count)
{
var tables = new List<dynamic>();
for (var i = 0; i < count; i++)
{
var index = i + 1;
tables.Add(new
{
RowGuid = Guid.NewGuid(),
ColumnBit = true,
ColumnDateTime = EpocDate.AddDays(index),
ColumnDateTime2 = DateTime.UtcNow,
ColumnDecimal = Convert.ToDecimal(index),
ColumnFloat = Convert.ToDouble(index),
ColumnInt = index,
ColumnNVarChar = $"NVARCHAR{index}"
});
}
return tables;
}

/// <summary>
/// Creates a list of dynamic objects for [dbo].[NonKeyedTable] table.
/// </summary>
/// <param name="count">The number of rows.</param>
/// <returns>A list of dynamic objects.</returns>
public static List<dynamic> CreateDynamicNonKeyedTables(int count)
{
var tables = new List<dynamic>();
for (var i = 0; i < count; i++)
{
var index = i + 1;
tables.Add(new
{
ColumnDateTime2 = DateTime.UtcNow,
ColumnInt = index,
ColumnNVarChar = $"NVARCHAR{index}"
});
}
return tables;
}

#endregion

#region NonIdentityTable
Expand Down Expand Up @@ -1111,6 +1100,45 @@ public static Tuple<List<dynamic>, IEnumerable<Field>> CreateDynamicNonIdentityT

#endregion

#region NonKeyedTable

/// <summary>
/// Creates a list of dynamic objects for [dbo].[NonKeyedTable] table.
/// </summary>
/// <param name="count">The number of rows.</param>
/// <returns>A list of dynamic objects.</returns>
public static List<dynamic> CreateDynamicNonKeyedTables(int count)
{
var tables = new List<dynamic>();
for (var i = 0; i < count; i++)
{
var index = i + 1;
tables.Add(new
{
ColumnDateTime2 = DateTime.UtcNow,
ColumnInt = index,
ColumnNVarChar = $"NVARCHAR{index}"
});
}
return tables;
}

/// <summary>
/// Creates an instance of dynamic object for [dbo].[NonKeyedTable] table.
/// </summary>
/// <returns>An instance of dynamic object.</returns>
public static dynamic CreateDynamicNonKeyedTable()
{
return new
{
ColumnDateTime2 = DateTime.UtcNow,
ColumnInt = new Random().Next(int.MinValue, int.MaxValue),
ColumnNVarChar = Guid.NewGuid().ToString()
};
}

#endregion

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1514,16 +1514,16 @@ public void TestSqlConnectionMergeAllViaTableNameForNonIdentityEmptyTableWithHin
}
}

[TestMethod, ExpectedException(typeof(InvalidQualifiersException))]
[TestMethod, ExpectedException(typeof(KeyFieldNotFoundException))]
public void ThrowExceptionOnSqlConnectionMergeAllIfTheKeyFieldIsNotPresent()
{
// Setup
var tables = Helper.CreateDynamicIdentityTablesWithoutIdentity(10);
var tables = Helper.CreateDynamicNonKeyedTables(10);

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
connection.MergeAll(ClassMappedNameCache.Get<IdentityTable>(), tables);
connection.MergeAll(ClassMappedNameCache.Get<NonKeyedTable>(), tables);
}
}

Expand Down Expand Up @@ -2002,12 +2002,12 @@ public void TestSqlConnectionMergeAllAsyncViaTableNameForNonIdentityEmptyTableWi
public void ThrowExceptionOnSqlConnectionMergeAllAsyncIfTheKeyFieldIsNotPresent()
{
// Setup
var tables = Helper.CreateDynamicIdentityTablesWithoutIdentity(10);
var tables = Helper.CreateNonKeyedTables(10);

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
connection.MergeAllAsync(ClassMappedNameCache.Get<IdentityTable>(), tables).Wait();
connection.MergeAllAsync(ClassMappedNameCache.Get<NonKeyedTable>(), tables).Wait();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,26 @@ public void TestSqlConnectionQueryViaExpression()
}
}

[TestMethod]
public void TestSqlConnectionQueryViaExpressionWitNullValue()
{
// Setup
var tables = Helper.CreateIdentityTables(10);
var last = tables.Last();

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
connection.InsertAll(tables);

// Act
var result = connection.Query<IdentityTable>(c => c.ColumnNVarChar == null);

// Assert
Assert.AreEqual(0, result.Count());
}
}

[TestMethod]
public void TestSqlConnectionQueryViaQueryField()
{
Expand Down Expand Up @@ -1545,6 +1565,26 @@ public void TestSqlConnectionQueryAsyncViaExpression()
}
}

[TestMethod]
public void TestSqlConnectionQueryAsyncViaExpressionWithNullValue()
{
// Setup
var tables = Helper.CreateIdentityTables(10);
var last = tables.Last();

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
connection.InsertAll(tables);

// Act
var result = connection.QueryAsync<IdentityTable>(c => c.ColumnNVarChar == null).Result;

// Assert
Assert.AreEqual(0, result.Count());
}
}

[TestMethod]
public void TestSqlConnectionQueryAsyncViaQueryField()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1651,30 +1651,45 @@ public void TestSqlConnectionUpdateViaTableNameWithHints()
}
}

[TestMethod, ExpectedException(typeof(KeyFieldNotFoundException))]
public void ThrowExceptionOnSqlConnectionUpdateIfThereIsNoKeyField()
{
// Setup
var data = Helper.CreateNonKeyedTable();

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
connection.Update<NonKeyedTable>(data);
}
}

[TestMethod, ExpectedException(typeof(KeyFieldNotFoundException))]
public void ThrowExceptionOnSqlConnectionUpdateViaTableNameIfThereIsNoKeyField()
{
// Setup
var data = Helper.CreateDynamicNonKeyedTable();

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
var data = new
{
ColumnInt = 1,
ColumnDecimal = 2
};
connection.Update(ClassMappedNameCache.Get<NonIdentityTable>(), data);
// Act
connection.Update(ClassMappedNameCache.Get<NonIdentityTable>(), (object)data);
}
}

[TestMethod, ExpectedException(typeof(EmptyException))]
public void ThrowExceptionOnSqlConnectionUpdateViaTableNameIfTheFieldsAreNotFound()
{
// Setup
var data = new
{
Id = 1,
AnyField = 1
};

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
var data = new
{
Id = 1,
AnyField = 1
};
// Act
connection.Update(ClassMappedNameCache.Get<NonIdentityTable>(), data);
}
}
Expand Down
Loading

0 comments on commit 8ee47c4

Please sign in to comment.