Skip to content

Commit

Permalink
repository tests
Browse files Browse the repository at this point in the history
Signed-off-by: Lillie Dae <lillie.dae@answerdigital.com>
  • Loading branch information
lillie-dae committed Sep 21, 2023
1 parent 442f4c9 commit 2a8bb5d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ public DicomAssociationInfoRepositoryTest(SqliteDatabaseFixture databaseFixture)
_logger.Setup(p => p.IsEnabled(It.IsAny<LogLevel>())).Returns(true);
}

[Fact]
public async Task GivenDestinationApplicationEntitiesInTheDatabase_WhenGetAllAsyncCalled_ExpectLimitedEntitiesToBeReturned()
{
var store = new DicomAssociationInfoRepository(_serviceScopeFactory.Object, _logger.Object, _options);
var startTime = DateTime.Now;
var endTime = DateTime.MinValue;
var filter = new Func<DicomAssociationInfo, bool>(t =>
t.DateTimeDisconnected >= startTime.ToUniversalTime() &&
t.DateTimeDisconnected <= endTime.ToUniversalTime());

var expected = _databaseFixture.DatabaseContext.Set<DicomAssociationInfo>()
.Where(filter)
.Skip(0)
.Take(1)
.ToList();
var actual = await store.GetAllAsync(0, 1, startTime, endTime, default).ConfigureAwait(false);

Assert.NotNull(actual);
Assert.Equal(expected, actual);
}

[Fact]
public async Task GivenADicomAssociationInfo_WhenAddingToDatabase_ExpectItToBeSaved()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ public async Task GivenADicomAssociationInfo_WhenAddingToDatabase_ExpectItToBeSa
actual!.DateTimeDisconnected.Should().BeCloseTo(association.DateTimeDisconnected, TimeSpan.FromMilliseconds(500));
}

[Fact]
public async Task GivenDestinationApplicationEntitiesInTheDatabase_WhenGetAllAsyncCalled_ExpectLimitedEntitiesToBeReturned()
{
var store = new DicomAssociationInfoRepository(_serviceScopeFactory.Object, _logger.Object, _options, _databaseFixture.Options);

var collection = _databaseFixture.Database.GetCollection<DicomAssociationInfo>(nameof(DicomAssociationInfo));
var startTime = DateTime.Now;
var endTime = DateTime.MinValue;
var builder = Builders<DicomAssociationInfo>.Filter;
var filter = builder.Empty;
filter &= builder.Where(t => t.DateTimeDisconnected >= startTime.ToUniversalTime());
filter &= builder.Where(t => t.DateTimeDisconnected <= endTime.ToUniversalTime());
var expected = await collection.Find(filter).ToListAsync().ConfigureAwait(false);
var actual = await store.GetAllAsync(0, 1, startTime, endTime, default).ConfigureAwait(false);

actual.Should().NotBeNull();
actual.Should().BeEquivalentTo(expected, options => options.Excluding(p => p.DateTimeCreated));
}

[Fact]
public async Task GivenDestinationApplicationEntitiesInTheDatabase_WhenToListIsCalled_ExpectAllEntitiesToBeReturned()
{
Expand Down

0 comments on commit 2a8bb5d

Please sign in to comment.