Exemplo n.º 1
0
        public async Task ListAllAsync_WithTracking_ShouldReturnEntities()
        {
            // 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.GetAll(true);

            // Assert
            result.Should()
            .NotBeNull().And
            .HaveCount(2);
        }
Exemplo n.º 2
0
        public async Task ListAllAsyncWithSpecification_ShouldApplySpecification()
        {
            // Arrange
            TestEntity[] entities = _fixture.CreateMany <TestEntity>(2).ToArray();

            var dbContextMock = new DbContextMock <TestDbContext>(_options);

            dbContextMock.CreateDbSetMock(x => x.TestEntities, (x, _) => x.Id, entities);
            dbContextMock.Setup(s => s.Set <TestEntity>().AsQueryable()).Returns(entities.AsQueryable());
            var repository = new ReadBaseRepository <TestEntity, Guid, TestDbContext>(dbContextMock.Object);

            var specification = new Mock <ISpecification <TestEntity> >();

            // Act
            TestEntity[] result = await repository.GetAll(specification.Object);

            // Assert
            result.Should()
            .NotBeEmpty().And
            .BeOfType(typeof(TestEntity[])).And
            .BeEquivalentTo(entities);
        }