Beispiel #1
0
        public async Task Commit_UOWHasChild_CallCommitCore()
        {
            Func <DbContext> dbContextFactory = () => new Mock <DbContext>().Object;

            var unitOfWorkRegistryStub = new ThreadLocalUnitOfWorkRegistry();

            var unitOfWorkProvider = new EntityFrameworkUnitOfWorkProvider(unitOfWorkRegistryStub, dbContextFactory);

            var unitOfWorkParentMock = new Mock <EntityFrameworkUnitOfWork>(unitOfWorkProvider, dbContextFactory, DbContextOptions.ReuseParentContext)
            {
                CallBase = true
            };

            using (var unitOfWorkParent = unitOfWorkParentMock.Object)
            {
                unitOfWorkRegistryStub.RegisterUnitOfWork(unitOfWorkParent);

                using (var unitOfWorkChild = new EntityFrameworkUnitOfWork(unitOfWorkProvider, dbContextFactory, DbContextOptions.ReuseParentContext))
                {
                    await unitOfWorkChild.CommitAsync();
                }

                await unitOfWorkParent.CommitAsync();
            }
            unitOfWorkParentMock.Protected().Verify("CommitAsyncCore", Times.Once(), new CancellationToken());
        }
Beispiel #2
0
        public async Task CanRemove()
        {
            using (var unitOfWork = new EntityFrameworkUnitOfWork(new TestDbContext()))
            {
                var countFish = (await unitOfWork.Repository.QueryAsync <Fish>()).Count();
                await unitOfWork.Repository.RemoveAsync((await unitOfWork.Repository.QueryAsync <Fish>()).First());

                await unitOfWork.CommitAsync();

                var newCountFish = (await unitOfWork.Repository.QueryAsync <Fish>()).Count();
                newCountFish.Should().Be.EqualTo(countFish - 1);
            }
        }
Beispiel #3
0
        public async Task CanUpdate()
        {
            using (var unitOfWork = new EntityFrameworkUnitOfWork(new TestDbContext()))
            {
                var fish = (await unitOfWork.Repository.QueryAsync <Fish>()).First();
                fish.Name.Should().Not.Be.EqualTo("NewName");
                fish.Name = "NewName";
                await unitOfWork.Repository.UpdateAsync(fish);

                await unitOfWork.CommitAsync();

                var updatedFish = (await unitOfWork.Repository.QueryAsync <Fish>()).First(x => x.Id == fish.Id);
                updatedFish.Name.Should().Be.EqualTo("NewName");
            }
        }