public async void QueryAsync_MustReturn_Entity(bool includeReferences)
        {
            // Arrange
            var sut        = new ReadOnlyRepositoryFixture(includeReferences);
            var entite     = sut.Configuration.DbSet.First();
            var entities   = sut.Configuration.DbSet.Where(e => e.Id != entite.Id).OrderBy(e => e.Id);
            var enumerator = entities.GetEnumerator();

            // Act
            var computed = await sut.QueryAsync(e => e.Id != entite.Id, 0, int.MaxValue);

            // Assert
            Assert.Equal(entities.Count(), computed.Count());
            Assert.All(computed, c =>
            {
                enumerator.MoveNext();
                Assert.Equal(enumerator.Current.Id, c.Id);
                if (includeReferences)
                {
                    Assert.NotNull(enumerator.Current.Reference);
                    Assert.NotNull(enumerator.Current.Collection);
                    Assert.NotEmpty(enumerator.Current.Collection);
                }
            });
        }
        public async void AnyAsync_MustCheck_Parameters()
        {
            // Arrange
            var repository = new ReadOnlyRepositoryFixture(false);

            // Act

            // Assert
            await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => await repository.AnyAsync(-1, 100));

            await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => await repository.AnyAsync(0, -1));
        }
        public void Constructor_MustSet_Properties()
        {
            // Arrange
            var fixture   = new Fixture();
            var dbContext = new DbContextFixture();

            // Act
            var sut = new ReadOnlyRepositoryFixture(dbContext, c => c.TestData);

            // Assert
            Assert.NotNull(sut.Configuration);
        }
        public async void CountAsync_MustReturn_Count(bool includeReferences)
        {
            // Arrange
            var sut = new ReadOnlyRepositoryFixture(includeReferences);

            // Act
            var computed = await sut.CountAsync();

            var computed2 = await sut.CountAsync(e => false);

            // Assert
            Assert.Equal(sut.Configuration.DbSet.Count(), computed);
            Assert.Equal(0, computed2);
        }
        public async void QueryAsync_MustCheck_Parameters()
        {
            // Arrange
            var repository = new ReadOnlyRepositoryFixture(false);

            // Act

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(async() => await repository.QueryAsync(null, 0, 100));

            await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => await repository.QueryAsync((o) => false, -1, 100));

            await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => await repository.QueryAsync((o) => false, 0, -1));

            await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => await repository.QueryAsync((o) => false, 0, 1, (SortOrder)(-1)));
        }
        public async void FindAsync_MustReturn_Entity(bool includeReferences)
        {
            // Arrange
            var sut    = new ReadOnlyRepositoryFixture(includeReferences);
            var entity = sut.Configuration.DbSet.Last();

            // Act
            var computed = await sut.FindAsync(entity.Id);

            // Assert
            Assert.NotNull(computed.Id);
            Assert.Equal(entity.Id, computed.Id);

            if (includeReferences)
            {
                Assert.NotNull(computed.Reference);
                Assert.NotNull(computed.Collection);
                Assert.NotEmpty(computed.Collection);
            }
        }
Ejemplo n.º 7
0
 public ReadOnlyRepositoryTests(ReadOnlyRepositoryFixture <TestModel> fixture)
 {
     _repository = fixture.Repository;
 }