コード例 #1
0
        public void Entity_Basic()
        {
            TestContext.DeleteAll(x => x.AuditEntries);
            TestContext.DeleteAll(x => x.Entity_Basics);

            TestContext.Insert(x => x.Entity_Basics, 3);

            var audit = AuditHelper.AutoSaveAudit();

            using (var ctx = new TestContext())
            {
                ctx.Entity_Basics.ToList().ForEach(x => x.ColumnInt++);

                ctx.SaveChanges(audit);
            }

            // UnitTest - Audit
            {
                var entries = audit.Entries;

                // Entries
                {
                    // Entries Count
                    Assert.AreEqual(3, entries.Count);

                    // Entries State
                    Assert.AreEqual(AuditEntryState.EntityModified, entries[0].State);
                    Assert.AreEqual(AuditEntryState.EntityModified, entries[1].State);
                    Assert.AreEqual(AuditEntryState.EntityModified, entries[2].State);

                    // Entries EntitySetName
                    Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basics), entries[0].EntitySetName);
                    Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basics), entries[1].EntitySetName);
                    Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basics), entries[2].EntitySetName);

                    // Entries TypeName
                    Assert.AreEqual(typeof(Entity_Basic).Name, entries[0].TypeName);
                    Assert.AreEqual(typeof(Entity_Basic).Name, entries[1].TypeName);
                    Assert.AreEqual(typeof(Entity_Basic).Name, entries[2].TypeName);
                }

                // Properties
                {
                    var propertyIndex = -1;

                    // Properties Count
                    Assert.AreEqual(1, entries[0].Properties.Count);
                    Assert.AreEqual(1, entries[1].Properties.Count);
                    Assert.AreEqual(1, entries[2].Properties.Count);

                    // ColumnInt
                    propertyIndex = 0;
                    Assert.AreEqual("ColumnInt", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ColumnInt", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ColumnInt", entries[2].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(0, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(1, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(2, entries[2].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(1, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(2, entries[1].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(3, entries[2].Properties[propertyIndex].NewValue);
                }
            }

            // UnitTest - Audit (Database)
            {
                using (var ctx = new TestContext())
                {
                    // ENSURE order
                    var entries = ctx.AuditEntries.OrderBy(x => x.AuditEntryID).Include(x => x.Properties).ToList();
                    entries.ForEach(x => x.Properties = x.Properties.OrderBy(y => y.AuditEntryPropertyID).ToList());

                    // Entries
                    {
                        // Entries Count
                        Assert.AreEqual(3, entries.Count);

                        // Entries State
                        Assert.AreEqual(AuditEntryState.EntityModified, entries[0].State);
                        Assert.AreEqual(AuditEntryState.EntityModified, entries[1].State);
                        Assert.AreEqual(AuditEntryState.EntityModified, entries[2].State);

                        // Entries EntitySetName
                        Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basics), entries[0].EntitySetName);
                        Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basics), entries[1].EntitySetName);
                        Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basics), entries[2].EntitySetName);

                        // Entries TypeName
                        Assert.AreEqual(typeof(Entity_Basic).Name, entries[0].TypeName);
                        Assert.AreEqual(typeof(Entity_Basic).Name, entries[1].TypeName);
                        Assert.AreEqual(typeof(Entity_Basic).Name, entries[2].TypeName);
                    }

                    // Properties
                    {
                        var propertyIndex = -1;

                        // Properties Count
                        Assert.AreEqual(1, entries[0].Properties.Count);
                        Assert.AreEqual(1, entries[1].Properties.Count);
                        Assert.AreEqual(1, entries[2].Properties.Count);

                        // ColumnInt
                        propertyIndex = 0;
                        Assert.AreEqual("ColumnInt", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ColumnInt", entries[1].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ColumnInt", entries[2].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("0", entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("1", entries[1].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("2", entries[2].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("1", entries[0].Properties[propertyIndex].NewValue);
                        Assert.AreEqual("2", entries[1].Properties[propertyIndex].NewValue);
                        Assert.AreEqual("3", entries[2].Properties[propertyIndex].NewValue);
                    }
                }
            }
        }
コード例 #2
0
        public void All()
        {
            var identitySeedCat = TestContext.GetIdentitySeed(x => x.Inheritance_TPC_Animals, Inheritance_TPC_Cat.Create);
            var identitySeedDog = TestContext.GetIdentitySeed(x => x.Inheritance_TPC_Animals, Inheritance_TPC_Dog.Create);

            TestContext.DeleteAll(x => x.AuditEntryProperties);
            TestContext.DeleteAll(x => x.AuditEntries);
            TestContext.DeleteAll(x => x.Inheritance_TPC_Animals);

            var audit = AuditHelper.AutoSaveAudit();

            audit.Configuration.ExcludeProperty();

            using (var ctx = new TestContext())
            {
                TestContext.Insert(ctx, x => x.Inheritance_TPC_Animals, Inheritance_TPC_Cat.Create, 1);
                TestContext.Insert(ctx, x => x.Inheritance_TPC_Animals, Inheritance_TPC_Dog.Create, 2);
                ctx.SaveChanges(audit);
            }

            // UnitTest - Audit
            {
                var entries = audit.Entries;

                // Entries
                {
                    // Entries Count
                    Assert.AreEqual(3, entries.Count);

                    // Entries State
                    Assert.AreEqual(AuditEntryState.EntityAdded, entries[0].State);
                    Assert.AreEqual(AuditEntryState.EntityAdded, entries[1].State);
                    Assert.AreEqual(AuditEntryState.EntityAdded, entries[2].State);

                    // Entries EntitySetName
                    Assert.AreEqual(TestContext.TypeName(x => x.Inheritance_TPC_Animals), entries[0].EntitySetName);
                    Assert.AreEqual(TestContext.TypeName(x => x.Inheritance_TPC_Animals), entries[1].EntitySetName);
                    Assert.AreEqual(TestContext.TypeName(x => x.Inheritance_TPC_Animals), entries[2].EntitySetName);

                    // Entries TypeName
                    Assert.AreEqual(typeof(Inheritance_TPC_Cat).Name, entries[0].EntityTypeName);
                    Assert.AreEqual(typeof(Inheritance_TPC_Dog).Name, entries[1].EntityTypeName);
                    Assert.AreEqual(typeof(Inheritance_TPC_Dog).Name, entries[2].EntityTypeName);
                }

                // Properties
                {
                    // Properties Count
                    Assert.AreEqual(0, entries[0].Properties.Count);
                    Assert.AreEqual(0, entries[1].Properties.Count);
                    Assert.AreEqual(0, entries[2].Properties.Count);
                }
            }

            // UnitTest - Audit (Database)
            {
                using (var ctx = new TestContext())
                {
                    // ENSURE order
                    var entries = ctx.AuditEntries.OrderBy(x => x.AuditEntryID).Include(x => x.Properties).ToList();
                    entries.ForEach(x => x.Properties = x.Properties.OrderBy(y => y.AuditEntryPropertyID).ToList());

                    // Entries
                    {
                        // Entries Count
                        Assert.AreEqual(3, entries.Count);

                        // Entries State
                        Assert.AreEqual(AuditEntryState.EntityAdded, entries[0].State);
                        Assert.AreEqual(AuditEntryState.EntityAdded, entries[1].State);
                        Assert.AreEqual(AuditEntryState.EntityAdded, entries[2].State);

                        // Entries EntitySetName
                        Assert.AreEqual(TestContext.TypeName(x => x.Inheritance_TPC_Animals), entries[0].EntitySetName);
                        Assert.AreEqual(TestContext.TypeName(x => x.Inheritance_TPC_Animals), entries[1].EntitySetName);
                        Assert.AreEqual(TestContext.TypeName(x => x.Inheritance_TPC_Animals), entries[2].EntitySetName);

                        // Entries TypeName
                        Assert.AreEqual(typeof(Inheritance_TPC_Cat).Name, entries[0].EntityTypeName);
                        Assert.AreEqual(typeof(Inheritance_TPC_Dog).Name, entries[1].EntityTypeName);
                        Assert.AreEqual(typeof(Inheritance_TPC_Dog).Name, entries[2].EntityTypeName);
                    }

                    // Properties
                    {
                        // Properties Count
                        Assert.AreEqual(0, entries[0].Properties.Count);
                        Assert.AreEqual(0, entries[1].Properties.Count);
                        Assert.AreEqual(0, entries[2].Properties.Count);
                    }
                }
            }
        }
コード例 #3
0
        public void Inheritance_TPC()
        {
            var identitySeedCat = TestContext.GetIdentitySeed(x => x.Inheritance_TPC_Animals, Inheritance_TPC_Cat.Create);
            var identitySeedDog = TestContext.GetIdentitySeed(x => x.Inheritance_TPC_Animals, Inheritance_TPC_Dog.Create);

            TestContext.DeleteAll(x => x.AuditEntryProperties);
            TestContext.DeleteAll(x => x.AuditEntries);
            TestContext.DeleteAll(x => x.Inheritance_TPC_Animals);

            TestContext.Insert(x => x.Inheritance_TPC_Animals, Inheritance_TPC_Cat.Create, 1);
            TestContext.Insert(x => x.Inheritance_TPC_Animals, Inheritance_TPC_Dog.Create, 2);

            var audit = AuditHelper.AutoSaveAudit();

            using (var ctx = new TestContext())
            {
                TestContext.DeleteAll(ctx, x => x.Inheritance_TPC_Animals);

                ctx.SaveChanges(audit);
            }

            // UnitTest - Audit
            {
                var entries = audit.Entries;

                // Entries
                {
                    // Entries Count
                    Assert.AreEqual(3, entries.Count);

                    // Entries State
                    Assert.AreEqual(AuditEntryState.EntityDeleted, entries[0].State);
                    Assert.AreEqual(AuditEntryState.EntityDeleted, entries[1].State);
                    Assert.AreEqual(AuditEntryState.EntityDeleted, entries[2].State);

                    // Entries EntitySetName
                    Assert.AreEqual(TestContext.TypeName(x => x.Inheritance_TPC_Animals), entries[0].EntitySetName);
                    Assert.AreEqual(TestContext.TypeName(x => x.Inheritance_TPC_Animals), entries[1].EntitySetName);
                    Assert.AreEqual(TestContext.TypeName(x => x.Inheritance_TPC_Animals), entries[2].EntitySetName);

                    // Entries TypeName
                    Assert.AreEqual(typeof(Inheritance_TPC_Dog).Name, entries[0].EntityTypeName);
                    Assert.AreEqual(typeof(Inheritance_TPC_Dog).Name, entries[1].EntityTypeName);
                    Assert.AreEqual(typeof(Inheritance_TPC_Cat).Name, entries[2].EntityTypeName);
                }

                // Properties
                {
                    var propertyIndex = -1;

                    // Properties Count
                    Assert.AreEqual(3, entries[0].Properties.Count);
                    Assert.AreEqual(3, entries[1].Properties.Count);
                    Assert.AreEqual(3, entries[2].Properties.Count);

                    // ID
                    propertyIndex = 0;
                    Assert.AreEqual("ID", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ID", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ID", entries[2].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(identitySeedDog + 1, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(identitySeedDog + 2, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(identitySeedCat + 1, entries[2].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(null, entries[1].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(null, entries[2].Properties[propertyIndex].NewValue);

                    // ColumnInt
                    propertyIndex = 1;
                    Assert.AreEqual("ColumnInt", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ColumnInt", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ColumnInt", entries[2].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(0, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(1, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(0, entries[2].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(null, entries[1].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(null, entries[2].Properties[propertyIndex].NewValue);

                    // ColumnCat | ColumnDog
                    propertyIndex = 2;
                    Assert.AreEqual("ColumnDog", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ColumnDog", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ColumnCat", entries[2].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(0, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(1, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(0, entries[2].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(null, entries[1].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(null, entries[2].Properties[propertyIndex].NewValue);
                }
            }

            // UnitTest - Audit (Database)
            {
                using (var ctx = new TestContext())
                {
                    // ENSURE order
                    var entries = ctx.AuditEntries.OrderBy(x => x.AuditEntryID).Include(x => x.Properties).ToList();
                    entries.ForEach(x => x.Properties = x.Properties.OrderBy(y => y.AuditEntryPropertyID).ToList());

                    // Entries
                    {
                        // Entries Count
                        Assert.AreEqual(3, entries.Count);

                        // Entries State
                        Assert.AreEqual(AuditEntryState.EntityDeleted, entries[0].State);
                        Assert.AreEqual(AuditEntryState.EntityDeleted, entries[1].State);
                        Assert.AreEqual(AuditEntryState.EntityDeleted, entries[2].State);

                        // Entries EntitySetName
                        Assert.AreEqual(TestContext.TypeName(x => x.Inheritance_TPC_Animals), entries[0].EntitySetName);
                        Assert.AreEqual(TestContext.TypeName(x => x.Inheritance_TPC_Animals), entries[1].EntitySetName);
                        Assert.AreEqual(TestContext.TypeName(x => x.Inheritance_TPC_Animals), entries[2].EntitySetName);

                        // Entries TypeName
                        Assert.AreEqual(typeof(Inheritance_TPC_Dog).Name, entries[0].EntityTypeName);
                        Assert.AreEqual(typeof(Inheritance_TPC_Dog).Name, entries[1].EntityTypeName);
                        Assert.AreEqual(typeof(Inheritance_TPC_Cat).Name, entries[2].EntityTypeName);
                    }

                    // Properties
                    {
                        var propertyIndex = -1;

                        // Properties Count
                        Assert.AreEqual(3, entries[0].Properties.Count);
                        Assert.AreEqual(3, entries[1].Properties.Count);
                        Assert.AreEqual(3, entries[2].Properties.Count);

                        // ID
                        propertyIndex = 0;
                        Assert.AreEqual("ID", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ID", entries[1].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ID", entries[2].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual((identitySeedDog + 1).ToString(), entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual((identitySeedDog + 2).ToString(), entries[1].Properties[propertyIndex].OldValue);
                        Assert.AreEqual((identitySeedCat + 1).ToString(), entries[2].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(null, entries[0].Properties[propertyIndex].NewValue);
                        Assert.AreEqual(null, entries[1].Properties[propertyIndex].NewValue);
                        Assert.AreEqual(null, entries[2].Properties[propertyIndex].NewValue);

                        // ColumnInt
                        propertyIndex = 1;
                        Assert.AreEqual("ColumnInt", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ColumnInt", entries[1].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ColumnInt", entries[2].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("0", entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("1", entries[1].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("0", entries[2].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(null, entries[0].Properties[propertyIndex].NewValue);
                        Assert.AreEqual(null, entries[1].Properties[propertyIndex].NewValue);
                        Assert.AreEqual(null, entries[2].Properties[propertyIndex].NewValue);

                        // ColumnCat | ColumnDog
                        propertyIndex = 2;
                        Assert.AreEqual("ColumnDog", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ColumnDog", entries[1].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ColumnCat", entries[2].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("0", entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("1", entries[1].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("0", entries[2].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(null, entries[0].Properties[propertyIndex].NewValue);
                        Assert.AreEqual(null, entries[1].Properties[propertyIndex].NewValue);
                        Assert.AreEqual(null, entries[2].Properties[propertyIndex].NewValue);
                    }
                }
            }
        }
コード例 #4
0
        public void IgnoreEntityModified_IsFalse()
        {
            TestContext.DeleteAll(x => x.AuditEntryProperties);
            TestContext.DeleteAll(x => x.AuditEntries);
            TestContext.DeleteAll(x => x.Entity_Basics);

            TestContext.Insert(x => x.Entity_Basics, 2);

            var audit = AuditHelper.AutoSaveAudit();

            Assert.AreEqual(false, audit.Configuration.IgnoreEntityModified);

            using (var ctx = new TestContext())
            {
                var list = ctx.Entity_Basics.OrderBy(x => x.ID).ToList();

                // INSERT one
                TestContext.Insert(ctx, x => x.Entity_Basics, 1);

                // DELETE one
                ctx.Entity_Basics.Remove(list[0]);

                // UPDATE one
                list[1].ColumnInt++;

                ctx.SaveChanges(audit);
            }

            // UnitTest - Audit
            {
                var entries = audit.Entries;

                // Entries
                {
                    // Entries Count
                    Assert.AreEqual(3, entries.Count);

                    // Entries State
                    Assert.AreEqual(AuditEntryState.EntityAdded, entries[0].State);
                    Assert.AreEqual(AuditEntryState.EntityModified, entries[1].State);
                    Assert.AreEqual(AuditEntryState.EntityDeleted, entries[2].State);
                }
            }

            // UnitTest - Audit (Database)
            {
                using (var ctx = new TestContext())
                {
                    // ENSURE order
                    var entries = ctx.AuditEntries.OrderBy(x => x.AuditEntryID).ToList();

                    // Entries
                    {
                        // Entries Count
                        Assert.AreEqual(3, entries.Count);

                        // Entries State
                        Assert.AreEqual(AuditEntryState.EntityAdded, entries[0].State);
                        Assert.AreEqual(AuditEntryState.EntityModified, entries[1].State);
                        Assert.AreEqual(AuditEntryState.EntityDeleted, entries[2].State);
                    }
                }
            }
        }
コード例 #5
0
        public void IncludeRelationshipDeleted_IsFalse()
        {
            TestContext.DeleteAll(x => x.AuditEntries);
            TestContext.DeleteAll(x => x.Association_OneToMany_Lefts);
            TestContext.DeleteAll(x => x.Association_OneToMany_Rights);

            var audit = AuditHelper.AutoSaveAudit();

            audit.Configuration.IncludeRelationshipDeleted = false;

            using (var ctx = new TestContext())
            {
                var left = TestContext.Insert(ctx, x => x.Association_OneToMany_Lefts, 2).First();

                var right = new Association_OneToMany_Right {
                    ColumnInt = 0
                };

                left.Rights = new List <Association_OneToMany_Right> {
                    right
                };
                ctx.SaveChanges();
            }

            using (var ctx = new TestContext())
            {
                var list  = ctx.Association_OneToMany_Lefts.OrderBy(x => x.ID).ToList();
                var right = ctx.Association_OneToMany_Rights.First();

                // DELETE one
                list[0].Rights.Clear();

                // INSERT one
                list[1].Rights = new List <Association_OneToMany_Right> {
                    right
                };

                ctx.SaveChanges(audit);
            }

            // UnitTest - Audit
            {
                var entries = audit.Entries;

                // Entries
                {
                    // Entries Count
                    Assert.AreEqual(1, entries.Count);

                    // Entries State
                    Assert.AreEqual(AuditEntryState.RelationshipAdded, entries[0].State);
                }
            }

            // UnitTest - Audit (Database)
            {
                using (var ctx = new TestContext())
                {
                    // ENSURE order
                    var entries = ctx.AuditEntries.OrderBy(x => x.AuditEntryID).ToList();

                    // Entries
                    {
                        // Entries Count
                        Assert.AreEqual(1, entries.Count);

                        // Entries State
                        Assert.AreEqual(AuditEntryState.RelationshipAdded, entries[0].State);
                    }
                }
            }
        }
コード例 #6
0
        public void CurrentPrincipal()
        {
            var identitySeed = TestContext.GetIdentitySeed(x => x.Entity_Basics);

            TestContext.DeleteAll(x => x.AuditEntryProperties);
            TestContext.DeleteAll(x => x.AuditEntries);
            TestContext.DeleteAll(x => x.Entity_Basics);

            var audit     = AuditHelper.AutoSaveAudit();
            var createdBy = audit.CreatedBy;

            using (var ctx = new TestContext())
            {
                TestContext.Insert(ctx, x => x.Entity_Basics, 3);
                ctx.SaveChanges(audit);
            }

            // UnitTest - Audit
            {
                var entries = audit.Entries;

                // Entries
                {
                    Assert.AreNotEqual(null, createdBy);

                    // Entries Count
                    Assert.AreEqual(3, entries.Count);

                    // Entries State
                    Assert.AreEqual(AuditEntryState.EntityAdded, entries[0].State);
                    Assert.AreEqual(AuditEntryState.EntityAdded, entries[1].State);
                    Assert.AreEqual(AuditEntryState.EntityAdded, entries[2].State);

                    // Entries EntitySetName
                    Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basics), entries[0].EntitySetName);
                    Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basics), entries[1].EntitySetName);
                    Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basics), entries[2].EntitySetName);

                    // Entries TypeName
                    Assert.AreEqual(typeof(Entity_Basic).Name, entries[0].EntityTypeName);
                    Assert.AreEqual(typeof(Entity_Basic).Name, entries[1].EntityTypeName);
                    Assert.AreEqual(typeof(Entity_Basic).Name, entries[2].EntityTypeName);

                    // Entries CreatedBy
                    Assert.AreEqual(createdBy, entries[0].CreatedBy);
                    Assert.AreEqual(createdBy, entries[1].CreatedBy);
                    Assert.AreEqual(createdBy, entries[2].CreatedBy);
                }

                // Properties
                {
                    var propertyIndex = -1;

                    // Properties Count
                    Assert.AreEqual(2, entries[0].Properties.Count);
                    Assert.AreEqual(2, entries[1].Properties.Count);
                    Assert.AreEqual(2, entries[2].Properties.Count);

                    // ID
                    propertyIndex = 0;
                    Assert.AreEqual("ID", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ID", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ID", entries[2].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(null, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[2].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(identitySeed + 1, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(identitySeed + 2, entries[1].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(identitySeed + 3, entries[2].Properties[propertyIndex].NewValue);

                    // ColumnInt
                    propertyIndex = 1;
                    Assert.AreEqual("ColumnInt", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ColumnInt", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ColumnInt", entries[2].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(null, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[2].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(0, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(1, entries[1].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(2, entries[2].Properties[propertyIndex].NewValue);
                }
            }

            // UnitTest - Audit (Database)
            {
                using (var ctx = new TestContext())
                {
                    // ENSURE order
                    var entries = ctx.AuditEntries.OrderBy(x => x.AuditEntryID).Include(x => x.Properties).ToList();
                    entries.ForEach(x => x.Properties = x.Properties.OrderBy(y => y.AuditEntryPropertyID).ToList());

                    // Entries
                    {
                        // Entries Count
                        Assert.AreEqual(3, entries.Count);

                        // Entries State
                        Assert.AreEqual(AuditEntryState.EntityAdded, entries[0].State);
                        Assert.AreEqual(AuditEntryState.EntityAdded, entries[1].State);
                        Assert.AreEqual(AuditEntryState.EntityAdded, entries[2].State);

                        // Entries EntitySetName
                        Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basics), entries[0].EntitySetName);
                        Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basics), entries[1].EntitySetName);
                        Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basics), entries[2].EntitySetName);

                        // Entries TypeName
                        Assert.AreEqual(typeof(Entity_Basic).Name, entries[0].EntityTypeName);
                        Assert.AreEqual(typeof(Entity_Basic).Name, entries[1].EntityTypeName);
                        Assert.AreEqual(typeof(Entity_Basic).Name, entries[2].EntityTypeName);

                        // Entries CreatedBy
                        Assert.AreEqual(createdBy, entries[0].CreatedBy);
                        Assert.AreEqual(createdBy, entries[1].CreatedBy);
                        Assert.AreEqual(createdBy, entries[2].CreatedBy);
                    }

                    // Properties
                    {
                        var propertyIndex = -1;

                        // Properties Count
                        Assert.AreEqual(2, entries[0].Properties.Count);
                        Assert.AreEqual(2, entries[1].Properties.Count);
                        Assert.AreEqual(2, entries[2].Properties.Count);

                        // ID
                        propertyIndex = 0;
                        Assert.AreEqual("ID", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ID", entries[1].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ID", entries[2].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual(null, entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(null, entries[1].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(null, entries[2].Properties[propertyIndex].OldValue);
                        Assert.AreEqual((identitySeed + 1).ToString(), entries[0].Properties[propertyIndex].NewValue);
                        Assert.AreEqual((identitySeed + 2).ToString(), entries[1].Properties[propertyIndex].NewValue);
                        Assert.AreEqual((identitySeed + 3).ToString(), entries[2].Properties[propertyIndex].NewValue);

                        // ColumnInt
                        propertyIndex = 1;
                        Assert.AreEqual("ColumnInt", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ColumnInt", entries[1].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ColumnInt", entries[2].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual(null, entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(null, entries[1].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(null, entries[2].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("0", entries[0].Properties[propertyIndex].NewValue);
                        Assert.AreEqual("1", entries[1].Properties[propertyIndex].NewValue);
                        Assert.AreEqual("2", entries[2].Properties[propertyIndex].NewValue);
                    }
                }
            }
        }
コード例 #7
0
        public void Association_ManyToMany()
        {
            int leftID;
            int rightID_0;
            int rightID_1;

            TestContext.DeleteAll(x => x.AuditEntries);
            TestContext.DeleteAll(x => x.Association_ManyToMany_Lefts);
            TestContext.DeleteAll(x => x.Association_ManyToMany_Rights);

            var audit = AuditHelper.AutoSaveAudit();

            using (var ctx = new TestContext())
            {
                var left   = TestContext.Insert(ctx, x => x.Association_ManyToMany_Lefts, 1).First();
                var rights = TestContext.Insert(ctx, x => x.Association_ManyToMany_Rights, 2);

                left.Rights = new List <Association_ManyToMany_Right>(rights);

                ctx.SaveChanges();

                leftID    = left.ID;
                rightID_0 = rights[0].ID;
                rightID_1 = rights[1].ID;
            }

            using (var ctx = new TestContext())
            {
                // LOAD relation otherwise we will not know about it.
                var listRight = ctx.Association_ManyToMany_Rights.Include(x => x.Lefts).ToList();
                TestContext.DeleteAll(ctx, x => x.Association_ManyToMany_Rights);
                ctx.SaveChanges(audit);
            }

            // UnitTest - Audit
            {
                var entries = audit.Entries;

                // Entries
                {
                    // Entries Count
                    Assert.AreEqual(4, entries.Count);

                    // Entries State
                    Assert.AreEqual(AuditEntryState.RelationshipDeleted, entries[0].State);
                    Assert.AreEqual(AuditEntryState.RelationshipDeleted, entries[1].State);

                    // Entries EntitySetName
                    Assert.AreEqual("Association_ManyToMany_Left_Rights", entries[0].EntitySetName);
                    Assert.AreEqual("Association_ManyToMany_Left_Rights", entries[1].EntitySetName);

                    // Entries TypeName
                    Assert.AreEqual(null, entries[0].TypeName);
                    Assert.AreEqual(null, entries[1].TypeName);
                }

                // Properties
                {
                    var propertyIndex = -1;

                    // Properties Count
                    Assert.AreEqual(2, entries[0].Properties.Count);
                    Assert.AreEqual(2, entries[1].Properties.Count);

                    // Association_ManyToMany_Left_Rights_Source;ID
                    propertyIndex = 0;
                    Assert.AreEqual("Association_ManyToMany_Left_Rights_Source;ID", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("Association_ManyToMany_Left_Rights_Source;ID", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(leftID, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(leftID, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(null, entries[1].Properties[propertyIndex].NewValue);

                    propertyIndex = 1;
                    Assert.AreEqual("Association_ManyToMany_Left_Rights_Target;ID", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("Association_ManyToMany_Left_Rights_Target;ID", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(rightID_0, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(rightID_1, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(null, entries[1].Properties[propertyIndex].NewValue);
                }
            }

            // UnitTest - Audit (Database)
            {
                using (var ctx = new TestContext())
                {
                    // ENSURE order
                    var entries = ctx.AuditEntries.OrderBy(x => x.AuditEntryID).Include(x => x.Properties).ToList();
                    entries.ForEach(x => x.Properties = x.Properties.OrderBy(y => y.AuditEntryPropertyID).ToList());

                    // Entries
                    {
                        // Entries Count
                        Assert.AreEqual(4, entries.Count);

                        // Entries State
                        Assert.AreEqual(AuditEntryState.RelationshipDeleted, entries[0].State);
                        Assert.AreEqual(AuditEntryState.RelationshipDeleted, entries[1].State);

                        // Entries EntitySetName
                        Assert.AreEqual("Association_ManyToMany_Left_Rights", entries[0].EntitySetName);
                        Assert.AreEqual("Association_ManyToMany_Left_Rights", entries[1].EntitySetName);

                        // Entries TypeName
                        Assert.AreEqual(null, entries[0].TypeName);
                        Assert.AreEqual(null, entries[1].TypeName);
                    }

                    // Properties
                    {
                        var propertyIndex = -1;

                        // Properties Count
                        Assert.AreEqual(2, entries[0].Properties.Count);
                        Assert.AreEqual(2, entries[1].Properties.Count);

                        // Association_ManyToMany_Left_Rights_Source;ID
                        propertyIndex = 0;
                        Assert.AreEqual("Association_ManyToMany_Left_Rights_Source;ID", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("Association_ManyToMany_Left_Rights_Source;ID", entries[1].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual(leftID.ToString(), entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(leftID.ToString(), entries[1].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(null, entries[0].Properties[propertyIndex].NewValue);
                        Assert.AreEqual(null, entries[1].Properties[propertyIndex].NewValue);

                        propertyIndex = 1;
                        Assert.AreEqual("Association_ManyToMany_Left_Rights_Target;ID", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("Association_ManyToMany_Left_Rights_Target;ID", entries[1].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual(rightID_0.ToString(), entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(rightID_1.ToString(), entries[1].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(null, entries[0].Properties[propertyIndex].NewValue);
                        Assert.AreEqual(null, entries[1].Properties[propertyIndex].NewValue);
                    }
                }
            }
        }
コード例 #8
0
        public void Association_OneToMany()
        {
            int leftID;
            int rightID_0;
            int rightID_1;

            TestContext.DeleteAll(x => x.AuditEntryProperties);
            TestContext.DeleteAll(x => x.AuditEntries);
            TestContext.DeleteAll(x => x.Association_OneToMany_Lefts);
            TestContext.DeleteAll(x => x.Association_OneToMany_Rights);

            var audit = AuditHelper.AutoSaveAudit();

            using (var ctx = new TestContext())
            {
                var left   = TestContext.Insert(ctx, x => x.Association_OneToMany_Lefts, 1).First();
                var right0 = new Association_OneToMany_Right {
                    ColumnInt = 0
                };
                var right1 = new Association_OneToMany_Right {
                    ColumnInt = 1
                };

                left.Rights = new List <Association_OneToMany_Right> {
                    right0, right1
                };

                ctx.SaveChanges(audit);

                leftID    = left.ID;
                rightID_0 = right0.ID;
                rightID_1 = right1.ID;
            }

            // UnitTest - Audit
            {
                var entries = audit.Entries;

                // Entries
                {
                    // Entries Count
                    Assert.AreEqual(5, entries.Count);

                    // Entries State
                    Assert.AreEqual(AuditEntryState.RelationshipAdded, entries[0].State);
                    Assert.AreEqual(AuditEntryState.RelationshipAdded, entries[1].State);

                    // Entries EntitySetName
                    Assert.AreEqual("Association_OneToMany_Left_Rights", entries[0].EntitySetName);
                    Assert.AreEqual("Association_OneToMany_Left_Rights", entries[1].EntitySetName);

                    // Entries TypeName
                    Assert.AreEqual(null, entries[0].EntityTypeName);
                    Assert.AreEqual(null, entries[1].EntityTypeName);
                }

                // Properties
                {
                    var propertyIndex = -1;

                    // Properties Count
                    Assert.AreEqual(2, entries[0].Properties.Count);
                    Assert.AreEqual(2, entries[1].Properties.Count);

                    // Association_OneToMany_Left_Rights_Source;ID
                    propertyIndex = 0;
                    Assert.AreEqual("Association_OneToMany_Left_Rights_Source", entries[0].Properties[propertyIndex].RelationName);
                    Assert.AreEqual("Association_OneToMany_Left_Rights_Source", entries[1].Properties[propertyIndex].RelationName);
                    Assert.AreEqual("ID", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ID", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(null, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(leftID, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(leftID, entries[1].Properties[propertyIndex].NewValue);

                    propertyIndex = 1;
                    Assert.AreEqual("Association_OneToMany_Left_Rights_Target", entries[0].Properties[propertyIndex].RelationName);
                    Assert.AreEqual("Association_OneToMany_Left_Rights_Target", entries[1].Properties[propertyIndex].RelationName);
                    Assert.AreEqual("ID", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ID", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(null, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(rightID_0, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(rightID_1, entries[1].Properties[propertyIndex].NewValue);
                }
            }

            // UnitTest - Audit (Database)
            {
                using (var ctx = new TestContext())
                {
                    // ENSURE order
                    var entries = ctx.AuditEntries.OrderBy(x => x.AuditEntryID).Include(x => x.Properties).ToList();
                    entries.ForEach(x => x.Properties = x.Properties.OrderBy(y => y.AuditEntryPropertyID).ToList());

                    // Entries
                    {
                        // Entries Count
                        Assert.AreEqual(5, entries.Count);

                        // Entries State
                        Assert.AreEqual(AuditEntryState.RelationshipAdded, entries[0].State);
                        Assert.AreEqual(AuditEntryState.RelationshipAdded, entries[1].State);

                        // Entries EntitySetName
                        Assert.AreEqual("Association_OneToMany_Left_Rights", entries[0].EntitySetName);
                        Assert.AreEqual("Association_OneToMany_Left_Rights", entries[1].EntitySetName);

                        // Entries TypeName
                        Assert.AreEqual(null, entries[0].EntityTypeName);
                        Assert.AreEqual(null, entries[1].EntityTypeName);
                    }

                    // Properties
                    {
                        var propertyIndex = -1;

                        // Properties Count
                        Assert.AreEqual(2, entries[0].Properties.Count);
                        Assert.AreEqual(2, entries[1].Properties.Count);

                        // Association_OneToMany_Left_Rights_Source;ID
                        propertyIndex = 0;
                        Assert.AreEqual("Association_OneToMany_Left_Rights_Source", entries[0].Properties[propertyIndex].RelationName);
                        Assert.AreEqual("Association_OneToMany_Left_Rights_Source", entries[1].Properties[propertyIndex].RelationName);
                        Assert.AreEqual("ID", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ID", entries[1].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual(null, entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(null, entries[1].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(leftID.ToString(), entries[0].Properties[propertyIndex].NewValue);
                        Assert.AreEqual(leftID.ToString(), entries[1].Properties[propertyIndex].NewValue);

                        propertyIndex = 1;
                        Assert.AreEqual("Association_OneToMany_Left_Rights_Target", entries[0].Properties[propertyIndex].RelationName);
                        Assert.AreEqual("Association_OneToMany_Left_Rights_Target", entries[1].Properties[propertyIndex].RelationName);
                        Assert.AreEqual("ID", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ID", entries[1].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual(null, entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(null, entries[1].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(rightID_0.ToString(), entries[0].Properties[propertyIndex].NewValue);
                        Assert.AreEqual(rightID_1.ToString(), entries[1].Properties[propertyIndex].NewValue);
                    }
                }
            }
        }
コード例 #9
0
        public void Entity_Proxy()
        {
            var identitySeed = TestContext.GetIdentitySeed(x => x.Entity_Proxies);

            TestContext.DeleteAll(x => x.AuditEntryProperties);
            TestContext.DeleteAll(x => x.AuditEntries);
            TestContext.DeleteAll(x => x.Entity_Proxies);

            TestContext.Insert(x => x.Entity_Proxies, 3);

            var audit = AuditHelper.AutoSaveAudit();

            using (var ctx = new TestContext())
            {
                var list = ctx.Entity_Proxies.ToList();

                foreach (var item in list)
                {
                    // ENSURE it's proxy
                    Assert.AreNotEqual(item.GetType(), ObjectContext.GetObjectType(item.GetType()));
                }

                list.ForEach(x => x.ColumnInt++);

                ctx.SaveChanges(audit);
            }

            // UnitTest - Audit
            {
                var entries = audit.Entries;

                // Entries
                {
                    // Entries Count
                    Assert.AreEqual(3, entries.Count);

                    // Entries State
                    Assert.AreEqual(AuditEntryState.EntityModified, entries[0].State);
                    Assert.AreEqual(AuditEntryState.EntityModified, entries[1].State);
                    Assert.AreEqual(AuditEntryState.EntityModified, entries[2].State);

                    // Entries EntitySetName
                    Assert.AreEqual(TestContext.TypeName(x => x.Entity_Proxies), entries[0].EntitySetName);
                    Assert.AreEqual(TestContext.TypeName(x => x.Entity_Proxies), entries[1].EntitySetName);
                    Assert.AreEqual(TestContext.TypeName(x => x.Entity_Proxies), entries[2].EntitySetName);

                    // Entries TypeName
                    Assert.AreEqual(typeof(Entity_Proxy).Name, entries[0].EntityTypeName);
                    Assert.AreEqual(typeof(Entity_Proxy).Name, entries[1].EntityTypeName);
                    Assert.AreEqual(typeof(Entity_Proxy).Name, entries[2].EntityTypeName);
                }

                // Properties
                {
                    var propertyIndex = -1;

                    // Properties Count
                    Assert.AreEqual(2, entries[0].Properties.Count);
                    Assert.AreEqual(2, entries[1].Properties.Count);
                    Assert.AreEqual(2, entries[2].Properties.Count);

                    // ID
                    propertyIndex = 0;
                    Assert.AreEqual("ID", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ID", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ID", entries[2].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(identitySeed + 1, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(identitySeed + 2, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(identitySeed + 3, entries[2].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(identitySeed + 1, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(identitySeed + 2, entries[1].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(identitySeed + 3, entries[2].Properties[propertyIndex].NewValue);

                    propertyIndex = 1;
                    Assert.AreEqual("ColumnInt", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ColumnInt", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ColumnInt", entries[2].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(0, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(1, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(2, entries[2].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(1, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(2, entries[1].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(3, entries[2].Properties[propertyIndex].NewValue);
                }
            }

            // UnitTest - Audit (Database)
            {
                using (var ctx = new TestContext())
                {
                    // ENSURE order
                    var entries = ctx.AuditEntries.OrderBy(x => x.AuditEntryID).Include(x => x.Properties).ToList();
                    entries.ForEach(x => x.Properties = x.Properties.OrderBy(y => y.AuditEntryPropertyID).ToList());

                    // Entries
                    {
                        // Entries Count
                        Assert.AreEqual(3, entries.Count);

                        // Entries State
                        Assert.AreEqual(AuditEntryState.EntityModified, entries[0].State);
                        Assert.AreEqual(AuditEntryState.EntityModified, entries[1].State);
                        Assert.AreEqual(AuditEntryState.EntityModified, entries[2].State);

                        // Entries EntitySetName
                        Assert.AreEqual(TestContext.TypeName(x => x.Entity_Proxies), entries[0].EntitySetName);
                        Assert.AreEqual(TestContext.TypeName(x => x.Entity_Proxies), entries[1].EntitySetName);
                        Assert.AreEqual(TestContext.TypeName(x => x.Entity_Proxies), entries[2].EntitySetName);

                        // Entries TypeName
                        Assert.AreEqual(typeof(Entity_Proxy).Name, entries[0].EntityTypeName);
                        Assert.AreEqual(typeof(Entity_Proxy).Name, entries[1].EntityTypeName);
                        Assert.AreEqual(typeof(Entity_Proxy).Name, entries[2].EntityTypeName);
                    }

                    // Properties
                    {
                        var propertyIndex = -1;

                        // Properties Count
                        Assert.AreEqual(2, entries[0].Properties.Count);
                        Assert.AreEqual(2, entries[1].Properties.Count);
                        Assert.AreEqual(2, entries[2].Properties.Count);

                        // ID
                        propertyIndex = 0;
                        Assert.AreEqual("ID", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ID", entries[1].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ID", entries[2].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual((identitySeed + 1).ToString(), entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual((identitySeed + 2).ToString(), entries[1].Properties[propertyIndex].OldValue);
                        Assert.AreEqual((identitySeed + 3).ToString(), entries[2].Properties[propertyIndex].OldValue);
                        Assert.AreEqual((identitySeed + 1).ToString(), entries[0].Properties[propertyIndex].NewValue);
                        Assert.AreEqual((identitySeed + 2).ToString(), entries[1].Properties[propertyIndex].NewValue);
                        Assert.AreEqual((identitySeed + 3).ToString(), entries[2].Properties[propertyIndex].NewValue);

                        // ColumnInt
                        propertyIndex = 1;
                        Assert.AreEqual("ColumnInt", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ColumnInt", entries[1].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ColumnInt", entries[2].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("0", entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("1", entries[1].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("2", entries[2].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("1", entries[0].Properties[propertyIndex].NewValue);
                        Assert.AreEqual("2", entries[1].Properties[propertyIndex].NewValue);
                        Assert.AreEqual("3", entries[2].Properties[propertyIndex].NewValue);
                    }
                }
            }
        }
コード例 #10
0
ファイル: Many.cs プロジェクト: xthrush/EntityFramework-Plus
        public void Many()
        {
            var identitySeed = TestContext.GetIdentitySeed(x => x.Entity_Basic_Manies);

            TestContext.DeleteAll(x => x.AuditEntryProperties);
            TestContext.DeleteAll(x => x.AuditEntries);
            TestContext.DeleteAll(x => x.Entity_Basic_Manies);

            var audit = AuditHelper.AutoSaveAudit();

            audit.Configuration.Format <Entity_Basic_Many>(x => new { x.Column1, x.Column2, x.Column3 }, o => 1000 + (int)o);
            using (var ctx = new TestContext())
            {
                TestContext.Insert(ctx, x => x.Entity_Basic_Manies, 3);
                ctx.SaveChanges(audit);
            }

            // UnitTest - Audit
            {
                var entries = audit.Entries;

                // Entries
                {
                    // Entries Count
                    Assert.AreEqual(3, entries.Count);

                    // Entries State
                    Assert.AreEqual(AuditEntryState.EntityAdded, entries[0].State);
                    Assert.AreEqual(AuditEntryState.EntityAdded, entries[1].State);
                    Assert.AreEqual(AuditEntryState.EntityAdded, entries[2].State);

                    // Entries EntitySetName
                    Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basic_Manies), entries[0].EntitySetName);
                    Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basic_Manies), entries[1].EntitySetName);
                    Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basic_Manies), entries[2].EntitySetName);

                    // Entries TypeName
                    Assert.AreEqual(typeof(Entity_Basic_Many).Name, entries[0].EntityTypeName);
                    Assert.AreEqual(typeof(Entity_Basic_Many).Name, entries[1].EntityTypeName);
                    Assert.AreEqual(typeof(Entity_Basic_Many).Name, entries[2].EntityTypeName);
                }

                // Properties
                {
                    var propertyIndex = -1;

                    // Properties Count
                    Assert.AreEqual(4, entries[0].Properties.Count);
                    Assert.AreEqual(4, entries[1].Properties.Count);
                    Assert.AreEqual(4, entries[2].Properties.Count);

                    // ID
                    propertyIndex = 0;
                    Assert.AreEqual("ID", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ID", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ID", entries[2].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(null, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[2].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(identitySeed + 1, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(identitySeed + 2, entries[1].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(identitySeed + 3, entries[2].Properties[propertyIndex].NewValue);

                    // Column1
                    propertyIndex = 1;
                    Assert.AreEqual("Column1", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("Column1", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("Column1", entries[2].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(null, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[2].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(0, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(1, entries[1].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(2, entries[2].Properties[propertyIndex].NewValue);

                    // Column2
                    propertyIndex = 2;
                    Assert.AreEqual("Column2", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("Column2", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("Column2", entries[2].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(null, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[2].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(0, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(1, entries[1].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(2, entries[2].Properties[propertyIndex].NewValue);

                    // Column3
                    propertyIndex = 3;
                    Assert.AreEqual("Column3", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("Column3", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("Column3", entries[2].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(null, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[2].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(0, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(1, entries[1].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(2, entries[2].Properties[propertyIndex].NewValue);
                }
            }

            // UnitTest - Audit (Database)
            {
                using (var ctx = new TestContext())
                {
                    // ENSURE order
                    var entries = ctx.AuditEntries.OrderBy(x => x.AuditEntryID).Include(x => x.Properties).ToList();
                    entries.ForEach(x => x.Properties = x.Properties.OrderBy(y => y.AuditEntryPropertyID).ToList());

                    // Entries
                    {
                        // Entries Count
                        Assert.AreEqual(3, entries.Count);

                        // Entries State
                        Assert.AreEqual(AuditEntryState.EntityAdded, entries[0].State);
                        Assert.AreEqual(AuditEntryState.EntityAdded, entries[1].State);
                        Assert.AreEqual(AuditEntryState.EntityAdded, entries[2].State);

                        // Entries EntitySetName
                        Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basic_Manies), entries[0].EntitySetName);
                        Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basic_Manies), entries[1].EntitySetName);
                        Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basic_Manies), entries[2].EntitySetName);

                        // Entries TypeName
                        Assert.AreEqual(typeof(Entity_Basic_Many).Name, entries[0].EntityTypeName);
                        Assert.AreEqual(typeof(Entity_Basic_Many).Name, entries[1].EntityTypeName);
                        Assert.AreEqual(typeof(Entity_Basic_Many).Name, entries[2].EntityTypeName);
                    }

                    // Properties
                    {
                        var propertyIndex = -1;

                        // Properties Count
                        Assert.AreEqual(4, entries[0].Properties.Count);
                        Assert.AreEqual(4, entries[1].Properties.Count);
                        Assert.AreEqual(4, entries[2].Properties.Count);

                        // ID
                        propertyIndex = 0;
                        Assert.AreEqual("ID", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ID", entries[1].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ID", entries[2].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual(null, entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(null, entries[1].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(null, entries[2].Properties[propertyIndex].OldValue);
                        Assert.AreEqual((identitySeed + 1).ToString(), entries[0].Properties[propertyIndex].NewValue);
                        Assert.AreEqual((identitySeed + 2).ToString(), entries[1].Properties[propertyIndex].NewValue);
                        Assert.AreEqual((identitySeed + 3).ToString(), entries[2].Properties[propertyIndex].NewValue);

                        // Column1
                        propertyIndex = 1;
                        Assert.AreEqual("Column1", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("Column1", entries[1].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("Column1", entries[2].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual(null, entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(null, entries[1].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(null, entries[2].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("1000", entries[0].Properties[propertyIndex].NewValue);
                        Assert.AreEqual("1001", entries[1].Properties[propertyIndex].NewValue);
                        Assert.AreEqual("1002", entries[2].Properties[propertyIndex].NewValue);

                        // Column2
                        propertyIndex = 2;
                        Assert.AreEqual("Column2", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("Column2", entries[1].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("Column2", entries[2].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual(null, entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(null, entries[1].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(null, entries[2].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("1000", entries[0].Properties[propertyIndex].NewValue);
                        Assert.AreEqual("1001", entries[1].Properties[propertyIndex].NewValue);
                        Assert.AreEqual("1002", entries[2].Properties[propertyIndex].NewValue);

                        // Column3
                        propertyIndex = 3;
                        Assert.AreEqual("Column3", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("Column3", entries[1].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("Column3", entries[2].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual(null, entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(null, entries[1].Properties[propertyIndex].OldValue);
                        Assert.AreEqual(null, entries[2].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("1000", entries[0].Properties[propertyIndex].NewValue);
                        Assert.AreEqual("1001", entries[1].Properties[propertyIndex].NewValue);
                        Assert.AreEqual("1002", entries[2].Properties[propertyIndex].NewValue);
                    }
                }
            }
        }
コード例 #11
0
        public void Entity_Complex()
        {
            var identitySeed = TestContext.GetIdentitySeed(x => x.Entity_Complexes);

            TestContext.DeleteAll(x => x.AuditEntryProperties);
            TestContext.DeleteAll(x => x.AuditEntries);
            TestContext.DeleteAll(x => x.Entity_Complexes);

            TestContext.Insert(x => x.Entity_Complexes, 3);

            var audit = AuditHelper.AutoSaveAudit();

            using (var ctx = new TestContext())
            {
                ctx.Entity_Complexes.ToList().ForEach(x =>
                {
                    x.ColumnInt++;
                    x.Info.ColumnInt++;
                    x.Info.Info.ColumnInt++;
                });

                ctx.SaveChanges(audit);
            }

            // UnitTest - Audit
            {
                var entries = audit.Entries;

                // Entries
                {
                    // Entries Count
                    Assert.AreEqual(3, entries.Count);

                    // Entries State
                    Assert.AreEqual(AuditEntryState.EntityModified, entries[0].State);
                    Assert.AreEqual(AuditEntryState.EntityModified, entries[1].State);
                    Assert.AreEqual(AuditEntryState.EntityModified, entries[2].State);

                    // Entries EntitySetName
                    Assert.AreEqual(TestContext.TypeName(x => x.Entity_Complexes), entries[0].EntitySetName);
                    Assert.AreEqual(TestContext.TypeName(x => x.Entity_Complexes), entries[1].EntitySetName);
                    Assert.AreEqual(TestContext.TypeName(x => x.Entity_Complexes), entries[2].EntitySetName);

                    // Entries TypeName
                    Assert.AreEqual(typeof(Entity_Complex).Name, entries[0].EntityTypeName);
                    Assert.AreEqual(typeof(Entity_Complex).Name, entries[1].EntityTypeName);
                    Assert.AreEqual(typeof(Entity_Complex).Name, entries[2].EntityTypeName);
                }

                // Properties
                {
                    var propertyIndex = -1;

                    // Properties Count
                    Assert.AreEqual(4, entries[0].Properties.Count);
                    Assert.AreEqual(4, entries[1].Properties.Count);
                    Assert.AreEqual(4, entries[2].Properties.Count);

                    // ID
                    propertyIndex = 0;
                    Assert.AreEqual("ID", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ID", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ID", entries[2].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(identitySeed + 1, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(identitySeed + 2, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(identitySeed + 3, entries[2].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(identitySeed + 1, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(identitySeed + 2, entries[1].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(identitySeed + 3, entries[2].Properties[propertyIndex].NewValue);

                    // ColumnInt
                    propertyIndex = 1;
                    Assert.AreEqual("ColumnInt", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ColumnInt", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ColumnInt", entries[2].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(0, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(1, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(2, entries[2].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(1, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(2, entries[1].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(3, entries[2].Properties[propertyIndex].NewValue);

                    // Info.ColumnInt
                    propertyIndex = 2;
                    Assert.AreEqual("Info.ColumnInt", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("Info.ColumnInt", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("Info.ColumnInt", entries[2].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(1000, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(1001, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(1002, entries[2].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(1001, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(1002, entries[1].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(1003, entries[2].Properties[propertyIndex].NewValue);

                    // Info.Info.ColumnInt
                    propertyIndex = 3;
                    Assert.AreEqual("Info.Info.ColumnInt", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("Info.Info.ColumnInt", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("Info.Info.ColumnInt", entries[2].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(1000000, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(1000001, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(1000002, entries[2].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(1000001, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(1000002, entries[1].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(1000003, entries[2].Properties[propertyIndex].NewValue);
                }
            }

            // UnitTest - Audit (Database)
            {
                using (var ctx = new TestContext())
                {
                    // ENSURE order
                    var entries = ctx.AuditEntries.OrderBy(x => x.AuditEntryID).Include(x => x.Properties).ToList();
                    entries.ForEach(x => x.Properties = x.Properties.OrderBy(y => y.AuditEntryPropertyID).ToList());

                    // Entries
                    {
                        // Entries Count
                        Assert.AreEqual(3, entries.Count);

                        // Entries State
                        Assert.AreEqual(AuditEntryState.EntityModified, entries[0].State);
                        Assert.AreEqual(AuditEntryState.EntityModified, entries[1].State);
                        Assert.AreEqual(AuditEntryState.EntityModified, entries[2].State);

                        // Entries EntitySetName
                        Assert.AreEqual(TestContext.TypeName(x => x.Entity_Complexes), entries[0].EntitySetName);
                        Assert.AreEqual(TestContext.TypeName(x => x.Entity_Complexes), entries[1].EntitySetName);
                        Assert.AreEqual(TestContext.TypeName(x => x.Entity_Complexes), entries[2].EntitySetName);

                        // Entries TypeName
                        Assert.AreEqual(typeof(Entity_Complex).Name, entries[0].EntityTypeName);
                        Assert.AreEqual(typeof(Entity_Complex).Name, entries[1].EntityTypeName);
                        Assert.AreEqual(typeof(Entity_Complex).Name, entries[2].EntityTypeName);
                    }

                    // Properties
                    {
                        var propertyIndex = -1;

                        // Properties Count
                        Assert.AreEqual(4, entries[0].Properties.Count);
                        Assert.AreEqual(4, entries[1].Properties.Count);
                        Assert.AreEqual(4, entries[2].Properties.Count);

                        // ID
                        propertyIndex = 0;
                        Assert.AreEqual("ID", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ID", entries[1].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ID", entries[2].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual((identitySeed + 1).ToString(), entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual((identitySeed + 2).ToString(), entries[1].Properties[propertyIndex].OldValue);
                        Assert.AreEqual((identitySeed + 3).ToString(), entries[2].Properties[propertyIndex].OldValue);
                        Assert.AreEqual((identitySeed + 1).ToString(), entries[0].Properties[propertyIndex].NewValue);
                        Assert.AreEqual((identitySeed + 2).ToString(), entries[1].Properties[propertyIndex].NewValue);
                        Assert.AreEqual((identitySeed + 3).ToString(), entries[2].Properties[propertyIndex].NewValue);

                        // ColumnInt
                        propertyIndex = 1;
                        Assert.AreEqual("ColumnInt", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ColumnInt", entries[1].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("ColumnInt", entries[2].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("0", entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("1", entries[1].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("2", entries[2].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("1", entries[0].Properties[propertyIndex].NewValue);
                        Assert.AreEqual("2", entries[1].Properties[propertyIndex].NewValue);
                        Assert.AreEqual("3", entries[2].Properties[propertyIndex].NewValue);

                        // Info.ColumnInt
                        propertyIndex = 2;
                        Assert.AreEqual("Info.ColumnInt", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("Info.ColumnInt", entries[1].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("Info.ColumnInt", entries[2].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("1000", entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("1001", entries[1].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("1002", entries[2].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("1001", entries[0].Properties[propertyIndex].NewValue);
                        Assert.AreEqual("1002", entries[1].Properties[propertyIndex].NewValue);
                        Assert.AreEqual("1003", entries[2].Properties[propertyIndex].NewValue);

                        // Info.Info.ColumnInt
                        propertyIndex = 3;
                        Assert.AreEqual("Info.Info.ColumnInt", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("Info.Info.ColumnInt", entries[1].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("Info.Info.ColumnInt", entries[2].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("1000000", entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("1000001", entries[1].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("1000002", entries[2].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("1000001", entries[0].Properties[propertyIndex].NewValue);
                        Assert.AreEqual("1000002", entries[1].Properties[propertyIndex].NewValue);
                        Assert.AreEqual("1000003", entries[2].Properties[propertyIndex].NewValue);
                    }
                }
            }
        }
コード例 #12
0
        public void IgnorePropertyUnchanged_IsTrue()
        {
            var identitySeed = TestContext.GetIdentitySeed(x => x.Entity_Complexes);

            TestContext.DeleteAll(x => x.AuditEntryProperties);
            TestContext.DeleteAll(x => x.AuditEntries);
            TestContext.DeleteAll(x => x.Entity_Complexes);

            TestContext.Insert(x => x.Entity_Complexes, 1);

            var audit = AuditHelper.AutoSaveAudit();

            Assert.AreEqual(true, audit.Configuration.IgnorePropertyUnchanged);

            using (var ctx = new TestContext())
            {
                ctx.Entity_Complexes.ToList().ForEach(x => x.Info.Info.ColumnInt++);
                ctx.SaveChanges(audit);
            }

            // UnitTest - Audit
            {
                var entries = audit.Entries;

                // Entries
                {
                    // Entries Count
                    Assert.AreEqual(1, entries.Count);

                    // Entries State
                    Assert.AreEqual(AuditEntryState.EntityModified, entries[0].State);
                }

                // Properties
                {
                    var propertyIndex = -1;

                    // Properties Count
                    Assert.AreEqual(2, entries[0].Properties.Count);

                    // ID
                    propertyIndex = 0;
                    Assert.AreEqual("ID", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(identitySeed + 1, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(identitySeed + 1, entries[0].Properties[propertyIndex].NewValue);

                    // Info.Info.ColumnInt
                    propertyIndex = 1;
                    Assert.AreEqual("Info.Info.ColumnInt", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(1000000, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(1000001, entries[0].Properties[propertyIndex].NewValue);
                }
            }

            // UnitTest - Audit (Database)
            {
                using (var ctx = new TestContext())
                {
                    // ENSURE order
                    var entries = ctx.AuditEntries.OrderBy(x => x.AuditEntryID).Include(x => x.Properties).ToList();
                    entries.ForEach(x => x.Properties = x.Properties.OrderBy(y => y.AuditEntryPropertyID).ToList());

                    // Entries
                    {
                        var propertyIndex = -1;

                        // Properties Count
                        Assert.AreEqual(2, entries[0].Properties.Count);

                        // ID
                        propertyIndex = 0;
                        Assert.AreEqual("ID", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual((identitySeed + 1).ToString(), entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual((identitySeed + 1).ToString(), entries[0].Properties[propertyIndex].NewValue);

                        // Info.Info.ColumnInt
                        propertyIndex = 1;
                        Assert.AreEqual("Info.Info.ColumnInt", entries[0].Properties[propertyIndex].PropertyName);
                        Assert.AreEqual("1000000", entries[0].Properties[propertyIndex].OldValue);
                        Assert.AreEqual("1000001", entries[0].Properties[propertyIndex].NewValue);
                    }
                }
            }
        }
コード例 #13
0
        public async Task IsNull_Async()
        {
            var identitySeed = TestContext.GetIdentitySeed(x => x.Entity_Basics);

            TestContext.DeleteAll(x => x.AuditEntryProperties);
            TestContext.DeleteAll(x => x.AuditEntries);
            TestContext.DeleteAll(x => x.Entity_Basics);

            var audit = AuditHelper.AutoSaveAudit();

            audit.Configuration.AutoSavePreAction = null;

            using (var ctx = new TestContext())
            {
                TestContext.Insert(ctx, x => x.Entity_Basics, 3);
                await ctx.SaveChangesAsync(audit);
            }

            // UnitTest - Audit
            {
                var entries = audit.Entries;

                // Entries
                {
                    // Entries Count
                    Assert.AreEqual(3, entries.Count);

                    // Entries State
                    Assert.AreEqual(AuditEntryState.EntityAdded, entries[0].State);
                    Assert.AreEqual(AuditEntryState.EntityAdded, entries[1].State);
                    Assert.AreEqual(AuditEntryState.EntityAdded, entries[2].State);

                    // Entries EntitySetName
                    Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basics), entries[0].EntitySetName);
                    Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basics), entries[1].EntitySetName);
                    Assert.AreEqual(TestContext.TypeName(x => x.Entity_Basics), entries[2].EntitySetName);

                    // Entries TypeName
                    Assert.AreEqual(typeof(Entity_Basic).Name, entries[0].EntityTypeName);
                    Assert.AreEqual(typeof(Entity_Basic).Name, entries[1].EntityTypeName);
                    Assert.AreEqual(typeof(Entity_Basic).Name, entries[2].EntityTypeName);
                }

                // Properties
                {
                    var propertyIndex = -1;

                    // Properties Count
                    Assert.AreEqual(2, entries[0].Properties.Count);
                    Assert.AreEqual(2, entries[1].Properties.Count);
                    Assert.AreEqual(2, entries[2].Properties.Count);

                    // ID
                    propertyIndex = 0;
                    Assert.AreEqual("ID", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ID", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ID", entries[2].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(null, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[2].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(identitySeed + 1, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(identitySeed + 2, entries[1].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(identitySeed + 3, entries[2].Properties[propertyIndex].NewValue);

                    // ColumnInt
                    propertyIndex = 1;
                    Assert.AreEqual("ColumnInt", entries[0].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ColumnInt", entries[1].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual("ColumnInt", entries[2].Properties[propertyIndex].PropertyName);
                    Assert.AreEqual(null, entries[0].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[1].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(null, entries[2].Properties[propertyIndex].OldValue);
                    Assert.AreEqual(0, entries[0].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(1, entries[1].Properties[propertyIndex].NewValue);
                    Assert.AreEqual(2, entries[2].Properties[propertyIndex].NewValue);
                }
            }

            // UnitTest - Audit (Database)
            {
                using (var ctx = new TestContext())
                {
                    // ENSURE order
                    var entries = ctx.AuditEntries.OrderBy(x => x.AuditEntryID).Include(x => x.Properties).ToList();
                    entries.ForEach(x => x.Properties = x.Properties.OrderBy(y => y.AuditEntryPropertyID).ToList());

                    // Entries
                    {
                        // Entries Count
                        Assert.AreEqual(0, entries.Count);
                    }
                }
            }
        }