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

C# InMemoryAdapter类代码示例

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

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



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

示例1: StopUsingMockAdapterStopsUsingMockAdapter

 public void StopUsingMockAdapterStopsUsingMockAdapter()
 {
     var mock = new InMemoryAdapter();
     Database.UseMockAdapter(mock);
     Database db = Database.OpenNamedConnection("Mock");
     Assert.AreSame(mock, db.GetAdapter());
     Database.StopUsingMockAdapter();
     db = Database.OpenNamedConnection("Mock");
     Assert.IsInstanceOf<AdoAdapter>(db.GetAdapter());
 }
开发者ID:JorgeGamba,项目名称:Simple.Data,代码行数:10,代码来源:StopUsingMockTest.cs


示例2: InsertAndGetShouldWork

 public void InsertAndGetShouldWork()
 {
     var adapter = new InMemoryAdapter();
     adapter.SetKeyColumn("Test", "Id");
     Database.UseMockAdapter(adapter);
     var db = Database.Open();
     db.Test.Insert(Id: 1, Name: "Alice");
     var record = db.Test.Get(1);
     Assert.IsNotNull(record);
     Assert.AreEqual(1, record.Id);
     Assert.AreEqual("Alice", record.Name);
 }
开发者ID:da9l,项目名称:Simple.Data,代码行数:12,代码来源:InMemoryTests.cs


示例3: InsertAndFindByTableNameResolvesCorrectlyWithHomogenisedStringComparer

        public void InsertAndFindByTableNameResolvesCorrectlyWithHomogenisedStringComparer()
        {
            var inMemoryAdapter = new InMemoryAdapter(new AdoCompatibleComparer());

            Database.UseMockAdapter(inMemoryAdapter);
            var db = Database.Open();

            db.CUSTOMER.Insert(ID: 1, NAME: "ACME");

            var actual = db.Customers.FindById(1);
            Assert.IsNotNull(actual);
            Assert.AreEqual("ACME", actual.Name);
        }
开发者ID:JorgeGamba,项目名称:Simple.Data,代码行数:13,代码来源:NameResolutionTest.cs


示例4: InsertAndGetWithArrayPropertyShouldWork

 public void InsertAndGetWithArrayPropertyShouldWork()
 {
     var adapter = new InMemoryAdapter();
     adapter.SetKeyColumn("Test", "Id");
     Database.UseMockAdapter(adapter);
     var db = Database.Open();
     db.Test.Insert(Id: 1, Names: new List<string> {"Alice", "Bob", "Charlie"});
     People record = db.Test.Get(1);
     Assert.IsNotNull(record);
     Assert.AreEqual(1, record.Id);
     Assert.AreEqual("Alice", record.Names[0]);
     Assert.AreEqual("Bob", record.Names[1]);
     Assert.AreEqual("Charlie", record.Names[2]);
 }
开发者ID:JorgeGamba,项目名称:Simple.Data,代码行数:14,代码来源:CanAssignArray.cs


示例5: TestJoinWithAlias

        public void TestJoinWithAlias()
        {
            var adapter = new InMemoryAdapter();
            adapter.ConfigureJoin("Customer", "ID", "Customer", "Orders", "CustomerID", "Orders");
            Database.UseMockAdapter(adapter);
            var db = Database.Open();
            db.Customer.Insert(ID: 1, Name: "NASA");
            db.Customer.Insert(ID: 2, Name: "ACME");
            db.Orders.Insert(ID: 1, Name: "Order1", CustomerID: 1);
            db.Orders.Insert(ID: 2, Name: "Order2", CustomerID: 2);
            db.Orders.Insert(ID: 3, Name: "Order3", CustomerID: 2);

            IEnumerable<dynamic> orders = db.Orders.Query()
                .Where(db.Orders.Customer.Name == "ACME")
                .Select(db.Orders.Name.As("OrderName"),
                        db.Orders.Customer.Name.As("CustomerName"))
                .ToList();
            Assert.IsNotNull(orders);
            Assert.AreEqual(2, orders.Count());
            Assert.AreEqual(2, orders.Count(x => x.CustomerName == "ACME"));
        }
开发者ID:da9l,项目名称:Simple.Data,代码行数:21,代码来源:InMemoryTests.cs


示例6: ThreadTestHelper

 private static int ThreadTestHelper(int userId)
 {
     var mockAdapter = new InMemoryAdapter();
     Database.UseMockAdapter(mockAdapter);
     var db = Database.Open();
     db.Users.Insert(Id: userId, Email: "foo");
     return Database.Default.Users.FindByEmail("foo").Id;
 }
开发者ID:da9l,项目名称:Simple.Data,代码行数:8,代码来源:InMemoryTests.cs


示例7: ShouldBeAbleToSetAutoIncrementWhenSettingKeyColumn

        public void ShouldBeAbleToSetAutoIncrementWhenSettingKeyColumn()
        {
            // Arrange
            var adapter = new InMemoryAdapter();

            // Act
            adapter.SetAutoIncrementKeyColumn("Users", "Id");

            // Assert
            Database.UseMockAdapter(adapter);
            var db = Database.Open();
            var firstId = db.Users.Insert(Name: "Marcus").Id;
            Assert.AreEqual(1, firstId);
        }
开发者ID:da9l,项目名称:Simple.Data,代码行数:14,代码来源:InMemoryTests.cs


示例8: TestFindAcrossJoinAfterDelete

        public void TestFindAcrossJoinAfterDelete()
        {
            var adapter = new InMemoryAdapter();
            adapter.SetKeyColumn("Thing1Table", "Id");
            adapter.SetKeyColumn("Thing2Table", "Id");
            adapter.Join.Master("Thing1Table", "Id").Detail("ThingJoin", "Thing1Id");
            adapter.Join.Master("Thing2Table", "Id").Detail("ThingJoin", "Thing2Id");

            Database.UseMockAdapter(adapter);
            var db = Database.Open();

            var thing1 = new {Id = 1, Name = "Thing1"};
            var thing2 = new {Id = 2, Name = "Thing2"};
            var thingJoin = new {Thing1Id = 1, Thing2Id = 2};
 
            db.Thing1Table.Insert(thing1);
            db.Thing2Table.Insert(thing2);
            db.ThingJoin.Insert(thingJoin);
 
            //Delete the join object.
            db.ThingJoin.DeleteAll(db.ThingJoin.Thing1Id == 1 && db.ThingJoin.Thing2Id == 2);
            
            //Ensure after we drop one of the relationships, there is only no records left in the join table.
            Assert.AreEqual(0, db.ThingJoin.All().ToList().Count);

            //Ensure we don't find the Thing across the join after the delete
            var foundByJoin = db.Thing1Table.FindAll(db.Thing1Table.ThingJoin.Thing1Id == 1).FirstOrDefault();
            Assert.IsNull(foundByJoin);
        }
开发者ID:vertiman,项目名称:Simple.Data,代码行数:29,代码来源:InMemoryTests.cs


示例9: JoinTest

 public void JoinTest()
 {
     Guid masterId = Guid.NewGuid();
     InMemoryAdapter adapter = new InMemoryAdapter();
     adapter.Join.Master("Master", "Id").Detail("Detail", "MasterId");
     Database.UseMockAdapter(adapter);
     var db = Database.Open();
     db.Master.Insert(Id: masterId);
     db.Detail.Insert(Id: Guid.NewGuid(), MasterId: masterId, Box: 999);
     // Act
     IEnumerable<dynamic> list = db.Detail.All()
         .Join(db.Master).On(db.Master.Id == db.Detail.MasterId)
         .Select(db.Master.Id, db.Detail.Box)
                 .Cast<dynamic>();
     // Assert
     dynamic detail = list.FirstOrDefault();
     Assert.NotNull(detail);
     Assert.That(detail.Id, Is.EqualTo(masterId));
     Assert.That(detail.Box, Is.EqualTo(999));
 }
开发者ID:da9l,项目名称:Simple.Data,代码行数:20,代码来源:InMemoryTests.cs


示例10: UpsertShouldUpdateExistingRecord

 public void UpsertShouldUpdateExistingRecord()
 {
     var adapater = new InMemoryAdapter();
     adapater.SetKeyColumn("Test","Id");
     Database.UseMockAdapter(adapater);
     var db = Database.Open();
     db.Test.Upsert(Id: 1, SomeValue: "Testing");
     db.Test.Upsert(Id: 1, SomeValue: "Updated");
     List<dynamic> allRecords = db.Test.All().ToList();
     Assert.IsNotNull(allRecords);
     Assert.AreEqual(1,allRecords.Count);
     Assert.AreEqual("Updated", allRecords.Single().SomeValue);
 }
开发者ID:da9l,项目名称:Simple.Data,代码行数:13,代码来源:InMemoryTests.cs


示例11: ProcedureWithParametersReturningArrayShouldWork

 public void ProcedureWithParametersReturningArrayShouldWork()
 {
     var adapter = new InMemoryAdapter();
     adapter.AddFunction<string, object, IDictionary<string, object>[]>("Test", (key, value) => new IDictionary<string, object>[] {new Dictionary<string, object> { { key, value } }});
     Database.UseMockAdapter(adapter);
     var db = Database.Open();
     foreach (var row in db.Test("Foo", "Bar"))
     {
         Assert.AreEqual("Bar", row.Foo);
     }
 }
开发者ID:da9l,项目名称:Simple.Data,代码行数:11,代码来源:InMemoryTests.cs


示例12: TestUpdate

 public void TestUpdate()
 {
     var adapter = new InMemoryAdapter();
     adapter.SetKeyColumn("Test", "Id");
     Database.UseMockAdapter(adapter);
     var db = Database.Open();
     var alice = db.Test.Insert(Id: 1, Name: "Alice");
     var allyce = new { Id = 1, Name = "Allyce" };
     int updated = db.Test.Update(allyce);
     Assert.AreEqual(1, updated);
     var record = db.Test.FindById(1);
     Assert.AreEqual("Allyce", record.Name);
 }
开发者ID:da9l,项目名称:Simple.Data,代码行数:13,代码来源:InMemoryTests.cs


示例13: UpdateWithOriginalValuesRowsUpdatedShouldBeZeroIfNewValueAreSameAsOriginalValue

        public void UpdateWithOriginalValuesRowsUpdatedShouldBeZeroIfNewValueAreSameAsOriginalValue()
        {
            var adapter = new InMemoryAdapter();
            adapter.SetKeyColumn("Test", "Id");
            Database.UseMockAdapter(adapter);
            var db = Database.Open();
            db.Test.Upsert(Id: 1, SomeValue: "Testing");
            var record = db.Test.Get(1);
            var record1 = record.Clone();

            var rowsUpdated = db.Test.Update(record, record1);

            Assert.AreEqual(0, rowsUpdated);
        }
开发者ID:vertiman,项目名称:Simple.Data,代码行数:14,代码来源:InMemoryTests.cs


示例14: CanSimulateProcedureWithOutputParameters

 public void CanSimulateProcedureWithOutputParameters()
 {
     const string key = "outparam";
     const string value = "outParamValue";
     var adapter = new InMemoryAdapter();
     adapter.AddFunction("Test", p =>
         {
             p.Add(key, value);
             return p;
         });
     Database.UseMockAdapter(adapter);
     var db = Database.Open();
     var result = db.Test();
     Assert.That(result.OutputValues[key], Is.EqualTo(value));
 }
开发者ID:vertiman,项目名称:Simple.Data,代码行数:15,代码来源:InMemoryTests.cs


示例15: InsertAndGetWithTransactionShouldWork

 public void InsertAndGetWithTransactionShouldWork()
 {
     var adapter = new InMemoryAdapter();
     adapter.SetKeyColumn("Test", "Id");
     Database.UseMockAdapter(adapter);
     var db = Database.Open();
     using (var tx = db.BeginTransaction())
     {
         tx.Test.Insert(Id: 1, Name: "Alice");
         var record = tx.Test.Get(1);
         Assert.IsNotNull(record);
         Assert.AreEqual(1, record.Id);
         Assert.AreEqual("Alice", record.Name);
     }
 }
开发者ID:da9l,项目名称:Simple.Data,代码行数:15,代码来源:InMemoryTests.cs


示例16: ProcedureReturningArrayShouldWork

 public void ProcedureReturningArrayShouldWork()
 {
     var adapter = new InMemoryAdapter();
     adapter.AddFunction("Test", () => new[] { new Dictionary<string, object> { { "Foo", "Bar" } } });
     Database.UseMockAdapter(adapter);
     var db = Database.Open();
     foreach (var row in db.Test())
     {
         Assert.AreEqual("Bar", row.Foo);
     }
 }
开发者ID:da9l,项目名称:Simple.Data,代码行数:11,代码来源:InMemoryTests.cs


示例17: TestJoinConfig

        public void TestJoinConfig()
        {
            var adapter = new InMemoryAdapter();
            adapter.Join.Master("Customer", "ID").Detail("Order", "CustomerID");
            Database.UseMockAdapter(adapter);
            var db = Database.Open();
            db.Customer.Insert(ID: 1, Name: "NASA");
            db.Customer.Insert(ID: 2, Name: "ACME");
            db.Order.Insert(ID: 1, CustomerID: 1, Date: new DateTime(1997, 1, 12));
            db.Order.Insert(ID: 2, CustomerID: 2, Date: new DateTime(2001, 1, 1));

            var customers = db.Customer.FindAll(db.Customer.Order.Date < new DateTime(1999, 12, 31)).ToList();
            Assert.IsNotNull(customers);
            Assert.AreEqual(1, customers.Count);
        }
开发者ID:da9l,项目名称:Simple.Data,代码行数:15,代码来源:InMemoryTests.cs


示例18: UpsertShouldAddNewRecord

 public void UpsertShouldAddNewRecord()
 {
     var adapter = new InMemoryAdapter();
     adapter.SetKeyColumn("Test", "Id");
     Database.UseMockAdapter(adapter);
     var db = Database.Open();
     db.Test.Upsert(Id: 1, SomeValue: "Testing");
     var record = db.Test.Get(1);
     Assert.IsNotNull(record);
     Assert.AreEqual("Testing", record.SomeValue);
 }
开发者ID:da9l,项目名称:Simple.Data,代码行数:11,代码来源:InMemoryTests.cs


示例19: FindAllWhenUsingAnyOldPropertyNameShouldWork

        public void FindAllWhenUsingAnyOldPropertyNameShouldWork()
        {
            var adapter = new InMemoryAdapter();
            adapter.ConfigureJoin("Users", "Id", "User", "Categories", "UserId", "Categories");
            Database.UseMockAdapter(adapter);
            var db = Database.Open();

            db.Users.Insert(Id: 1, UserName: "Marcus");
            db.Users.Insert(Id: 2, UserName: "Per");
            db.Categories.Insert(Id: 1, UserId: 1, CategoryName: "Category 1");
            db.Categories.Insert(Id: 2, UserId: 2, CategoryName: "Category 2");

            var categories = db.Users.FindAll(db.User.Categories.CategoryName == "Category 1").ToList();
            Assert.NotNull(categories);
            Assert.AreEqual(1, categories.Count);
        }
开发者ID:da9l,项目名称:Simple.Data,代码行数:16,代码来源:InMemoryTests.cs


示例20: UpsertWithoutDefinedKeyColumnsSHouldThrowMeaningfulException

 public void UpsertWithoutDefinedKeyColumnsSHouldThrowMeaningfulException()
 {
     var adapter = new InMemoryAdapter();
     Database.UseMockAdapter(adapter);
     var db = Database.Open();
     var exception = Assert.Throws<InvalidOperationException>(() => db.Test.Upsert(Id: 1, HasTowel: true));
     Assert.AreEqual("No key columns defined for table \"Test\"", exception.Message);
 }
开发者ID:da9l,项目名称:Simple.Data,代码行数:8,代码来源:InMemoryTests.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# InMemoryBus类代码示例发布时间:2022-05-24
下一篇:
C# InIReader类代码示例发布时间: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