Skip to content

Commit

Permalink
Initial integration tests for immutable classes. #465
Browse files Browse the repository at this point in the history
  • Loading branch information
mikependon committed Aug 22, 2020
1 parent 26d6290 commit 59328ab
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/ImmutableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ public void TestSqlConnectionMergeForImmutableWithNonEmptyTable()
// Act
var insertResult = connection.Merge<ImmutableIdentityTable, long>(entity);

// The ID could not be set back to the entities, so it should be 0

// Setup
var newEntity = new ImmutableIdentityTable(insertResult,
entity.RowGuid,
Expand All @@ -180,9 +178,11 @@ public void TestSqlConnectionMergeForImmutableWithNonEmptyTable()
// Act
var mergeResult = connection.Merge<ImmutableIdentityTable, long>(newEntity);

// The ID could not be set back to the entities, so it should be 0

// Assert
Assert.IsTrue(mergeResult > 0);
Assert.AreEqual(entity.Id, mergeResult);
Assert.AreEqual(insertResult, mergeResult);

// Act
var queryResult = connection.Query<ImmutableIdentityTable>(newEntity.Id).FirstOrDefault();
Expand Down Expand Up @@ -229,12 +229,12 @@ public void TestSqlConnectionMergeAllForImmutable()
public void TestSqlConnectionMergeAllForImmutableWithNonEmptyTables()
{
// Setup
var entities = Helper.CreateImmutableIdentityTables(10);
var entities = Helper.CreateIdentityTables(10);

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
var insertAllResult = connection.InsertAll<ImmutableIdentityTable>(entities);
var insertAllResult = connection.InsertAll<IdentityTable>(entities);

// Setup
var newEntities = entities.Select(entity => new ImmutableIdentityTable(entity.Id,
Expand All @@ -253,18 +253,13 @@ public void TestSqlConnectionMergeAllForImmutableWithNonEmptyTables()
// Assert
Assert.AreEqual(entities.Count, mergeAllResult);

// The ID could not be set back to the entities, so it should be 0

// Assert
Assert.IsTrue(entities.All(e => e.Id == 0));

// Act
var queryResult = connection.QueryAll<ImmutableIdentityTable>().AsList();
var queryResult = connection.QueryAll<IdentityTable>().AsList();

// Assert
Assert.AreEqual(entities.Count, queryResult.Count());
newEntities.ForEach(entity =>
Helper.AssertPropertiesEquality(entity, queryResult[entities.IndexOf(entity)]));
Helper.AssertPropertiesEquality(entity, queryResult[newEntities.IndexOf(entity)]));
}
}

Expand Down Expand Up @@ -299,12 +294,12 @@ public void TestSqlConnectionQueryForImmutable()
public void TestSqlConnectionUpdateForImmutableViaDataEntity()
{
// Setup
var entity = Helper.CreateImmutableIdentityTable();
var entity = Helper.CreateIdentityTable();

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
connection.Insert<ImmutableIdentityTable, long>(entity);
connection.Insert<IdentityTable, long>(entity);

// Setup
var newEntity = new ImmutableIdentityTable(entity.Id,
Expand Down Expand Up @@ -336,12 +331,12 @@ public void TestSqlConnectionUpdateForImmutableViaDataEntity()
public void TestSqlConnectionUpdateForImmutableViaPrimaryKey()
{
// Setup
var entity = Helper.CreateImmutableIdentityTable();
var entity = Helper.CreateIdentityTable();

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
connection.Insert<ImmutableIdentityTable, long>(entity);
connection.Insert<IdentityTable>(entity);

// Setup
var newEntity = new ImmutableIdentityTable(entity.Id,
Expand Down Expand Up @@ -377,12 +372,12 @@ public void TestSqlConnectionUpdateForImmutableViaPrimaryKey()
public void TestSqlConnectionUpdateAllForImmutable()
{
// Setup
var entities = Helper.CreateImmutableIdentityTables(10);
var entities = Helper.CreateIdentityTables(10);

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
connection.InsertAll<ImmutableIdentityTable>(entities);
connection.InsertAll<IdentityTable>(entities);

// Setup
var newEntities = entities.Select(entity => new ImmutableIdentityTable(entity.Id,
Expand All @@ -407,7 +402,7 @@ public void TestSqlConnectionUpdateAllForImmutable()
// Assert
Assert.AreEqual(entities.Count, queryResult.Count());
newEntities.ForEach(entity =>
Helper.AssertPropertiesEquality(entity, queryResult[entities.IndexOf(entity)]));
Helper.AssertPropertiesEquality(entity, queryResult[newEntities.IndexOf(entity)]));
}
}

Expand Down

0 comments on commit 59328ab

Please sign in to comment.