Example #1
0
        public async Task GetOrDefaultAsync_OneGenericVersion_Success_Should_ReturnNull()
        {
            IRepositoryAsync <TestAggregateRoot> repository = new TestAggregateRootRepository1(_Context);

            var entity = await repository.GetOrDefaultAsync(new object[] { Guid.NewGuid() });

            entity.Should().BeNull();
        }
Example #2
0
        public async Task DeleteAsync_OneGenericVersion_Success_Should_HaveZeroCountInTrackedEntities()
        {
            const int expCount = 0;
            IRepositoryAsync <TestAggregateRoot> repository = new TestAggregateRootRepository1(_Context);
            var aggregateRoot = new TestAggregateRoot("testing");

            var entry = await repository.DeleteAsync(new object[] { aggregateRoot.Id });

            entry.Should().BeNull();
            _Context.ChangeTracker.Entries <TestAggregateRoot>()
            .Should().HaveCount(expCount);
        }
Example #3
0
        public async Task UpdateAsync_OneGenericVersion_Success_Should_AddEntityWithModifiedState()
        {
            const int expCount = 1;
            IRepositoryAsync <TestAggregateRoot> repository = new TestAggregateRootRepository1(_Context);
            var aggregateRoot = new TestAggregateRoot("testing");

            var entry = await repository.UpdateAsync(aggregateRoot);

            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.Modified);
        }
Example #4
0
        public async Task GetAsync_OneGenericVersion_Success_Should_ReturnEntityInDatabase()
        {
            var aggregateRoot = new TestAggregateRoot("testing");

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

            _Context.ChangeTracker.Clear();

            IRepositoryAsync <TestAggregateRoot> repository = new TestAggregateRootRepository1(_Context);

            var entity = await repository.GetAsync(new object[] { aggregateRoot.Id });

            entity.Should().NotBeNull();
        }
Example #5
0
        public async Task GetAsync_OneGenericVersion_Success_Should_ReturnEntitiesInDatabase()
        {
            var aggregateRoot = new TestAggregateRoot("testing");
            var expCount      = 1;

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

            _Context.ChangeTracker.Clear();

            IRepositoryAsync <TestAggregateRoot> repository = new TestAggregateRootRepository1(_Context);

            var list = await repository.GetAsync();

            list.Should().HaveCount(expCount);
        }
Example #6
0
        public async Task DeleteAsync_OneGenericVersion_Success_Should_AddEntityWithDeletedState()
        {
            const int expCount      = 1;
            var       aggregateRoot = new TestAggregateRoot("testing");

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

            _Context.ChangeTracker.Clear();

            IRepositoryAsync <TestAggregateRoot> repository = new TestAggregateRootRepository1(_Context);

            var entry = await repository.DeleteAsync(new object[] { 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);
        }