Пример #1
0
        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);
        }
Пример #2
0
        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);
        }