• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# TestDbContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中TestDbContext的典型用法代码示例。如果您正苦于以下问题:C# TestDbContext类的具体用法?C# TestDbContext怎么用?C# TestDbContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TestDbContext类属于命名空间,在下文中一共展示了TestDbContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ShouldNotUpdatePropertiesOfAnAssociatedEntity

        public void ShouldNotUpdatePropertiesOfAnAssociatedEntity()
        {
            var node1 = new TestNode
            {
                Title = "New Node",
                OneToOneAssociated = new OneToOneAssociatedModel { Title = "Associated Node" }
            };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.SaveChanges();
            } // Simulate detach

            node1.OneToOneAssociated.Title = "Updated Content";

            using (var context = new TestDbContext())
            {
                context.UpdateGraph(node1);

                context.SaveChanges();
                var node2 = context.Nodes.Include(p => p.OneToOneAssociated).Single(p => p.Id == node1.Id);
                Assert.IsNotNull(node2);
                Assert.IsTrue(node2.OneToOneAssociated.OneParent == node2);
                // should not delete it as it is associated and no cascade rule set.
                Assert.IsTrue(node2.OneToOneAssociated.Title == "Associated Node");
            }
        }
开发者ID:siegeon,项目名称:GraphDiff,代码行数:28,代码来源:AssociatedEntityBehaviours.cs


示例2: ShouldNotUpdateEntitesWithinAnAssociatedCollection

        public void ShouldNotUpdateEntitesWithinAnAssociatedCollection()
        {
            var node1 = new TestNode
            {
                Title = "New Node",
                OneToManyAssociated = new List<OneToManyAssociatedModel>
                {
                    new OneToManyAssociatedModel { Title = "First One" }
                }
            };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.SaveChanges();
            } // Simulate detach

            node1.OneToManyAssociated.First().Title = "This should not overwrite value";

            using (var context = new TestDbContext())
            {
                // Setup mapping
                context.UpdateGraph(node1, map => map
                    .AssociatedCollection(p => p.OneToManyAssociated));

                context.SaveChanges();
                var node2 = context.Nodes.Include(p => p.OneToManyAssociated).Single(p => p.Id == node1.Id);
                Assert.IsNotNull(node2);
                Assert.IsTrue(node2.OneToManyAssociated.Single().Title == "First One");
            }
        }
开发者ID:GertArnold,项目名称:GraphDiff,代码行数:31,代码来源:AssociatedCollectionBehaviours.cs


示例3: Dispose

 public void Dispose()
 {
     using (var dbContext = new TestDbContext())
     {
         dbContext.Database.Delete();
     }
 }
开发者ID:wayne-o,项目名称:delete-me,代码行数:7,代码来源:SqlDataContextFixture.cs


示例4: ShouldAddRelationToExistingAssociatedCollection

        public void ShouldAddRelationToExistingAssociatedCollection()
        {
            var associated = new OneToManyAssociatedModel { Title = "Second One" };
            var node1 = new TestNode
            {
                Title = "New Node",
                OneToManyAssociated = new List<OneToManyAssociatedModel>
                {
                    new OneToManyAssociatedModel { Title = "First One" }
                }
            };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.OneToManyAssociatedModels.Add(associated);
                context.SaveChanges();
            } // Simulate detach

            node1.OneToManyAssociated.Add(associated);

            using (var context = new TestDbContext())
            {
                // Setup mapping
                context.UpdateGraph(node1, map => map
                    .AssociatedCollection(p => p.OneToManyAssociated));

                context.SaveChanges();
                var node2 = context.Nodes.Include(p => p.OneToManyAssociated).Single(p => p.Id == node1.Id);
                Assert.IsNotNull(node2);
                Assert.IsTrue(node2.OneToManyAssociated.Count == 2);
            }
        }
开发者ID:GertArnold,项目名称:GraphDiff,代码行数:33,代码来源:AssociatedCollectionBehaviours.cs


示例5: ShouldSupportGuidKeys

        public void ShouldSupportGuidKeys()
        {
            var model = new GuidTestNode();
            using (var context = new TestDbContext())
            {
                context.GuidKeyModels.Add(model);
                context.SaveChanges();

                // http://stackoverflow.com/questions/5270721/using-guid-as-pk-with-ef4-code-first
                Assert.IsTrue(Attribute.IsDefined(model.GetType().GetProperty("Id"), typeof(DatabaseGeneratedAttribute)));

                Assert.IsNotNull(model.Id);
                Assert.AreNotEqual(Guid.Empty, model.Id);
            } // simulate detach

            model.OneToOneOwned = new GuidOneToOneOwned();

            using (var context = new TestDbContext())
            {
                model = context.UpdateGraph(model, map => map.OwnedEntity(g => g.OneToOneOwned));
                context.SaveChanges();

                Assert.IsNotNull(model.OneToOneOwned);
                Assert.IsNotNull(model.OneToOneOwned.Id);
                Assert.AreNotEqual(Guid.Empty, model.OneToOneOwned.Id);
            }
        }
开发者ID:rho24,项目名称:GraphDiff,代码行数:27,代码来源:GuidKeyBehaviors.cs


示例6: ShouldSupportNullValuesInTree

        public void ShouldSupportNullValuesInTree()
        {
            var node1 = new TestNode
            {
                Title = "New Node",
                OneToOneOwned = null
            };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.SaveChanges();
            } // Simulate detach

            using (var context = new TestDbContext())
            {
                // Setup mapping
                node1 = context.UpdateGraph(node1, map => map
                    .OwnedEntity(p => p.OneToOneOwned, with =>
                        with.OwnedEntity(p => p.OneToOneOneToOneOwned)));

                context.SaveChanges();
                context.Entry(node1).Reload();
                Assert.IsTrue(node1.OneToOneOwned == null);
            }
        }
开发者ID:joswalt,项目名称:Highway.Data,代码行数:26,代码来源:ThirdTierBehaviours.cs


示例7: ShouldThrowDbUpdateConcurrencyExceptionWithEmptyRowVersion

        public void ShouldThrowDbUpdateConcurrencyExceptionWithEmptyRowVersion()
        {
            TestNode node;
            using (var db = new TestDbContext())
            {
                node = new TestNode
                {
                    Title = "Hello",
                    OneToManyOwned = new List<OneToManyOwnedModel>
                    {
                        new OneToManyOwnedModel { Title = "Test1" },
                        new OneToManyOwnedModel { Title = "Test2" }
                    }
                };
                db.Nodes.Add(node);
                db.SaveChanges();
            }

            using (var db = new TestDbContext())
            {
                node.OneToManyOwned.First().RowVersion = null;
                db.UpdateGraph(node, map => map.OwnedCollection(p => p.OneToManyOwned));
                db.SaveChanges();
            }
        }
开发者ID:joswalt,项目名称:Highway.Data,代码行数:25,代码来源:OptimisticConcurrencyBehaviours.cs


示例8: ShouldAddNewAggregateRoot_Attached

        public void ShouldAddNewAggregateRoot_Attached()
        {
            var associated = new OneToOneAssociatedModel { Title = "Associated" };
            var manyAssociated = new OneToManyAssociatedModel { Title = "Associated" };
            var node1 = new TestNode
            {
                Title = "New Node",
                OneToManyOwned = new List<OneToManyOwnedModel>
                {
                    new OneToManyOwnedModel { Title = "One" },
                    new OneToManyOwnedModel { Title = "Two" },
                    new OneToManyOwnedModel { Title = "Three" }
                },
                OneToManyAssociated = new List<OneToManyAssociatedModel>
                {
                    manyAssociated
                },
                OneToOneOwned = new OneToOneOwnedModel { Title = "OneToOne" },
                OneToOneAssociated = associated
            };

            using (var context = new TestDbContext())
            {
                context.OneToManyAssociatedModels.Add(manyAssociated);
                context.OneToOneAssociatedModels.Add(associated);

                     node1 = context.UpdateGraph(node1);

                context.SaveChanges();
                Assert.IsNotNull(context.Nodes.SingleOrDefault(p => p.Id == node1.Id));
            }
        }
开发者ID:siegeon,项目名称:GraphDiff,代码行数:32,代码来源:AddAggregateBehaviours.cs


示例9: ShouldAddAssociatedWithoutChangingRequiredAssociate

        public void ShouldAddAssociatedWithoutChangingRequiredAssociate()
        {
            var root = new RootEntity { RequiredAssociate = new RequiredAssociate(), Sources = new List<RootEntity>() };
            var requiredAssociate = new RequiredAssociate();
            using (var context = new TestDbContext())
            {
                context.RootEntities.Add(root);
                context.RequiredAssociates.Add(requiredAssociate);
                context.SaveChanges();
            } // Simulate detach

            var expectedAssociateId = requiredAssociate.Id;
            var owned = new RootEntity { RequiredAssociate = requiredAssociate };
            root.Sources.Add(owned);

            using (var context = new TestDbContext())
            {
                root = context.UpdateGraph(root, map => map.AssociatedCollection(r => r.Sources));
                context.SaveChanges();

                var ownedAfterSave = root.Sources.FirstOrDefault();
                Assert.IsNotNull(ownedAfterSave);
                Assert.IsNotNull(ownedAfterSave.RequiredAssociate);
                Assert.AreEqual(expectedAssociateId, ownedAfterSave.RequiredAssociate.Id);

                var ownedReloaded = context.RootEntities.Single(r => r.Id == ownedAfterSave.Id);
                Assert.IsNotNull(ownedReloaded.RequiredAssociate);
                Assert.AreEqual(expectedAssociateId, ownedReloaded.RequiredAssociate.Id);
            }
        }
开发者ID:rklachko,项目名称:GraphDiff,代码行数:30,代码来源:AssociatedCollectionBehaviours.cs


示例10: ShouldAddNewItemInOwnedCollection

        public void ShouldAddNewItemInOwnedCollection()
        {
            var node1 = new TestNode
            {
                Title = "New Node",
                OneToManyOwned = new List<OneToManyOwnedModel>
                {
                    new OneToManyOwnedModel { Title = "Hello" }
                }
            };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.SaveChanges();
            } // Simulate detach

            var newModel = new OneToManyOwnedModel { Title = "Hi" };
            node1.OneToManyOwned.Add(newModel);
            using (var context = new TestDbContext())
            {
                // Setup mapping
                context.UpdateGraph(node1, map => map
                    .OwnedCollection(p => p.OneToManyOwned));

                context.SaveChanges();
                var node2 = context.Nodes.Include(p => p.OneToManyOwned).Single(p => p.Id == node1.Id);
                Assert.IsNotNull(node2);
                Assert.IsTrue(node2.OneToManyOwned.Count == 2);
                var owned = context.OneToManyOwnedModels.Single(p => p.Id == newModel.Id);
                Assert.IsTrue(owned.OneParent == node2 && owned.Title == "Hi");
            }
        }
开发者ID:GertArnold,项目名称:GraphDiff,代码行数:33,代码来源:OwnedCollectionBehaviours.cs


示例11: ShouldSupportMultipleKeys

        public void ShouldSupportMultipleKeys()
        {
            var model = new MultiKeyModel
            {
                Title = "Hello",
                Date = DateTime.Now,
                KeyPart1 = "A123",
                KeyPart2 = "A234"
            };

            using (var context = new TestDbContext())
            {
                context.MultiKeyModels.Add(model);
                context.SaveChanges();
            } // simulate detach

            model.Date = DateTime.Parse("01/01/2010");
            using (var context = new TestDbContext())
            {
                model = context.UpdateGraph(model);
                context.SaveChanges();

                context.Entry(model).Reload();
                Assert.IsTrue(model.Date == DateTime.Parse("01/01/2010"));
            }
        }
开发者ID:rklachko,项目名称:GraphDiff,代码行数:26,代码来源:MiscBehaviours.cs


示例12: ShouldAddRelationIfPreviousValueWasNullWithCycle

        public void ShouldAddRelationIfPreviousValueWasNullWithCycle()
        {
            GroupedTestNode two;
            GroupedTestNode one;
            using (var context = new TestDbContext())
            {
                var group = new NodeGroup();
                context.NodeGroups.Add(group);
                context.SaveChanges();

                one = new GroupedTestNode { Group = group };
                context.Nodes.Add(one);
                context.SaveChanges();

                two = new GroupedTestNode { Group = group };
                context.Nodes.Add(two);
                context.SaveChanges();

                Assert.AreEqual(2, group.Members.Count);
            } // Simulate detach

            using (var context = new TestDbContext())
            {
                one.Two = two;

                // Setup mapping
                context.UpdateGraph(one, map => map.AssociatedEntity(o => o.Two));
                context.SaveChanges();

                var oneReloaded = context.Nodes.OfType<GroupedTestNode>().Include("Two").Single(n => n.Id == one.Id);
                Assert.IsNotNull(oneReloaded.Two);
                Assert.AreEqual(two.Id, oneReloaded.Two.Id);
            }
        }
开发者ID:rho24,项目名称:GraphDiff,代码行数:34,代码来源:AssociatedEntityBehaviours.cs


示例13: ShouldAddRelationIfPreviousValueWasNull

        public void ShouldAddRelationIfPreviousValueWasNull()
        {
            var node1 = new TestNode { Title = "New Node" };
            var associated = new OneToOneAssociatedModel { Title = "Associated Node" };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.OneToOneAssociatedModels.Add(associated);
                context.SaveChanges();
            } // Simulate detach

            node1.OneToOneAssociated = associated;

            using (var context = new TestDbContext())
            {
                // Setup mapping
                context.UpdateGraph(node1, map => map
                    .AssociatedEntity(p => p.OneToOneAssociated));

                context.SaveChanges();
                var node2 = context.Nodes.Include(p => p.OneToOneAssociated).Single(p => p.Id == node1.Id);
                Assert.IsNotNull(node2);
                Assert.IsTrue(node2.OneToOneAssociated.OneParent == node2);
            }
        }
开发者ID:rho24,项目名称:GraphDiff,代码行数:26,代码来源:AssociatedEntityBehaviours.cs


示例14: Initialize

 public void Initialize()
 {
     //Arrange
     Context = new TestDbContext();
     var uow = new UnitofWork(Context);
     Controller = new UnitofWorkPatternController(uow);
 }
开发者ID:haithemaraissia,项目名称:RentalMVCClean,代码行数:7,代码来源:UnitRepositoryWithTestDB.cs


示例15: ShouldBeAbleToVisitExpressionsStoredAsProperties

        public void ShouldBeAbleToVisitExpressionsStoredAsProperties()
        {
            var node1 = new TestNode
            {
                Title = "One",
                OneToOneOwned = new OneToOneOwnedModel { Title = "Hello" }
            };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.SaveChanges();
            } // Simulate detach

            node1.OneToOneOwned.Title = "Hey2";

            Lambda = (p => p.OneToOneOwned);
            Expression<Func<IUpdateConfiguration<TestNode>, dynamic>> exp = map => map.OwnedEntity(Lambda);

            using (var context = new TestDbContext())
            {
                // Setup mapping
                context.UpdateGraph(node1, exp);

                context.SaveChanges();
                Assert.IsTrue(context.Nodes
                    .Include(p => p.OneToOneOwned)
                    .Single(p => p.Id == node1.Id)
                    .OneToOneOwned.Title == "Hey2");
            }
        }
开发者ID:rho24,项目名称:GraphDiff,代码行数:31,代码来源:ConfigurationVisitorBehaviours.cs


示例16: ShouldThrowDbUpdateConcurrencyExceptionIfEditingNestedOutOfDateModel

        public void ShouldThrowDbUpdateConcurrencyExceptionIfEditingNestedOutOfDateModel()
        {
            TestNode node;
            using (var db = new TestDbContext())
            {
                node = new TestNode
                {
                    Title = "Hello",
                    OneToManyOwned = new List<OneToManyOwnedModel>
                    {
                        new OneToManyOwnedModel { Title = "Test1" },
                        new OneToManyOwnedModel { Title = "Test2" }
                    }
                };
                db.Nodes.Add(node);
                db.SaveChanges();
            }

            using (var db = new TestDbContext())
            {
                node.OneToManyOwned.First().RowVersion = new byte[] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1 };
                db.UpdateGraph(node);
                db.SaveChanges();
            }
        }
开发者ID:siegeon,项目名称:GraphDiff,代码行数:25,代码来源:OptimisticConcurrencyBehaviours.cs


示例17: InsertTestItems

        public static void InsertTestItems(TestDbContext context)
        {
            var item1 = new Item { Name = "Test Item 1", Description = "Test Item 1" };
            var item2 = new Item { Name = "Test Item 2", Description = "Test Item 2" };

            context.Set<Item>().Add(item1);
            context.Set<Item>().Add(item2);
        }
开发者ID:careldutoit-vox,项目名称:AfricanCraftsold,代码行数:8,代码来源:TestData.cs


示例18: TestInitialize

        public void TestInitialize()
        {
            context = new TestDbContext();
            repo = new MBlogRepository(context);

            for (int i = 1; i <= 10; i++)
                context.Posts.Add(new Post() { Title = "Post " + i, PublishDate = DateTime.UtcNow.AddDays(11 - i) });
        }
开发者ID:Henroc,项目名称:MBlog,代码行数:8,代码来源:HomeControllerTest.cs


示例19: ShouldThrowIfTypeIsNotKnown

 public void ShouldThrowIfTypeIsNotKnown()
 {
     using (var context = new TestDbContext())
     {
         context.UpdateGraph(new UnknownType());
         context.SaveChanges();
     }
 }
开发者ID:rho24,项目名称:GraphDiff,代码行数:8,代码来源:ErrorHandlingBehaviours.cs


示例20: SqlDataContextFixture

 public SqlDataContextFixture()
 {
     using (var dbContext = new TestDbContext())
     {
         dbContext.Database.Delete();
         dbContext.Database.Create();
     }
 }
开发者ID:wayne-o,项目名称:delete-me,代码行数:8,代码来源:SqlDataContextFixture.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# TestDelegate类代码示例发布时间:2022-05-24
下一篇:
C# TestDatabaseContext类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap