本文整理汇总了C#中InMemoryAdapter类的典型用法代码示例。如果您正苦于以下问题:C# InMemoryAdapter类的具体用法?C# InMemoryAdapter怎么用?C# InMemoryAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InMemoryAdapter类属于命名空间,在下文中一共展示了InMemoryAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例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);
}
示例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);
}
示例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]);
}
示例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"));
}
示例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;
}
示例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);
}
示例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);
}
示例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));
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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));
}
示例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);
}
}