本文整理汇总了C#中SQLite.Net.Tests.TestDb.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# TestDb.Insert方法的具体用法?C# TestDb.Insert怎么用?C# TestDb.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQLite.Net.Tests.TestDb
的用法示例。
在下文中一共展示了TestDb.Insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Collate
public void Collate()
{
var obj = new TestObj
{
CollateDefault = "Alpha ",
CollateBinary = "Alpha ",
CollateRTrim = "Alpha ",
CollateNoCase = "Alpha ",
};
var db = new TestDb(new SQLitePlatformTest(), TestPath.GetTempFileName());
db.Insert(obj);
Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateDefault == "Alpha " select o).Count());
Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateDefault == "ALPHA " select o).Count());
Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateDefault == "Alpha" select o).Count());
Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateDefault == "ALPHA" select o).Count());
Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateBinary == "Alpha " select o).Count());
Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateBinary == "ALPHA " select o).Count());
Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateBinary == "Alpha" select o).Count());
Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateBinary == "ALPHA" select o).Count());
Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateRTrim == "Alpha " select o).Count());
Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateRTrim == "ALPHA " select o).Count());
Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateRTrim == "Alpha" select o).Count());
Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateRTrim == "ALPHA" select o).Count());
Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateNoCase == "Alpha " select o).Count());
Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateNoCase == "ALPHA " select o).Count());
Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateNoCase == "Alpha" select o).Count());
Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateNoCase == "ALPHA" select o).Count());
}
示例2: CreateThem
public void CreateThem()
{
var db = new TestDb(new SQLitePlatformTest());
var foo = new Product
{
Name = "Foo",
Price = 10.0m
};
var bar = new Product
{
Name = "Bar",
Price = 0.10m
};
db.Insert(foo);
db.Insert(bar);
db.Insert(new OrderLine
{
ProductId = foo.Id,
Quantity = 6,
UnitPrice = 10.01m
});
db.Insert(new OrderLine
{
ProductId = foo.Id,
Quantity = 3,
UnitPrice = 0.02m
});
db.Insert(new OrderLine
{
ProductId = bar.Id,
Quantity = 9,
UnitPrice = 100.01m
});
OrderLine[] lines = foo.GetOrderLines();
Assert.AreEqual(lines.Length, 2, "Has 2 order lines");
Assert.AreEqual(foo.Connection, db, "foo.Connection was set");
Assert.AreEqual(lines[0].Connection, db, "lines[0].Connection was set");
}
示例3: Issue86
public void Issue86()
{
var db = new TestDb();
db.CreateTable<Foo>();
db.Insert(new Foo
{
Bar = 42
});
db.Insert(new Foo
{
Bar = 69
});
Foo found42 = db.Table<Foo>().Where(f => f.Bar == 42).FirstOrDefault();
Assert.IsNotNull(found42);
var ordered = new List<Foo>(db.Table<Foo>().OrderByDescending(f => f.Bar));
Assert.AreEqual(2, ordered.Count);
Assert.AreEqual(69, ordered[0].Bar);
Assert.AreEqual(42, ordered[1].Bar);
}
示例4: VerifyCreations
private static void VerifyCreations(TestDb db)
{
TableMapping orderLine = db.GetMapping(typeof (OrderLine));
Assert.AreEqual(6, orderLine.Columns.Length);
var l = new OrderLine
{
Status = OrderLineStatus.Shipped
};
db.Insert(l);
OrderLine lo = db.Table<OrderLine>().First(x => x.Status == OrderLineStatus.Shipped);
Assert.AreEqual(lo.Id, l.Id);
}
示例5: ToUpper
public void ToUpper()
{
var db = new TestDb();
db.CreateTable<TestTable>();
var testTable = new TestTable()
{
Name = "test"
};
db.Insert(testTable);
var x = db.Table<TestTable>().Where(t => t.Name.ToUpper() == "TEST");
Assert.AreEqual(1, x.Count());
}
示例6: TestDateTimeOffset
void TestDateTimeOffset (TestDb db)
{
db.CreateTable<TestObj> ();
TestObj o, o2;
//
// Ticks
//
o = new TestObj {
ModifiedTime = new DateTimeOffset (2012, 1, 14, 3, 2, 1, TimeSpan.Zero),
};
db.Insert (o);
o2 = db.Get<TestObj> (o.Id);
Assert.AreEqual (o.ModifiedTime, o2.ModifiedTime);
}
示例7: CheckPK
private void CheckPK(TestDb db)
{
for (int i = 1; i <= 10; i++)
{
var na = new NoAttributes
{
Id = i,
AColumn = i.ToString(),
IndexedId = 0
};
db.Insert(na);
}
var item = db.Get<NoAttributes>(2);
Assert.IsNotNull(item);
Assert.AreEqual(2, item.Id);
}
示例8: SelectWorks
public void SelectWorks()
{
using (var db = new TestDb(TestPath.GetTempFileName()))
{
db.Insert(new TestObj() {Order = 5});
try
{
Assert.That(db.Table<TestObj>().Select(obj => obj.Order * 2).First(), Is.EqualTo(10));
}
catch (NotImplementedException)
{
//Allow Not implemented exceptions as the selection may be too complex.
}
}
}
示例9: Insert
public void Insert()
{
var db = new TestDb();
db.CreateTable<UnicodeProduct>();
string testString = "\u2329\u221E\u232A";
db.Insert(new UnicodeProduct
{
Name = testString,
});
var p = db.Get<UnicodeProduct>(1);
Assert.AreEqual(testString, p.Name);
}
示例10: Query
public void Query()
{
var db = new TestDb();
db.CreateTable<UnicodeProduct>();
string testString = "\u2329\u221E\u232A";
db.Insert(new UnicodeProduct
{
Name = testString,
});
var ps = (from p in db.Table<UnicodeProduct>() where p.Name == testString select p).ToList();
Assert.AreEqual(1, ps.Count);
Assert.AreEqual(testString, ps[0].Name);
}
示例11: TestDateTime
private void TestDateTime(TestDb db)
{
db.CreateTable<TestObj>();
//
// Ticks
//
var org = new TestObj
{
Time1 = DateTime.UtcNow,
Time2 = DateTime.Now,
};
db.Insert(org);
var fromDb = db.Get<TestObj>(org.Id);
Assert.AreEqual(fromDb.Time1.ToUniversalTime(), org.Time1.ToUniversalTime());
Assert.AreEqual(fromDb.Time2.ToUniversalTime(), org.Time2.ToUniversalTime());
Assert.AreEqual(fromDb.Time1.ToLocalTime(), org.Time1.ToLocalTime());
Assert.AreEqual(fromDb.Time2.ToLocalTime(), org.Time2.ToLocalTime());
}
示例12: TestDateTime
private void TestDateTime(TestDb db)
{
db.CreateTable<TestObj>();
TestObj o, o2;
//
// Ticks
//
o = new TestObj
{
ModifiedTime = DateTime.UtcNow,
};
db.Insert(o);
o2 = db.Get<TestObj>(o.Id);
Assert.AreEqual(o.ModifiedTime, o2.ModifiedTime.ToUniversalTime());
var expectedTimeZone = db.StoreDateTimeAsTicks ? DateTimeKind.Utc : DateTimeKind.Local;
Assert.AreEqual(o2.ModifiedTime.Kind, expectedTimeZone);
}
示例13: CreateInsertDrop
public void CreateInsertDrop()
{
var db = new TestDb();
db.CreateTable<Product>();
db.Insert(new Product
{
Name = "Hello",
Price = 16,
});
int n = db.Table<Product>().Count();
Assert.AreEqual(1, n);
db.DropTable<Product>();
ExceptionAssert.Throws<SQLiteException>(() => db.Table<Product>().Count());
}
示例14: Issue303_WhereNot_B
public void Issue303_WhereNot_B()
{
using (var db = new TestDb())
{
db.CreateTable<Issue303_B>();
db.Insert(new Issue303_B { Id = 1, Flag = true });
db.Insert(new Issue303_B { Id = 2, Flag = false });
db.Insert(new Issue303_B { Id = 3, Flag = true });
db.Insert(new Issue303_B { Id = 4, Flag = false });
var r = (from p in db.Table<Issue303_B>() where !p.Flag select p).ToList();
Assert.AreEqual(2, r.Count);
Assert.AreEqual(2, r[0].Id);
Assert.AreEqual(4, r[1].Id);
}
}
示例15: NotNullConstraintExceptionListsOffendingColumnsOnInsert
public void NotNullConstraintExceptionListsOffendingColumnsOnInsert()
{
using (TestDb db = new TestDb())
{
db.CreateTable<NotNullNoPK>();
try
{
NotNullNoPK obj = new NotNullNoPK() { RequiredStringProp = "Some value" };
db.Insert(obj);
}
catch (NotNullConstraintViolationException ex)
{
string expected = "AnotherRequiredStringProp, RequiredIntProp";
string actual = string.Join(", ", ex.Columns.Where(c => !c.IsPK).OrderBy(p => p.PropertyName).Select(c => c.PropertyName));
Assert.AreEqual(expected, actual, "NotNullConstraintViolationException did not correctly list the columns that violated the constraint");
return;
}
catch (SQLiteException ex)
{
if (db.Platform.SQLiteApi.LibVersionNumber() < 3007017 && ex.Result == Result.Constraint)
{
Assert.Inconclusive("Detailed constraint information is only available in SQLite3 version 3.7.17 and above.");
}
}
Assert.Fail("Expected an exception of type NotNullConstraintViolationException to be thrown. No exception was thrown.");
}
}