当前位置: 首页>>代码示例>>C#>>正文


C# TestContext.SaveChanges方法代码示例

本文整理汇总了C#中TestContext.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# TestContext.SaveChanges方法的具体用法?C# TestContext.SaveChanges怎么用?C# TestContext.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TestContext的用法示例。


在下文中一共展示了TestContext.SaveChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Single_EnumeratorAsync

        public async Task Single_EnumeratorAsync()
        {
            TestContext.DeleteAll(x => x.Association_OneToMany_Lefts);
            TestContext.DeleteAll(x => x.Association_OneToMany_Rights);

            using (var ctx = new TestContext())
            {
                var left = TestContext.Insert(ctx, x => x.Association_OneToMany_Lefts, 1).First();
                left.Rights = TestContext.Insert(ctx, x => x.Association_OneToMany_Rights, 5);
                ctx.SaveChanges();
            }

            using (var ctx = new TestContext())
            {
                var list = await ctx.Association_OneToMany_Lefts
                    .IncludeOptimized(left => left.Rights.Where(y => y.ColumnInt > 2))
                    .ToListAsync();

                // TEST: context
                Assert.AreEqual(3, ctx.ChangeTracker.Entries().Count());

                // TEST: left
                Assert.AreEqual(1, list.Count);

                // TEST: right
                var item = list[0];
                Assert.AreEqual(2, item.Rights.Count);
                var first = item.Rights[0].ColumnInt == 3 ? item.Rights[0] : item.Rights[1];
                var second = item.Rights[0].ColumnInt == 3 ? item.Rights[1] : item.Rights[0];
                Assert.AreEqual(3, first.ColumnInt);
                Assert.AreEqual(4, second.ColumnInt);
            }
        }
开发者ID:emmatb1,项目名称:EntityFramework-Plus,代码行数:33,代码来源:Single_EnumeratorAsync.cs

示例2: IncludeEntityAdded_IsFalse

        public void IncludeEntityAdded_IsFalse()
        {
            TestContext.DeleteAll(x => x.AuditEntries);
            TestContext.DeleteAll(x => x.Entity_Basics);

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

            var audit = AuditHelper.AutoSaveAudit();
            audit.Configuration.IncludeEntityAdded = false;

            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(2, entries.Count);

                    // Entries State
                    Assert.AreEqual(AuditEntryState.EntityModified, entries[0].State);
                    Assert.AreEqual(AuditEntryState.EntityDeleted, entries[1].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(2, entries.Count);

                        // Entries State
                        Assert.AreEqual(AuditEntryState.EntityModified, entries[0].State);
                        Assert.AreEqual(AuditEntryState.EntityDeleted, entries[1].State);
                    }
                }
            }
        }
开发者ID:DebugOfTheRoad,项目名称:EntityFramework-Plus,代码行数:60,代码来源:IncludeEntityAdded_IsFalse.cs

示例3: DeleteRecord

 static void DeleteRecord(Client client)
 {
     TestContext context = new TestContext();
     context.Clients.Attach(client);
     context.Clients.DeleteObject(client);
     context.SaveChanges();
 }
开发者ID:ErickMC,项目名称:Llama,代码行数:7,代码来源:Program.cs

示例4: Single_ThenQuery_Enumerator

        public void Single_ThenQuery_Enumerator()
        {
            TestContext.DeleteAll(x => x.Association_OneToMany_Lefts);
            TestContext.DeleteAll(x => x.Association_OneToMany_Rights);

            using (var ctx = new TestContext())
            {
                {
                    var left = TestContext.Insert(ctx, x => x.Association_OneToMany_Lefts, 1).First();
                    left.Rights = TestContext.Insert(ctx, x => x.Association_OneToMany_Rights, 5);
                }
                {
                    var left = TestContext.Insert(ctx, x => x.Association_OneToMany_Lefts, 1).First();
                    left.ColumnInt = 5;
                    left.Rights = TestContext.Insert(ctx, x => x.Association_OneToMany_Rights, 5);
                }
                ctx.SaveChanges();
            }


            using (var ctx = new TestContext())
            {
                var list = ctx.Association_OneToMany_Lefts.Include(left => left.Rights, true).Where(x => x.ColumnInt < 5).OrderBy(x => x.ID).ToList();

                // TEST: context
                Assert.AreEqual(6, ctx.ChangeTracker.Entries().Count());
            }
        }
开发者ID:DebugOfTheRoad,项目名称:EntityFramework-Plus,代码行数:28,代码来源:Single_ThenQuery_Enumerator.cs

示例5: Single_Executor

        public void Single_Executor()
        {
            TestContext.DeleteAll(x => x.Association_OneToMany_Lefts);
            TestContext.DeleteAll(x => x.Association_OneToMany_Rights);

            using (var ctx = new TestContext())
            {
                var left = TestContext.Insert(ctx, x => x.Association_OneToMany_Lefts, 1).First();
                left.Rights = TestContext.Insert(ctx, x => x.Association_OneToMany_Rights, 5);
                ctx.SaveChanges();
            }


            using (var ctx = new TestContext())
            {
                var item = ctx.Association_OneToMany_Lefts.IncludeQuery(left => left.Rights.Where(x => x.ColumnInt > 2)).First();

                // TEST: context
                Assert.AreEqual(3, ctx.ChangeTracker.Entries().Count());

                // TEST: right
                Assert.AreEqual(2, item.Rights.Count);

                if (item.Rights[0].ColumnInt == 3)
                {
                    Assert.AreEqual(3, item.Rights[0].ColumnInt);
                    Assert.AreEqual(4, item.Rights[1].ColumnInt);
                }
                else
                {
                    Assert.AreEqual(4, item.Rights[0].ColumnInt);
                    Assert.AreEqual(3, item.Rights[1].ColumnInt);
                }
            }
        }
开发者ID:DebugOfTheRoad,项目名称:EntityFramework-Plus,代码行数:35,代码来源:Single_Executor.cs

示例6: Single_Enumerator

        public void Single_Enumerator()
        {
            TestContext.DeleteAll(x => x.Association_OneToMany_Lefts);
            TestContext.DeleteAll(x => x.Association_OneToMany_Rights);

            using (var ctx = new TestContext())
            {
                var left = TestContext.Insert(ctx, x => x.Association_OneToMany_Lefts, 1).First();
                left.Rights = TestContext.Insert(ctx, x => x.Association_OneToMany_Rights, 5);
                ctx.SaveChanges();
            }

            using (var ctx = new TestContext())
            {
                var list = ctx.Association_OneToMany_Lefts
                    .IncludeFilter(left => left.Rights.Where(y => y.ColumnInt > 2))
                    .ToList();

                // TEST: context
                Assert.AreEqual(3, ctx.ChangeTracker.Entries().Count());

                // TEST: left
                Assert.AreEqual(1, list.Count);

                // TEST: right
                var item = list[0];
                Assert.AreEqual(2, item.Rights.Count);
                Assert.AreEqual(3, item.Rights[0].ColumnInt);
                Assert.AreEqual(4, item.Rights[1].ColumnInt);
            }
        }
开发者ID:emmatb1,项目名称:EntityFramework-Plus,代码行数:31,代码来源:Single_Enumerator.cs

示例7: Many_Executor

        public void Many_Executor()
        {
            TestContext.DeleteAll(x => x.Association_Multi_OneToMany_Lefts);
            TestContext.DeleteAll(x => x.Association_Multi_OneToMany_Right1s);
            TestContext.DeleteAll(x => x.Association_Multi_OneToMany_Right2s);

            using (var ctx = new TestContext())
            {
                var left = TestContext.Insert(ctx, x => x.Association_Multi_OneToMany_Lefts, 1).First();
                left.Right1s = TestContext.Insert(ctx, x => x.Association_Multi_OneToMany_Right1s, 5);
                left.Right2s = TestContext.Insert(ctx, x => x.Association_Multi_OneToMany_Right2s, 5);
                ctx.SaveChanges();
            }


            using (var ctx = new TestContext())
            {
                var item = ctx.Association_Multi_OneToMany_Lefts
                    .Include(left => left.Right1s, true)
                    .Include(left => left.Right2s, true)
                    .First();

                // TEST: context
                Assert.AreEqual(11, ctx.ChangeTracker.Entries().Count());
            }
        }
开发者ID:DebugOfTheRoad,项目名称:EntityFramework-Plus,代码行数:26,代码来源:Many_Executor.cs

示例8: Many_ExecutorAsync

        public async Task Many_ExecutorAsync()
        {
            TestContext.DeleteAll(x => x.Association_Multi_OneToMany_Right1s);
            TestContext.DeleteAll(x => x.Association_Multi_OneToMany_Right2s);
            TestContext.DeleteAll(x => x.Association_Multi_OneToMany_Lefts);

            using (var ctx = new TestContext())
            {
                var left = TestContext.Insert(ctx, x => x.Association_Multi_OneToMany_Lefts, 1).First();
                left.Right1s = TestContext.Insert(ctx, x => x.Association_Multi_OneToMany_Right1s, 5);
                left.Right2s = TestContext.Insert(ctx, x => x.Association_Multi_OneToMany_Right2s, 5);
                ctx.SaveChanges();
            }

            using (var ctx = new TestContext())
            {
                var item = await ctx.Association_Multi_OneToMany_Lefts
                    .IncludeOptimized(left => left.Right1s.Where(y => y.ColumnInt > 2))
                    .IncludeOptimized(left => left.Right2s.Where(y => y.ColumnInt > 2))
                    .FirstAsync(x => x.ColumnInt < 10);

                // TEST: context
                Assert.AreEqual(5, ctx.ChangeTracker.Entries().Count());

                // TEST: right1
                Assert.AreEqual(2, item.Right1s.Count);

                if (item.Right1s[0].ColumnInt == 3)
                {
                    Assert.AreEqual(3, item.Right1s[0].ColumnInt);
                    Assert.AreEqual(4, item.Right1s[1].ColumnInt);
                }
                else
                {
                    Assert.AreEqual(4, item.Right1s[0].ColumnInt);
                    Assert.AreEqual(3, item.Right1s[1].ColumnInt);
                }

                // TEST: right2
                Assert.AreEqual(2, item.Right2s.Count);

                if (item.Right2s[0].ColumnInt == 3)
                {
                    Assert.AreEqual(3, item.Right2s[0].ColumnInt);
                    Assert.AreEqual(4, item.Right2s[1].ColumnInt);
                }
                else
                {
                    Assert.AreEqual(4, item.Right2s[0].ColumnInt);
                    Assert.AreEqual(3, item.Right2s[1].ColumnInt);
                }
            }
        }
开发者ID:emmatb1,项目名称:EntityFramework-Plus,代码行数:53,代码来源:Many_ExecutorAsync.cs

示例9: Single_ThenQuery_ExecutorAsync

        public async Task Single_ThenQuery_ExecutorAsync()
        {
            TestContext.DeleteAll(x => x.Association_OneToMany_Lefts);
            TestContext.DeleteAll(x => x.Association_OneToMany_Rights);

            using (var ctx = new TestContext())
            {
                {
                    var left = TestContext.Insert(ctx, x => x.Association_OneToMany_Lefts, 1).First();
                    left.Rights = TestContext.Insert(ctx, x => x.Association_OneToMany_Rights, 5);
                }
                {
                    var left = TestContext.Insert(ctx, x => x.Association_OneToMany_Lefts, 1).First();
                    left.ColumnInt = 5;
                    left.Rights = TestContext.Insert(ctx, x => x.Association_OneToMany_Rights, 5);
                }
                ctx.SaveChanges();
            }

            using (var ctx = new TestContext())
            {
                var item = await ctx.Association_OneToMany_Lefts
                    .IncludeOptimized(left => left.Rights.Where(y => y.ColumnInt > 2))
                    .Where(x => x.ColumnInt < 5)
                    .OrderBy(x => x.ID)
                    .FirstAsync(x => x.ColumnInt < 10);

                // TEST: context
                Assert.AreEqual(3, ctx.ChangeTracker.Entries().Count());

                // TEST: context
                Assert.AreEqual(3, ctx.ChangeTracker.Entries().Count());

                // TEST: right
                Assert.AreEqual(2, item.Rights.Count);

                if (item.Rights[0].ColumnInt == 3)
                {
                    Assert.AreEqual(3, item.Rights[0].ColumnInt);
                    Assert.AreEqual(4, item.Rights[1].ColumnInt);
                }
                else
                {
                    Assert.AreEqual(4, item.Rights[0].ColumnInt);
                    Assert.AreEqual(3, item.Rights[1].ColumnInt);
                }
            }
        }
开发者ID:emmatb1,项目名称:EntityFramework-Plus,代码行数:48,代码来源:Single_ThenQuery_ExecutorAsync.cs

示例10: All

        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.Exclude(x => true);

            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(0, entries.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(0, entries.Count);
                    }
                }
            }
        }
开发者ID:emmatb1,项目名称:EntityFramework-Plus,代码行数:46,代码来源:All.cs

示例11: Register

        public RepositoryResult<User> Register(User user)
        {
            try
            {
                using (var db = new TestContext())
                {
                    db.Users.Add(user);
                    db.SaveChanges();
                }

                return RepositoryResult<User>.SuccessFunc("User " + user.UserName + " registered successfully", user);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return RepositoryResult<User>.ErrorFunc("User " + user.UserName + " can not be resigtered", user);
            }
        }
开发者ID:zkharazishvili,项目名称:OnlineTesting,代码行数:18,代码来源:UserRepository.cs

示例12: Many_EnumeratorAsync

        public async Task Many_EnumeratorAsync()
        {
            TestContext.DeleteAll(x => x.Association_Multi_OneToMany_Right1s);
            TestContext.DeleteAll(x => x.Association_Multi_OneToMany_Right2s);
            TestContext.DeleteAll(x => x.Association_Multi_OneToMany_Lefts);

            using (var ctx = new TestContext())
            {
                var left = TestContext.Insert(ctx, x => x.Association_Multi_OneToMany_Lefts, 1).First();
                left.Right1s = TestContext.Insert(ctx, x => x.Association_Multi_OneToMany_Right1s, 5);
                left.Right2s = TestContext.Insert(ctx, x => x.Association_Multi_OneToMany_Right2s, 5);
                ctx.SaveChanges();
            }

            using (var ctx = new TestContext())
            {
                var list = await ctx.Association_Multi_OneToMany_Lefts
                    .IncludeFilter(left => left.Right1s.Where(y => y.ColumnInt > 2))
                    .IncludeFilter(left => left.Right2s.Where(y => y.ColumnInt > 2))
                    .ToListAsync();

                // TEST: context
                Assert.AreEqual(5, ctx.ChangeTracker.Entries().Count());

                // TEST: left
                Assert.AreEqual(1, list.Count);
                var item = list[0];

                // TEST: right1
                Assert.AreEqual(2, item.Right1s.Count);
                Assert.AreEqual(3, item.Right1s[0].ColumnInt);
                Assert.AreEqual(4, item.Right1s[1].ColumnInt);

                // TEST: right2
                Assert.AreEqual(2, item.Right2s.Count);
                Assert.AreEqual(3, item.Right2s[0].ColumnInt);
                Assert.AreEqual(4, item.Right2s[1].ColumnInt);
            }
        }
开发者ID:emmatb1,项目名称:EntityFramework-Plus,代码行数:39,代码来源:Many_EnumeratorAsync.cs

示例13: TestWithEntityFrameWork

        public void TestWithEntityFrameWork()
        {
            string testString = "av\\fs\\dgdg\t\n\b\f\n\t";

            var context = new TestContext();
            var obj = new Tablea()
                {
                    Field_text = testString,
                };
            context.Tablea.Add(obj);
            context.SaveChanges();
            context.Dispose();

            context = new TestContext();
            var result = context.Tablea.FirstOrDefault(x => x.Field_serial == obj.Field_serial);
            if (result != null)
            {
                Assert.AreEqual(result.Field_text, testString);
            }
            else
            {
                Assert.Fail();
            }
        }
开发者ID:sanvel62,项目名称:Npgsql2,代码行数:24,代码来源:BackslashTests.cs

示例14: Many_ThenQuery_Executor

        public void Many_ThenQuery_Executor()
        {
            TestContext.DeleteAll(x => x.Association_Multi_OneToMany_Right1s);
            TestContext.DeleteAll(x => x.Association_Multi_OneToMany_Right2s);
            TestContext.DeleteAll(x => x.Association_Multi_OneToMany_Lefts);

            using (var ctx = new TestContext())
            {
                {
                    var left = TestContext.Insert(ctx, x => x.Association_Multi_OneToMany_Lefts, 1).First();
                    left.Right1s = TestContext.Insert(ctx, x => x.Association_Multi_OneToMany_Right1s, 5);
                    left.Right2s = TestContext.Insert(ctx, x => x.Association_Multi_OneToMany_Right2s, 5);
                }
                {
                    var left = TestContext.Insert(ctx, x => x.Association_Multi_OneToMany_Lefts, 1).First();
                    left.ColumnInt = 5;
                    left.Right1s = TestContext.Insert(ctx, x => x.Association_Multi_OneToMany_Right1s, 5);
                    left.Right2s = TestContext.Insert(ctx, x => x.Association_Multi_OneToMany_Right2s, 5);
                }

                ctx.SaveChanges();
            }

            using (var ctx = new TestContext())
            {
                var item = ctx.Association_Multi_OneToMany_Lefts
                    .IncludeFilter(left => left.Right1s.Where(y => y.ColumnInt > 2))
                    .IncludeFilter(left => left.Right2s.Where(y => y.ColumnInt > 2))
                    .Where(x => x.ColumnInt < 5)
                    .OrderBy(x => x.ID)
                    .First();

                // TEST: context
                Assert.AreEqual(5, ctx.ChangeTracker.Entries().Count());

                // TEST: right1
                Assert.AreEqual(2, item.Right1s.Count);

                if (item.Right1s[0].ColumnInt == 3)
                {
                    Assert.AreEqual(3, item.Right1s[0].ColumnInt);
                    Assert.AreEqual(4, item.Right1s[1].ColumnInt);
                }
                else
                {
                    Assert.AreEqual(4, item.Right1s[0].ColumnInt);
                    Assert.AreEqual(3, item.Right1s[1].ColumnInt);
                }

                // TEST: right2
                Assert.AreEqual(2, item.Right2s.Count);

                if (item.Right2s[0].ColumnInt == 3)
                {
                    Assert.AreEqual(3, item.Right2s[0].ColumnInt);
                    Assert.AreEqual(4, item.Right2s[1].ColumnInt);
                }
                else
                {
                    Assert.AreEqual(4, item.Right2s[0].ColumnInt);
                    Assert.AreEqual(3, item.Right2s[1].ColumnInt);
                }
            }
        }
开发者ID:emmatb1,项目名称:EntityFramework-Plus,代码行数:64,代码来源:Many_ThenQuery_Executor.cs

示例15: Entity_Basic

        public void Entity_Basic()
        {
            var identitySeed = TestContext.GetIdentitySeed(x => x.Entity_Basics);

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

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

            var audit = AuditHelper.AutoSaveAudit();
            audit.Configuration.SoftDeleted(x => true);

            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.EntitySoftDeleted, entries[0].State);
                    Assert.AreEqual(AuditEntryState.EntitySoftDeleted, entries[1].State);
                    Assert.AreEqual(AuditEntryState.EntitySoftDeleted, 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(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.EntitySoftDeleted, entries[0].State);
                        Assert.AreEqual(AuditEntryState.EntitySoftDeleted, entries[1].State);
                        Assert.AreEqual(AuditEntryState.EntitySoftDeleted, 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);
//.........这里部分代码省略.........
开发者ID:emmatb1,项目名称:EntityFramework-Plus,代码行数:101,代码来源:Entity_Basic.cs


注:本文中的TestContext.SaveChanges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。