public async Task Test_Begin_With_Null_Who_Throws_Exception() { // ARRANGE Mock <ILogger <VirtualBridgeData> > loggerMock = MockFactory.CreateLoggerMock <VirtualBridgeData>(); DbContextOptions <DataContext> dbOptions = TestUtils.DbContextOptionsInMemory <TestBeginCommit>( nameof(this.Test_Begin_With_Null_Who_Throws_Exception)); await using DataContext dataContext = new DataContext(dbOptions); Mock <IAuditHeaderRepository> auditHeaderRepositoryMock = MockFactory.CreateRepositoryMock <IAuditHeaderRepository>(); Mock <IOrganisationRepository> organisationRepositoryMock = MockFactory.CreateRepositoryMock <IOrganisationRepository>(); VirtualBridgeData data = new VirtualBridgeData( logger: loggerMock.Object, dataContext: dataContext, auditHeaderRepository: auditHeaderRepositoryMock.Object, organisationRepository: organisationRepositoryMock.Object); // ACT _ = data.BeginTransactionAsync( who: null !, auditEvent: EAuditEvent.OrganisationMaintenance) .ConfigureAwait(false); }
public async Task Test_Rollback_With_Null_Who_Throws_Exception() { // ARRANGE Mock <ILogger <VirtualBridgeData> > loggerMock = MockFactory.CreateLoggerMock <VirtualBridgeData>(); DbContextOptions <DataContext> dbOptions = TestUtils.DbContextOptionsInMemory <TestBeginCommit>( nameof(this.Test_Rollback_Does_Not_Thorw_Exception)); await using DataContext dataContext = new DataContext(dbOptions); Mock <IAuditHeaderRepository> auditHeaderRepositoryMock = MockFactory.CreateRepositoryMock <IAuditHeaderRepository>(); Mock <IOrganisationRepository> organisationRepositoryMock = MockFactory.CreateRepositoryMock <IOrganisationRepository>(); VirtualBridgeData data = new VirtualBridgeData( logger: loggerMock.Object, dataContext: dataContext, auditHeaderRepository: auditHeaderRepositoryMock.Object, organisationRepository: organisationRepositoryMock.Object); // ACT data.RollbackTransaction( who: null !); }
public async Task Test_Commit_Writes_Record() { // ARRANGE Mock <ILogger <VirtualBridgeData> > loggerMock = MockFactory.CreateLoggerMock <VirtualBridgeData>(); Mock <ILogger <AuditHeaderRepository> > auditHeaderRepositoryLoggerMock = MockFactory.CreateLoggerMock <AuditHeaderRepository>(); DbContextOptions <DataContext> dbOptions = TestUtils.DbContextOptionsInMemory <TestBeginCommit>( nameof(this.Test_Commit_Writes_Record)); await using DataContext dataContext = new DataContext(dbOptions); AuditHeaderRepository auditHeaderRepository = new AuditHeaderRepository( logger: auditHeaderRepositoryLoggerMock.Object, dataContext: dataContext); Mock <IOrganisationRepository> organisationRepositoryMock = MockFactory.CreateRepositoryMock <IOrganisationRepository>(); VirtualBridgeData data = new VirtualBridgeData( logger: loggerMock.Object, dataContext: dataContext, auditHeaderRepository: auditHeaderRepository, organisationRepository: organisationRepositoryMock.Object); IWho who = Create.Who(); // ACT IAuditHeaderWithAuditDetails auditHeader = await data.BeginTransactionAsync( who : who, auditEvent : EAuditEvent.OrganisationMaintenance) .ConfigureAwait(false); auditHeader.AuditDetails.Add( AuditDetail.CreateForCreate( auditHeader: auditHeader, tableName: "Organisation", columnName: "Name", recordId: Guid.NewGuid(), newValue: "NewValue")); await data.CommitTransactionAsync(who, auditHeader) .ConfigureAwait(false); // ASSERT int auditHeadersCount = await dataContext.AuditHeaders.CountAsync() .ConfigureAwait(false); int auditDetailsCount = await dataContext.AuditDetails.CountAsync() .ConfigureAwait(false); Assert.AreEqual(1, auditHeadersCount); Assert.AreEqual(1, auditDetailsCount); }
public async Task Test_Rollback_Does_Not_Thorw_Exception() { // ARRANGE Mock <ILogger <VirtualBridgeData> > loggerMock = MockFactory.CreateLoggerMock <VirtualBridgeData>(); DbContextOptions <DataContext> dbOptions = TestUtils.DbContextOptionsInMemory <TestBeginCommit>( nameof(this.Test_Rollback_Does_Not_Thorw_Exception)); await using DataContext dataContext = new DataContext(dbOptions); Mock <IAuditHeaderRepository> auditHeaderRepositoryMock = MockFactory.CreateRepositoryMock <IAuditHeaderRepository>(); Mock <IOrganisationRepository> organisationRepositoryMock = MockFactory.CreateRepositoryMock <IOrganisationRepository>(); VirtualBridgeData data = new VirtualBridgeData( logger: loggerMock.Object, dataContext: dataContext, auditHeaderRepository: auditHeaderRepositoryMock.Object, organisationRepository: organisationRepositoryMock.Object); IWho who = Create.Who(); // ACT IAuditHeaderWithAuditDetails auditHeader = await data.BeginTransactionAsync( who : who, auditEvent : EAuditEvent.OrganisationMaintenance) .ConfigureAwait(false); data.RollbackTransaction(who); await data.CommitTransactionAsync(who, auditHeader) .ConfigureAwait(false); // ASSERT Assert.IsTrue(true); }