public void GetByIdAsync_Should_Return_The_Expected_Data(Mock <ISessionManager> mockSessionManager, DefaultSession session, Dummy data) { //Arrange mockSessionManager.Setup(m => m.Current) .Returns(session); var options = new DbContextOptionsBuilder <DummyContext>() .UseInMemoryDatabase("DummyDb") .Options; using (var context = new DummyContext(options, mockSessionManager.Object)) { var repository = new WriteRepository <DummyContext, Dummy>(context); repository.Add(data); } //Act Task <Dummy> dummyData; using (var context = new DummyContext(options, mockSessionManager.Object)) { var repository = new ReadRepository <DummyContext, Dummy>(context); dummyData = repository.GetByIdAsync(data.Id); } //Assert dummyData.Result.Should().BeEquivalentTo(data); }
public async Task GetByIdAsync_UnknownId_ShouldReturnNull() { // Arrange TestEntity[] entities = _fixture.CreateMany <TestEntity>(2).ToArray(); var dbContextMock = new DbContextMock <TestDbContext>(_options); dbContextMock.CreateDbSetMock(x => x.TestEntities, (x, _) => (x.Id), entities); var repository = new ReadRepository <TestEntity, Guid>(() => dbContextMock.Object); // Act TestEntity result = await repository.GetByIdAsync(Guid.NewGuid()); // Assert result.Should().BeNull(); }