Пример #1
0
        public async Task GetAsync_TwoGenericVersion_Success_Should_ReturnFalse()
        {
            IRepositoryAsync <TestAggregateRoot, Guid> repository = new TestAggregateRootRepository2(_Context);

            var exist = await repository.CheckExistAsync(Guid.NewGuid());

            exist.Should().BeFalse();
        }
Пример #2
0
        public async Task GetOrDefaultAsync_TwoGenericVersion_Success_Should_ReturnNull()
        {
            IRepositoryAsync <TestAggregateRoot, Guid> repository = new TestAggregateRootRepository2(_Context);

            var entity = await repository.GetOrDefaultAsync(Guid.NewGuid());

            entity.Should().BeNull();
        }
Пример #3
0
        public async Task GetAsync_TwoGenericVersion_Failure_Should_ThrowInvalidOperationException()
        {
            IRepositoryAsync <TestAggregateRoot, Guid> repository = new TestAggregateRootRepository2(_Context);

            Func <Task> act = () => repository.GetAsync(Guid.NewGuid());

            await act.Should().ThrowExactlyAsync <InvalidOperationException>()
            .WithMessage("entity");
        }
Пример #4
0
        public async Task DeleteAsync_TwoGenericVersion_Success_Should_HaveZeroCountInTrackedEntities()
        {
            const int expCount = 0;
            IRepositoryAsync <TestAggregateRoot, Guid> repository = new TestAggregateRootRepository2(_Context);
            var aggregateRoot = new TestAggregateRoot("testing");

            var entry = await repository.DeleteAsync(aggregateRoot.Id);

            entry.Should().BeNull();
            _Context.ChangeTracker.Entries <TestAggregateRoot>()
            .Should().HaveCount(expCount);
        }
Пример #5
0
        public async Task GetAsync_TwoGenericVersion_Success_Should_ReturnTrue()
        {
            var aggregateRoot = new TestAggregateRoot("testing");

            _Context.Add(aggregateRoot);
            await _Context.SaveChangesAsync();

            _Context.ChangeTracker.Clear();

            IRepositoryAsync <TestAggregateRoot, Guid> repository = new TestAggregateRootRepository2(_Context);

            var exist = await repository.CheckExistAsync(aggregateRoot.Id);

            exist.Should().BeTrue();
        }
Пример #6
0
        public async Task GetOrDefaultAsync_TwoGenericVersion_Success_Should_ReturnEntityInDatabase()
        {
            var aggregateRoot = new TestAggregateRoot("testing");

            _Context.Add(aggregateRoot);
            await _Context.SaveChangesAsync();

            _Context.ChangeTracker.Clear();

            IRepositoryAsync <TestAggregateRoot, Guid> repository = new TestAggregateRootRepository2(_Context);

            var entity = await repository.GetOrDefaultAsync(aggregateRoot.Id);

            entity.Should().NotBeNull();
        }
Пример #7
0
        public async Task GetCountAsync_Success_Should_ReturnEntityInPaginatedList_Detail_ThirdPage()
        {
            var expCount = 5;

            _Context.AddRange(new TestAggregateRoot("testing"), new TestAggregateRoot("testing"),
                              new TestAggregateRoot("testing"), new TestAggregateRoot("testing"), new TestAggregateRoot("testing"));
            await _Context.SaveChangesAsync();

            _Context.ChangeTracker.Clear();

            IRepositoryAsync <TestAggregateRoot, Guid> repository = new TestAggregateRootRepository2(_Context);

            var count = await repository.GetCountAsync();

            count.Should().Be(expCount);
        }
Пример #8
0
        public async Task PaginateAsync_Success_Should_ReturnEntityInPaginatedList_Detail_ThirdPage()
        {
            var expCount = 0;
            var page     = 2;
            var take     = 3;

            _Context.AddRange(new TestAggregateRoot("testing"), new TestAggregateRoot("testing"),
                              new TestAggregateRoot("testing"), new TestAggregateRoot("testing"), new TestAggregateRoot("testing"));
            await _Context.SaveChangesAsync();

            _Context.ChangeTracker.Clear();

            IRepositoryAsync <TestAggregateRoot, Guid> repository = new TestAggregateRootRepository2(_Context);

            var list = await repository.PaginateAsync(page, take);

            list.Should().HaveCount(expCount);
        }
Пример #9
0
        public async Task DeleteAsync_TwoGenericVersion_Success_Should_AddEntityWithDeletedState()
        {
            const int expCount      = 1;
            var       aggregateRoot = new TestAggregateRoot("testing");

            _Context.Add(aggregateRoot);
            await _Context.SaveChangesAsync();

            _Context.ChangeTracker.Clear();

            IRepositoryAsync <TestAggregateRoot, Guid> repository = new TestAggregateRootRepository2(_Context);

            var entry = await repository.DeleteAsync(aggregateRoot.Id);

            entry.Should().NotBeNull();
            _Context.ChangeTracker.Entries <TestAggregateRoot>()
            .Should().HaveCount(expCount);
            _Context.ChangeTracker.Entries <TestAggregateRoot>()
            .Should().Contain(e => e.Entity.Id == aggregateRoot.Id && e.State == EntityState.Deleted);
        }