public Tests() { IConfigurationRoot config = DependencyInjectionWiring.BuildConfig(); TestHarnessDbConfig testConfig = new TestHarnessDbConfig(); config.GetSection("TestHarnessDbConfig").Bind(testConfig); _provider = new TestHarnessUnitOfWorkProvider(testConfig); _repo = new TestHarnessRepository(_provider); }
public async Task Basic_Transaction_Management_Async() { ParentModel initial = null; ParentModel intrans = null; ParentModel outside = null; int id; TestHarnessRepository repo2 = new TestHarnessRepository(_provider); TestHarnessRepository repo3 = new TestHarnessRepository(_provider); IAsyncUnitOfWork uow = await _repo.CreateAsyncUnitOfWork(new[] { _repo, repo2, repo3 }); using (uow) { try { initial = await _repo.GetOnlyParentByNameAsync("crm"); id = initial.Id; initial = await _repo.GetParentByIdAsync(id); await repo2.InsertChildAsync(new ClientRedirectUri { ClientId = id, Uri = "asdfasdf" }); await repo3.InsertChildAsync(new ClientRedirectUri { ClientId = id, Uri = "fdsafdsa" }); intrans = await _repo.GetParentByIdAsync(id); await _repo.DbOperationAsync("crm"); } finally { uow.RollbackTransaction(); } } outside = await _repo.GetParentByIdAsync(id); initial.Should().NotBeNull(); intrans.Should().NotBeNull(); outside.Should().NotBeNull(); initial.Children.Should().NotBeNullOrEmpty(); intrans.Children.Should().NotBeNullOrEmpty(); outside.Children.Should().NotBeNullOrEmpty(); initial.Children.Count().Should().Be(intrans.Children.Count() - 2); initial.Children.Count().Should().Be(outside.Children.Count()); }
public void Basic_Transaction_Management() { ParentModel initial = null; ParentModel intrans = null; TestHarnessRepository repo2 = new TestHarnessRepository(_provider); TestHarnessRepository repo3 = new TestHarnessRepository(_provider); IUnitOfWork uow = _repo.CreateUnitOfWork(new[] { _repo, repo2, repo3 }); using (uow) { try { initial = _repo.GetOnlyParentByName("crm"); initial = _repo.GetParentById(initial.Id); repo2.InsertChild(new ClientRedirectUri { ClientId = initial.Id, Uri = "asdfasdf" }); repo3.InsertChild(new ClientRedirectUri { ClientId = initial.Id, Uri = "fdsafdsa" }); intrans = _repo.GetParentById(initial.Id); } finally { uow.RollbackTransaction(); } } initial.Should().NotBeNull(); intrans.Should().NotBeNull(); initial.Children.Should().NotBeNullOrEmpty(); intrans.Children.Should().NotBeNullOrEmpty(); initial.Children.Count().Should().Be(intrans.Children.Count() - 2); }