Skip to content

Commit

Permalink
Fixed UpdateAsync tests to adjust for new handling of empty enumerables
Browse files Browse the repository at this point in the history
  • Loading branch information
Psypher9 committed Apr 18, 2023
1 parent b818067 commit 72d190d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tests/Repositorty.Tests/KeylessRepositoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,28 @@ public async Task UpdateAsync_SimplyCalls_DbSaveChangesAsync()
sut = new KeylessRepository(_db);

// Act
await sut.UpdateAsync(Array.Empty<Trillig>());
await sut.UpdateAsync(new List<Trillig>() { new Trillig(), new Trillig(), new Trillig() });

mockDb.Verify(x => x.SaveChangesAsync(It.IsAny<CancellationToken>()), Times.Once());
mockSet.Verify(x => x.UpdateRange(It.IsAny<IEnumerable<Trillig>>()), Times.Once);
}

[Fact]
public async Task UpdateAsync_When_No_Entities_DoesNotCall_DbSaveChangesAsync()
{
// Arrange
var mockDb = new Mock<TestDbContext>(new DbContextOptionsBuilder<TestDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);
var mockSet = new Mock<DbSet<Trillig>>();
mockDb.Setup(x => x.SaveChangesAsync(It.IsAny<CancellationToken>())).ReturnsAsync(1);
mockDb.Setup(x => x.Set<Trillig>()).Returns(mockSet.Object);
_db = mockDb.Object;
sut = new KeylessRepository(_db);

// Act
await sut.UpdateAsync(Array.Empty<Trillig>());

mockDb.Verify(x => x.SaveChangesAsync(It.IsAny<CancellationToken>()), Times.Never);
mockSet.Verify(x => x.UpdateRange(It.IsAny<IEnumerable<Trillig>>()), Times.Never);
}
}
}

0 comments on commit 72d190d

Please sign in to comment.