Skip to content

Commit

Permalink
Feat(Tests): Bringing back the old ef repository tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphsodyz committed Jun 25, 2024
1 parent 5de99cb commit fc0d697
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
9 changes: 9 additions & 0 deletions Tests/Unit.Tests/Fixture/TestDatabaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,18 @@ private void SeedDatabase()
{
Context.Launch.AddRange(TestLaunchInMemoryObjects.Test1(), TestLaunchInMemoryObjects.Test2(), TestLaunchInMemoryObjects.Test3());
Context.SaveChanges();

DetachEntitiesEfChangeTracker();
}
}

public void DetachEntitiesEfChangeTracker()
{
var entries = Context.ChangeTracker.Entries().ToList();
foreach (var entry in entries)
entry.State = EntityState.Detached;
}

public Launch NewObjectForSaveTests()
{
return new Launch()
Expand Down
17 changes: 9 additions & 8 deletions Tests/Unit.Tests/Repository.Layer/LaunchRepositoryTest.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System.Linq.Expressions;
using Domain.Interface;
using Infrastructure.Persistence.Context;
using Tests.Test.Objects;
using Tests.Unit.Tests.Fixture;

namespace Tests.Unit.Tests.Repository.Layer
{
public class LaunchRepositoryTest : IClassFixture<TestDatabaseFixture>
{
/*private readonly TestDatabaseFixture _fixture;
private readonly TestDatabaseFixture _fixture;
public LaunchRepositoryTest(TestDatabaseFixture fixture)
{
_fixture = fixture;
Expand Down Expand Up @@ -361,13 +362,13 @@ public async Task GenericRepository_GetSelected_GetOneLaunchWithIncludeAndBuildD
public async Task GenericRepository_UpdateOnQuery_UpdateDatabaseObjectsWithoutBringToMemory()
{
//Arrange
_fixture.DetachEntitiesEfChangeTracker();
Expression<Func<Launch, bool>> selectedLaunch = l => l.Id == new Guid("000ebc80-d782-4dee-8606-1199d9074039");
Expression<Func<Launch, Launch>> updateStatusColumn = l => new Launch()
{ EntityStatus = EStatus.TRASH.GetDisplayName() };

//Act
await _fixture.Launch.UpdateOnQuery(selectedLaunch, updateStatusColumn);
_fixture.TransferUpdatedObjectsQueryContext();

//Assert
var getAssertInMemoryObject = await _fixture.Launch.GetSelected(
Expand All @@ -379,6 +380,7 @@ public async Task GenericRepository_UpdateOnQuery_UpdateDatabaseObjectsWithoutBr
Assert.Equal(getAssertInMemoryObject, EStatus.TRASH.GetDisplayName());

//Rolling back the change for the other tests...
_fixture.DetachEntitiesEfChangeTracker();
Expression<Func<Launch, Launch>> rollbackUpdate = l => new Launch()
{ EntityStatus = EStatus.PUBLISHED.GetDisplayName() };
await _fixture.Launch.UpdateOnQuery(selectedLaunch, rollbackUpdate);
Expand Down Expand Up @@ -428,7 +430,6 @@ public async Task GenericRepository_Save_SaveANewObjectInMemoryWithTransaction()
launchRepository.Setup(l => l.Save(It.IsAny<Launch>()));
launchRepository.Setup(l => l.CommitTransaction())
.Callback(async () => await _fixture.Launch.Save(newLaunch));
_fixture.TransferUpdatedObjectsQueryContext();

//Act
await launchRepository.Object.BeginTransaction();
Expand Down Expand Up @@ -500,10 +501,9 @@ public async Task GenericRepository_Save_UpdateAEntityWithSaveMethod()
{
//Arrange
Expression<Func<Launch, bool>> qryTest = l => l.Id == TestLaunchInMemoryObjects.Test1().Id;
var entityToBeUpdated = await _fixture.Launch.Get(filter: qryTest);
entityToBeUpdated.EntityStatus = EStatus.TRASH.GetDisplayName();

entityToBeUpdated.EntityStatus = EStatus.TRASH.GetDisplayName();
Assert.Equal(EStatus.PUBLISHED.GetDisplayName(), await _fixture.Launch.GetSelected(
filter: qryTest,
selectColumns:l => l.EntityStatus,
Expand All @@ -514,11 +514,12 @@ public async Task GenericRepository_Save_UpdateAEntityWithSaveMethod()
await _fixture.Launch.Save(entityToBeUpdated);

//Assert
Assert.Equal(EStatus.TRASH.GetDisplayName(), await _fixture.Launch.GetSelected(
var newStatus = await _fixture.Launch.GetSelected(
filter: qryTest,
selectColumns:l => l.EntityStatus,
buildObject: l => l
));
);
Assert.Equal(EStatus.TRASH.GetDisplayName(), newStatus);

//Rollback the changes..
entityToBeUpdated.EntityStatus = EStatus.PUBLISHED.GetDisplayName();
Expand Down Expand Up @@ -555,6 +556,6 @@ public async Task GenericRepository_Delete_DeleteEntityById()

//Assert
Assert.Equal(3, await _fixture.Launch.EntityCount());
}*/
}
}
}

0 comments on commit fc0d697

Please sign in to comment.