Пример #1
0
        public void TestShortConstructorWithValidValues()
        {
            // ARRANGE
            const EAuditEvent paramAuditEvent = EAuditEvent.OrganisationMaintenance;
            const string      paramUsername   = "******";
            Guid paramCorrelationId           = Guid.NewGuid();

            // ACT
            IAuditHeaderWithAuditDetails auditHeaderWithAuditDetails = new AuditHeaderWithAuditDetails(
                auditEvent: paramAuditEvent,
                username: paramUsername,
                correlationId: paramCorrelationId);

            // ASSERT
            double seconds = (DateTime.Now - auditHeaderWithAuditDetails.TimeStamp).TotalSeconds;

            Assert.AreNotEqual(Guid.Empty, auditHeaderWithAuditDetails.Id);
            Assert.AreEqual(paramAuditEvent, auditHeaderWithAuditDetails.AuditEvent);
            Assert.IsTrue(seconds >= 0 && seconds <= 5);
            Assert.AreEqual(paramUsername, auditHeaderWithAuditDetails.Username);
            Assert.AreNotEqual(Guid.Empty, auditHeaderWithAuditDetails.CorrelationId);
            Assert.AreEqual(paramCorrelationId, auditHeaderWithAuditDetails.CorrelationId);
            Assert.IsNotNull(auditHeaderWithAuditDetails.AuditDetails);
            Assert.AreEqual(0, auditHeaderWithAuditDetails.AuditDetails.Count);
        }
Пример #2
0
        public void TestFullConstructorWithValidValues()
        {
            // ARRANGE
            Guid paramId = Guid.NewGuid();
            const EAuditEvent paramAuditEvent      = EAuditEvent.OrganisationMaintenance;
            DateTime          paramTimeStamp       = DateTime.Now;
            const string      paramUsername        = "******";
            Guid paramCorrelationId                = Guid.NewGuid();
            IList <IAuditDetail> paramAuditDetails = new List <IAuditDetail>();

            // ACT
            IAuditHeaderWithAuditDetails auditHeaderWithAuditDetails = new AuditHeaderWithAuditDetails(
                id: paramId,
                auditEvent: paramAuditEvent,
                timeStamp: paramTimeStamp,
                username: paramUsername,
                correlationId: paramCorrelationId,
                auditDetails: paramAuditDetails);

            // ASSERT
            Assert.AreNotEqual(Guid.Empty, auditHeaderWithAuditDetails.Id);
            Assert.AreEqual(paramId, auditHeaderWithAuditDetails.Id);
            Assert.AreEqual(paramAuditEvent, auditHeaderWithAuditDetails.AuditEvent);
            Assert.AreEqual(paramTimeStamp, auditHeaderWithAuditDetails.TimeStamp);
            Assert.AreEqual(paramUsername, auditHeaderWithAuditDetails.Username);
            Assert.AreNotEqual(Guid.Empty, auditHeaderWithAuditDetails.CorrelationId);
            Assert.AreEqual(paramCorrelationId, auditHeaderWithAuditDetails.CorrelationId);
            Assert.AreSame(paramAuditDetails, auditHeaderWithAuditDetails.AuditDetails);
        }
Пример #3
0
        public void Test_Passing_Valid_Values()
        {
            // ARRANGE
            IAuditHeaderWithAuditDetails auditHeader = new AuditHeaderWithAuditDetails(
                auditEvent: EAuditEvent.OrganisationMaintenance,
                username: "******",
                correlationId: Guid.NewGuid());

            IAuditDetail auditDetail = new AuditDetail(
                id: Guid.NewGuid(),
                auditHeader: auditHeader,
                tableName: "TableName",
                columnName: "ColumnName",
                recordId: Guid.NewGuid(),
                oldValue: "Old Value",
                newValue: "New Value",
                databaseAction: EDatabaseAction.Update);

            auditHeader.AuditDetails.Add(auditDetail);

            // ACT
            AuditHeaderDto auditHeaderDto = AuditHeaderDto.ToDtoWithAuditDetails(auditHeader);

            // ASSERT
            Assert.AreEqual(auditHeader.Id, auditHeaderDto.Id);
            Assert.AreEqual(auditHeader.AuditEvent, auditHeaderDto.AuditEvent);
            Assert.AreEqual(auditHeader.TimeStamp, auditHeaderDto.TimeStamp);
            Assert.AreEqual(auditHeader.Username, auditHeaderDto.Username);
            Assert.AreEqual(auditHeader.CorrelationId, auditHeaderDto.CorrelationId);
            Assert.IsNotNull(auditHeaderDto.AuditDetails);
        }
Пример #4
0
        public async Task Test_With_Valid_Values()
        {
            // ARRANGE
            Mock <ILogger <AuditHeaderRepository> > loggerMock =
                TestUtilities.MockFactory.CreateLoggerMock <AuditHeaderRepository>();
            DbContextOptions <DataContext> dbOptions =
                TestUtils.DbContextOptionsInMemory <CreateAsyncTests>(nameof(this.Test_With_Valid_Values));

            await using DataContext dataContext = new DataContext(dbOptions);

            IAuditHeaderRepository repository = new AuditHeaderRepository(
                loggerMock.Object,
                dataContext);

            IAuditHeaderWithAuditDetails auditHeader = new AuditHeaderWithAuditDetails(
                auditEvent: EAuditEvent.OrganisationMaintenance,
                username: "******",
                correlationId: Guid.NewGuid());
            IAuditDetail auditDetail = AuditDetail.CreateForUpdate(
                auditHeader: auditHeader,
                tableName: "TableName",
                columnName: "ColumnName",
                recordId: Guid.NewGuid(),
                oldValue: "Old Value",
                newValue: "New Value");

            auditHeader.AuditDetails.Add(auditDetail);

            IWho who = new Who(
                "TestController",
                "Action",
                "/TestController/Action",
                string.Empty);

            // ACT
            await repository.CreateAsync(who, auditHeader)
            .ConfigureAwait(false);

            // ASSERT
            Assert.AreEqual(1, await dataContext.AuditHeaders.CountAsync().ConfigureAwait(false));
            Assert.AreEqual(1, await dataContext.AuditDetails.CountAsync().ConfigureAwait(false));
        }
Пример #5
0
        /// <inheritdoc />
        public Task <IAuditHeaderWithAuditDetails> BeginTransactionAsync(
            IWho who,
            EAuditEvent auditEvent)
        {
            if (who == null)
            {
                throw new ArgumentNullException(nameof(who));
            }

            return(BeginTransactionInternalAsync());

            async Task <IAuditHeaderWithAuditDetails> BeginTransactionInternalAsync()
            {
                this.logger.LogTrace(
                    "ENTRY {Method}(who, auditEvent) {@Who} {@AuditEvent}",
                    nameof(this.BeginTransactionAsync),
                    who,
                    auditEvent);

                await this.context.Database.BeginTransactionAsync()
                .ConfigureAwait(false);

                AuditHeaderWithAuditDetails auditHeader = new AuditHeaderWithAuditDetails(
                    auditEvent: auditEvent,
                    username: "******",
                    correlationId: who.CorrelationId);

                this.logger.LogTrace(
                    "EXIT {Method}(who, auditHeader) {@Who} {@AuditHeader}",
                    nameof(this.BeginTransactionAsync),
                    who,
                    auditHeader);

                return(auditHeader);
            }
        }