public void Can_GetFirstColumn() { const int n = 5; using (var db = OpenDbConnection()) { db.DropAndCreateTable <ModelWithIdAndName>(); n.Times(x => db.Insert(ModelWithIdAndName.Create(x))); var ids = db.Column <int>("SELECT Id FROM " + "ModelWithIdAndName".SqlTable(DialectProvider)); Assert.That(ids.Count, Is.EqualTo(n)); } }
public void Can_StoreAll_and_GetByIds_ModelWithIdAndName() { using (var redis = new RedisClient(TestConfig.SingleHost)) { var ids = new[] { 1, 2, 3, 4, 5 }; var tos = ids.ConvertAll(x => ModelWithIdAndName.Create(x)); redis.StoreAll(tos); var froms = redis.GetByIds <ModelWithIdAndName>(ids); var fromIds = froms.ConvertAll(x => x.Id); Assert.That(fromIds, Is.EquivalentTo(ids)); } }
public void Can_select_scalar_value() { const int n = 5; using (var db = OpenDbConnection()) { db.CreateTable <ModelWithIdAndName>(true); n.Times(x => db.Insert(ModelWithIdAndName.Create(x))); var count = db.Scalar <int>("SELECT COUNT(*) FROM ModelWithIdAndName"); Assert.That(count, Is.EqualTo(n)); } }
public void Can_GetFirstColumnDistinct() { const int n = 5; using (var db = OpenDbConnection()) { db.CreateTable <ModelWithIdAndName>(true); n.Times(x => db.Insert(ModelWithIdAndName.Create(x))); var ids = db.ColumnDistinct <int>("SELECT Id FROM ModelWithIdAndName"); Assert.That(ids.Count, Is.EqualTo(n)); } }
public void Can_GetFirstColumn() { const int n = 5; using (var db = ConnectionString.OpenDbConnection()) { db.CreateTable <ModelWithIdAndName>(true); n.Times(x => db.Insert(ModelWithIdAndName.Create(x))); var ids = db.GetFirstColumn <int>("SELECT \"Id\" FROM \"ModelWithIdAndName\""); Assert.That(ids.Count, Is.EqualTo(n)); } }
public void Can_GetFirstColumnDistinct() { const int n = 5; using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithIdAndName>(true); db.DeleteAll <ModelWithIdAndName>(); n.Times(x => db.Insert(ModelWithIdAndName.Create(0))); var ids = db.ColumnDistinct <int>("SELECT Id FROM ModelWIN"); Assert.That(ids.Count, Is.EqualTo(n)); } }
public void Can_Select_In_for_string_value() { const int n = 5; using (var db = OpenDbConnection()) { db.DropAndCreateTable <ModelWithIdAndName>(); n.Times(x => db.Insert(ModelWithIdAndName.Create(x))); var selectInNames = new[] { "Name1", "Name2" }; var rows = db.SelectFmt <ModelWithIdAndName>("Name IN ({0})", selectInNames.SqlInValues()); Assert.That(rows.Count, Is.EqualTo(selectInNames.Length)); } }
public void Can_ExecAs_ModelWithIdAndName_Func_List() { var expected = new[] { ModelWithIdAndName.Create(1), ModelWithIdAndName.Create(2), ModelWithIdAndName.Create(3), }; List <ModelWithIdAndName> actual = redisManager.ExecAs <ModelWithIdAndName>(m => { var list = m.Lists["typed-list"]; list.AddRange(expected); return(list.GetAll()); }); Assert.That(actual.EquivalentTo(expected)); }
public void Can_ExecAs_ModelWithIdAndName_Func_IList() { ModelWithIdAndName[] expected = { ModelWithIdAndName.Create(1), ModelWithIdAndName.Create(2), ModelWithIdAndName.Create(3) }; var actual = this._redisManager.ExecAs <ModelWithIdAndName>(m => { var list = m.Lists["typed-list"]; list.AddRange(expected); return((IList <ModelWithIdAndName>)list.GetAll()); }); Assert.That(actual.EquivalentTo(expected)); }
public void Can_select_scalar_value() { const int n = 5; using (var db = ConnectionString.OpenDbConnection()) using (var dbCmd = db.CreateCommand()) { dbCmd.CreateTable <ModelWithIdAndName>(true); n.Times(x => dbCmd.Insert(ModelWithIdAndName.Create(x))); var count = dbCmd.GetScalar <long>("SELECT COUNT(*) FROM \"ModelWithIdAndName\""); Assert.That(count, Is.EqualTo(n)); } }
public void Can_select_scalar_value() { const int n = 5; using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithIdAndName>(true); db.DeleteAll <ModelWithIdAndName>(); n.Times(x => db.Insert(ModelWithIdAndName.Create(0))); var count = db.Scalar <int>("SELECT COUNT(*) FROM ModelWIN"); Assert.That(count, Is.EqualTo(n)); } }
public void Can_Save_table_with_null_fields() { using var db = OpenDbConnection(); db.CreateTable <ModelWithIdAndName>(true); var row = ModelWithIdAndName.Create(1); row.Name = null; db.Save(row); var rows = db.Select <ModelWithIdAndName>(); Assert.That(rows, Has.Count.EqualTo(1)); ModelWithIdAndName.AssertIsEqual(rows[0], row); }
public void Can_Select_In_for_string_value() { const int n = 5; using (var db = ConnectionString.OpenDbConnection()) using (var dbCmd = db.CreateCommand()) { dbCmd.CreateTable <ModelWithIdAndName>(true); n.Times(x => dbCmd.Insert(ModelWithIdAndName.Create(x))); var selectInNames = new[] { "Name1", "Name2" }; var rows = dbCmd.Select <ModelWithIdAndName>("\"Name\" IN ({0})", selectInNames.SqlInValues()); Assert.That(rows.Count, Is.EqualTo(selectInNames.Length)); } }
public void Can_GetDictionary() { const int n = 5; using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithIdAndName>(true); db.DeleteAll <ModelWithIdAndName>(); n.Times(x => db.Insert(ModelWithIdAndName.Create(0))); var dictionary = db.Dictionary <int, string>("SELECT Id, Name FROM ModelWIN"); Assert.That(dictionary, Has.Count.EqualTo(5)); //Console.Write(dictionary.Dump()); } }
public void Can_GetFirstColumnDistinct() { const int n = 5; using (var db = ConnectionString.OpenDbConnection()) using (var dbCmd = db.CreateCommand()) { dbCmd.CreateTable <ModelWithIdAndName>(true); dbCmd.DeleteAll <ModelWithIdAndName>(); n.Times(x => dbCmd.Insert(ModelWithIdAndName.Create(0))); var ids = dbCmd.GetFirstColumnDistinct <int>("SELECT Id FROM ModelWIN"); Assert.That(ids.Count, Is.EqualTo(n)); } }
public void Can_GetDictionary() { const int n = 5; using (var db = OpenDbConnection()) { db.DropAndCreateTable <ModelWithIdAndName>(); n.Times(x => db.Insert(ModelWithIdAndName.Create(x))); var dictionary = db.Dictionary <int, string>("SELECT Id, Name FROM ModelWithIdAndName"); Assert.That(dictionary, Has.Count.EqualTo(5)); //Console.Write(dictionary.Dump()); } }
public void Can_GetDictionary() { const int n = 5; using (var db = OpenDbConnection()) { db.CreateTable <ModelWithIdAndName>(true); n.Times(x => db.Insert(ModelWithIdAndName.Create(x))); var dictionary = db.Dictionary <int, string>("SELECT \"id\", \"name\" FROM {0}".Fmt("ModelWithIdAndName".SqlTable())); Assert.That(dictionary, Has.Count.EqualTo(5)); //Console.Write(dictionary.Dump()); } }
public void Can_Select_In_for_string_value() { const int n = 5; using (var db = OpenDbConnection()) { db.DropAndCreateTable <ModelWithIdAndName>(); n.Times(x => db.Insert(ModelWithIdAndName.Create(x))); var selectInNames = new[] { "Name1", "Name2" }; var rows = db.Select <ModelWithIdAndName>("Name IN ({0})".Fmt(selectInNames.SqlInParams()), new { values = selectInNames.SqlInValues() }); Assert.That(rows.Count, Is.EqualTo(selectInNames.Length)); rows = db.Select <ModelWithIdAndName>("Name IN (@p1, @p2)".PreNormalizeSql(db), new { p1 = "Name1", p2 = "Name2" }); Assert.That(rows.Count, Is.EqualTo(selectInNames.Length)); } }
public void Can_insert_table_with_null_fields() { using (var db = ConnectionString.OpenDbConnection()) { db.CreateTable <ModelWithIdAndName>(true); db.DeleteAll <ModelWithIdAndName>(); var row = ModelWithIdAndName.Create(0); row.Name = null; db.Insert(row); var rows = db.Select <ModelWithIdAndName>(); Assert.That(rows, Has.Count.EqualTo(1)); ModelWithIdAndName.AssertIsEqual(rows[0], row); } }
public void Can_insert_table_with_null_fields() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithIdAndName>(true); db.DeleteAll <ModelWithIdAndName>(); var row = ModelWithIdAndName.Create(0); row.Name = null; db.Insert(row); var rows = db.Select <ModelWithIdAndName>(); Assert.That(rows, Has.Count.EqualTo(1)); ModelWithIdAndName.AssertIsEqual(rows[0], row); } }
public void Can_serialize_Stack_Generic() { var stack = new Stack <ModelWithIdAndName>(); stack.Push(ModelWithIdAndName.Create(1)); stack.Push(ModelWithIdAndName.Create(2)); stack.Push(ModelWithIdAndName.Create(3)); Serialize(stack); Assert.That(CsvSerializer.SerializeToString(stack), Is.EqualTo( "Id,Name\r\n" + "3,Name3\r\n" + "2,Name2\r\n" + "1,Name1\r\n" )); }
public void Can_serialize_Queue_Generic() { var queue = new Queue <ModelWithIdAndName>(); queue.Enqueue(ModelWithIdAndName.Create(1)); queue.Enqueue(ModelWithIdAndName.Create(2)); queue.Enqueue(ModelWithIdAndName.Create(3)); Serialize(queue); Assert.That(CsvSerializer.SerializeToString(queue), Is.EqualTo( "Id,Name\r\n" + "1,Name1\r\n" + "2,Name2\r\n" + "3,Name3\r\n" )); }
public void Can_GetDictionary() { const int n = 5; using (var db = ConnectionString.OpenDbConnection()) using (var dbCmd = db.CreateCommand()) { dbCmd.CreateTable <ModelWithIdAndName>(true); dbCmd.DeleteAll <ModelWithIdAndName>(); n.Times(x => dbCmd.Insert(ModelWithIdAndName.Create(0))); var dictionary = dbCmd.GetDictionary <int, string>("SELECT Id, Name FROM ModelWIN"); Assert.That(dictionary, Has.Count.EqualTo(5)); //Console.Write(dictionary.Dump()); } }
public void Can_GetTimeToLive() { var model = ModelWithIdAndName.Create(1); string key = "model:" + model.CreateUrn(); cacheClient.Add(key, model); var ttl = cacheClient.GetTimeToLive(key); Assert.That(ttl, Is.EqualTo(TimeSpan.MaxValue)); cacheClient.Set(key, model, expiresIn: TimeSpan.FromSeconds(10)); ttl = cacheClient.GetTimeToLive(key); Assert.That(ttl.Value, Is.GreaterThanOrEqualTo(TimeSpan.FromSeconds(9))); Assert.That(ttl.Value, Is.LessThanOrEqualTo(TimeSpan.FromSeconds(10))); cacheClient.Remove(key); ttl = cacheClient.GetTimeToLive(key); Assert.That(ttl, Is.Null); }
public void Can_retrieve_AutoIdentityId_with_InsertOnly_fieldNames() { using (var db = OpenDbConnection()) { db.DropAndCreateTable <ModelWithIdAndName>(); var row1 = ModelWithIdAndName.Create(5); var row2 = ModelWithIdAndName.Create(6); var row1LastInsertId = db.InsertOnly(row1, new[] { "Id", "Name" }, selectIdentity: true); var row2LastInsertId = db.InsertOnly(row2, new[] { "Id", "Name" }, selectIdentity: true); var insertedRow1 = db.SingleById <ModelWithIdAndName>(row1LastInsertId); var insertedRow2 = db.SingleById <ModelWithIdAndName>(row2LastInsertId); Assert.That(insertedRow1.Name, Is.EqualTo(row1.Name)); Assert.That(insertedRow2.Name, Is.EqualTo(row2.Name)); } }
public void Can_retrieve_LastInsertId_from_inserted_table() { using (var db = OpenDbConnection()) { db.DropAndCreateTable <ModelWithIdAndName>(); var row1 = ModelWithIdAndName.Create(5); var row2 = ModelWithIdAndName.Create(6); var row1LastInsertId = db.Insert(row1, selectIdentity: true); var row2LastInsertId = db.Insert(row2, selectIdentity: true); var insertedRow1 = db.SingleById <ModelWithIdAndName>(row1LastInsertId); var insertedRow2 = db.SingleById <ModelWithIdAndName>(row2LastInsertId); Assert.That(insertedRow1.Name, Is.EqualTo(row1.Name)); Assert.That(insertedRow2.Name, Is.EqualTo(row2.Name)); } }
public void Can_select_IN_using_array_or_List_params() { using (var db = OpenDbConnection()) { db.DropAndCreateTable <ModelWithIdAndName>(); 5.Times(x => db.Insert(ModelWithIdAndName.Create(x))); var names = new[] { "Name2", "Name3" }; var rows = db.Select <ModelWithIdAndName>("Name IN (@names)", new { names }); Assert.That(rows.Count, Is.EqualTo(2)); Assert.That(rows.Map(x => x.Name), Is.EquivalentTo(names)); var ids = new List <int> { 2, 3 }; rows = db.Select <ModelWithIdAndName>("Id IN (@ids)", new { ids }); Assert.That(rows.Count, Is.EqualTo(2)); Assert.That(rows.Map(x => x.Id), Is.EquivalentTo(ids)); } }
public void Can_GetLookup() { const int n = 5; using (var db = OpenDbConnection()) { db.DropAndCreateTable <ModelWithIdAndName>(); n.Times(x => { var row = ModelWithIdAndName.Create(x); row.Name = x % 2 == 0 ? "OddGroup" : "EvenGroup"; db.Insert(row); }); var lookup = db.LookupFmt <string, int>("SELECT Name, Id FROM ModelWithIdAndName"); Assert.That(lookup, Has.Count.EqualTo(2)); Assert.That(lookup["OddGroup"], Has.Count.EqualTo(3)); Assert.That(lookup["EvenGroup"], Has.Count.EqualTo(2)); } }
public void Can_GetLookup() { const int n = 5; using (var db = OpenDbConnection()) { db.CreateTable <ModelWithIdAndName>(true); n.Times(x => { var row = ModelWithIdAndName.Create(x); row.Name = x % 2 == 0 ? "OddGroup" : "EvenGroup"; db.Insert(row); }); var lookup = db.Lookup <string, int>("SELECT \"name\", \"id\" FROM " + "ModelWithIdAndName".SqlTable(DialectProvider)); Assert.That(lookup, Has.Count.EqualTo(2)); Assert.That(lookup["OddGroup"], Has.Count.EqualTo(3)); Assert.That(lookup["EvenGroup"], Has.Count.EqualTo(2)); } }
public void Can_retrieve_LastInsertId_from_inserted_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithIdAndName>(true); var row1 = ModelWithIdAndName.Create(5); var row2 = ModelWithIdAndName.Create(6); db.Insert(row1); var row1LastInsertId = db.LastInsertId(); db.Insert(row2); var row2LastInsertId = db.LastInsertId(); var insertedRow1 = db.SingleById <ModelWithIdAndName>(row1LastInsertId); var insertedRow2 = db.SingleById <ModelWithIdAndName>(row2LastInsertId); Assert.That(insertedRow1.Name, Is.EqualTo(row1.Name)); Assert.That(insertedRow2.Name, Is.EqualTo(row2.Name)); } }