Beispiel #1
0
        public async Task GetByIdAsync_UnknownIdAndWithTracking_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 ReadBaseRepository <TestEntity, Guid, TestDbContext>(dbContextMock.Object);

            // Act
            TestEntity result = await repository.GetById(Guid.NewGuid(), true);

            // Assert
            result.Should().BeNull();
        }
Beispiel #2
0
        public async Task GetByIdAsync_ShouldReturnEntity()
        {
            // 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 ReadBaseRepository <TestEntity, Guid, TestDbContext>(dbContextMock.Object);

            // Act
            TestEntity result = await repository.GetById(entities[0].Id);

            // Assert
            result.Should().NotBeNull();
            result.Should().BeEquivalentTo(entities[0]);
        }