public async Task AddUserAndAddAudit_Abort_UserNull() { //arrange var user = User.CreateSample(); IMongoDatabase db = _mongoRsResource.CreateDatabase(); await db.CreateCollectionAsync("users"); using (IClientSessionHandle session = await _mongoRsResource.Client.StartSessionAsync()) { var repo = new UserRepositoryWithTransaction(db); session.StartTransaction(); //act await repo.AddAsync(user, session); await session.AbortTransactionAsync(); } //assert User createdUser = await GetUserAsync(db, user.Id); createdUser.Should().BeNull(); }
public async Task AddUserAndAddAudit_Commit_RecordsExsists() { //arrange var user = User.CreateSample(); var audit = UserAudit.CreateSample(user.Id); IMongoDatabase db = _mongoRsResource.CreateDatabase(); await db.CreateCollectionAsync("users"); await db.CreateCollectionAsync("audit"); using (IClientSessionHandle session = await _mongoRsResource.Client.StartSessionAsync()) { var repo = new UserRepositoryWithTransaction(db); session.StartTransaction(); //act await repo.AddAsync(user, session); await repo.AddAuditAsync(audit, session); await session.CommitTransactionAsync(); } //assert User createdUser = await GetUserAsync(db, user.Id); createdUser.Should().BeEquivalentTo(user); UserAudit createdAudit = await GetUserAuditAsync(db, audit.Id); createdAudit.Should().BeEquivalentTo(audit); }