Example #1
0
        private void RegisterAuditTypes()
        {
            var auditTypeInfo = new AuditTypeInfo(typeof(Category), typeof(CategoryAudit));

            this.RegisterAuditType(auditTypeInfo);

            auditTypeInfo = new AuditTypeInfo(typeof(Transaction), typeof(TransactionAudit));
            this.RegisterAuditType(auditTypeInfo);
        }
        public void ShouldSuccessfullyCreateAuditTypeInfo()
        {
            // Arrange
            var auditableEntityType = typeof(TestEntity);
            var auditEntityType     = typeof(TestEntityAudit);

            // Act
            var auditTypeInfo = new AuditTypeInfo(auditableEntityType, auditEntityType);

            // Assert
            auditTypeInfo.Should().NotBeNull();
        }
Example #3
0
        public void ShouldFailToRegisterAuditTypeTwice()
        {
            // Arrange
            var auditTypeInfo = new AuditTypeInfo(typeof(TestEntity), typeof(TestEntityAudit));
            var context       = this.CreateContext();

            context.RegisterAuditType(auditTypeInfo);

            // Act
            Action action = () => context.RegisterAuditType(auditTypeInfo);

            // Assert
            action.Should().Throw <ArgumentException>().Which.Message.Should().Contain("Type TestEntity is already registered for auditing.");
        }
Example #4
0
        public void ShouldRegisterAuditType()
        {
            // Arrange
            var auditTypeInfo = new AuditTypeInfo(typeof(TestEntity), typeof(TestEntityAudit));
            var context       = this.CreateContext();

            // Act
            context.RegisterAuditType(auditTypeInfo);

            // Assert
            context.TestEntities.Add(new TestEntity());
            context.SaveChanges(TestAuditUser);

            var testEntityAudits = context.TestEntityAudits.ToList();

            testEntityAudits.Should().HaveCount(1);
            testEntityAudits.ElementAt(0).AuditType.Should().Be(AuditEntityState.Added);
        }