public void Store_sets_and_updates_both_cache_and_db()
        {
            using (var db = ConnectionString.OpenDbConnection())
                using (var dbCmd = db.CreateCommand())
                {
                    dbCmd.CreateTable <ModelWithFieldsOfDifferentTypes>(false);

                    var cacheClient = new MemoryCacheClient();

                    var ormCache = new OrmLitePersistenceProviderCache(cacheClient, db);

                    var row = ModelWithFieldsOfDifferentTypes.Create(1);

                    ormCache.Store(row);

                    var cacheKey = row.CreateUrn();
                    var dbRow    = dbCmd.GetById <ModelWithFieldsOfDifferentTypes>(row.Id);
                    var cacheRow = cacheClient.Get <ModelWithFieldsOfDifferentTypes>(cacheKey);

                    ModelWithFieldsOfDifferentTypes.AssertIsEqual(dbRow, row);
                    ModelWithFieldsOfDifferentTypes.AssertIsEqual(cacheRow, row);

                    row.Name = "UpdatedName";
                    ormCache.Store(row);

                    dbRow    = dbCmd.GetById <ModelWithFieldsOfDifferentTypes>(row.Id);
                    cacheRow = cacheClient.Get <ModelWithFieldsOfDifferentTypes>(cacheKey);

                    ModelWithFieldsOfDifferentTypes.AssertIsEqual(dbRow, row);
                    ModelWithFieldsOfDifferentTypes.AssertIsEqual(cacheRow, row);
                }
        }
        public void Can_convert_ModelWithFieldsOfDifferentTypes()
        {
            var model   = ModelWithFieldsOfDifferentTypes.Create(1);
            var toModel = Serialize(model);

            ModelWithFieldsOfDifferentTypes.AssertIsEqual(toModel, model);
        }
        public void Clear_only_clears_cache()
        {
            using (var db = ConnectionString.OpenDbConnection())
                using (var dbCmd = db.CreateCommand())
                {
                    dbCmd.CreateTable <ModelWithFieldsOfDifferentTypes>(false);

                    var cacheClient = new MemoryCacheClient();

                    var ormCache = new OrmLitePersistenceProviderCache(cacheClient, db);

                    var row = ModelWithFieldsOfDifferentTypes.Create(1);

                    ormCache.Store(row);

                    var cacheKey = row.CreateUrn();

                    var dbRow    = dbCmd.GetById <ModelWithFieldsOfDifferentTypes>(row.Id);
                    var cacheRow = cacheClient.Get <ModelWithFieldsOfDifferentTypes>(cacheKey);

                    ModelWithFieldsOfDifferentTypes.AssertIsEqual(dbRow, row);
                    ModelWithFieldsOfDifferentTypes.AssertIsEqual(cacheRow, row);

                    ormCache.Clear <ModelWithFieldsOfDifferentTypes>(row.Id);

                    dbRow    = dbCmd.GetById <ModelWithFieldsOfDifferentTypes>(row.Id);
                    cacheRow = cacheClient.Get <ModelWithFieldsOfDifferentTypes>(cacheKey);

                    ModelWithFieldsOfDifferentTypes.AssertIsEqual(dbRow, row);
                    Assert.IsNull(cacheRow);
                }
        }
        public void Can_update_ModelWithFieldsOfDifferentTypes_table_with_filter()
        {
            var row = CreateModelWithFieldsOfDifferentTypes();

            row.Id = (int)db.Insert(row, selectIdentity: true);

            row.Name = "UpdatedName";

            db.Update(row, x => x.LongId <= row.LongId);

            var dbRow = db.SingleById <ModelWithFieldsOfDifferentTypes>(row.Id);

            ModelWithFieldsOfDifferentTypes.AssertIsEqual(dbRow, row);
        }
        public void Can_update_with_optional_string_params()
        {
            var row = CreateModelWithFieldsOfDifferentTypes();

            row.Id   = (int)db.Insert(row, selectIdentity: true);
            row.Name = "UpdatedName";

            db.UpdateFmt <ModelWithFieldsOfDifferentTypes>(set: "NAME = {0}".SqlFmt(row.Name), where : "LongId".SqlColumn() + " <= {0}".SqlFmt(row.LongId));

            var dbRow = db.SingleById <ModelWithFieldsOfDifferentTypes>(row.Id);

            Console.WriteLine(dbRow.Dump());
            ModelWithFieldsOfDifferentTypes.AssertIsEqual(dbRow, row);
        }
        public void Can_update_with_optional_string_params()
        {
            var row = CreateModelWithFieldsOfDifferentTypes();

            db.Insert(row);
            row.Name = "UpdatedName";

            db.Update <ModelWithFieldsOfDifferentTypes>(set: "NAME = {0}".SqlFormat(row.Name), where : "LongId <= {0}".SqlFormat(row.LongId));

            var dbRow = db.GetById <ModelWithFieldsOfDifferentTypes>(row.Id);

            Console.WriteLine(dbRow.Dump());
            ModelWithFieldsOfDifferentTypes.AssertIsEqual(dbRow, row);
        }
        public void Can_update_ModelWithFieldsOfDifferentTypes_table_with_filter()
        {
            var row = CreateModelWithFieldsOfDifferentTypes();

            db.Insert(row);

            row.Name = "UpdatedName";

            db.Update(row, x => x.LongId <= row.LongId);

            var dbRow = db.GetById <ModelWithFieldsOfDifferentTypes>(1);

            ModelWithFieldsOfDifferentTypes.AssertIsEqual(dbRow, row);
        }
        public void Can_update_ModelWithFieldsOfDifferentTypes_table()
        {
            var row = ModelWithFieldsOfDifferentTypes.Create(1);

            db.Insert(row);

            row.Name = "UpdatedName";

            db.Update(row);

            var dbRow = db.GetById <ModelWithFieldsOfDifferentTypes>(1);

            ModelWithFieldsOfDifferentTypes.AssertIsEqual(dbRow, row);
        }
Example #9
0
        public void Can_update_ModelWithFieldsOfDifferentTypes_table_with_commandFilter()
        {
            using var db = OpenDbConnection();
            var row = CreateModelWithFieldsOfDifferentTypes(db);

            row.Id = (int)db.Insert(row, selectIdentity: true);

            row.Name = "UpdatedName";

            db.Update(row, cmd => cmd.CommandText.Print());

            var dbRow = db.SingleById <ModelWithFieldsOfDifferentTypes>(row.Id);

            ModelWithFieldsOfDifferentTypes.AssertIsEqual(dbRow, row);
        }
        public void Can_Save_and_select_from_ModelWithFieldsOfDifferentTypes_table()
        {
            using var db = OpenDbConnection();
            db.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

            var row = ModelWithFieldsOfDifferentTypes.Create(1);

            db.Save(row);

            var rows = db.Select <ModelWithFieldsOfDifferentTypes>();

            Assert.That(rows, Has.Count.EqualTo(1));

            ModelWithFieldsOfDifferentTypes.AssertIsEqual(rows[0], row);
        }
        public void Can_update_with_anonymousType_and_expr_filter()
        {
            var row = CreateModelWithFieldsOfDifferentTypes();

            row.Id       = (int)db.Insert(row, selectIdentity: true);
            row.DateTime = DateTime.Now;
            row.Name     = "UpdatedName";

            db.Update <ModelWithFieldsOfDifferentTypes>(new { row.Name, row.DateTime },
                                                        x => x.LongId >= row.LongId && x.LongId <= row.LongId);

            var dbRow = db.SingleById <ModelWithFieldsOfDifferentTypes>(row.Id);

            Console.WriteLine(dbRow.Dump());
            ModelWithFieldsOfDifferentTypes.AssertIsEqual(dbRow, row);
        }
Example #12
0
        public void Can_insert_and_select_from_ModelWithFieldsOfDifferentTypes_table()
        {
            using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open())
            {
                db.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

                var row = ModelWithFieldsOfDifferentTypes.Create(1);

                db.Insert(row);

                var rows = db.Select <ModelWithFieldsOfDifferentTypes>();

                Assert.That(rows, Has.Count.EqualTo(1));

                ModelWithFieldsOfDifferentTypes.AssertIsEqual(rows[0], row);
            }
        }
Example #13
0
        public void Can_update_allColumns_ModelWithFieldsOfDifferentTypes_table_with_Implicit_Filter()
        {
            CreateModelWithFieldsOfDifferentTypes();
            using (var conn = OpenDbConnection())
            {
                var row = conn.Select <ModelWithFieldsOfDifferentTypes>(x => x.Id == 1).FirstOrDefault();
                row.Name = "UpdatedName";

                conn.Update(row);

                var dbRow = conn.Select <ModelWithFieldsOfDifferentTypes>(x => x.Id == 1).FirstOrDefault();

                ModelWithFieldsOfDifferentTypes.AssertIsEqual(dbRow, row);

                Assert.AreNotEqual(row.Name, OpenDbConnection().First <ModelWithFieldsOfDifferentTypes>(x => x.Id == 2).Name);
            }
        }
Example #14
0
        public void Can_GetById_from_basic_persistence_provider()
        {
            using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open())
            {
                db.DropAndCreateTable <ModelWithFieldsOfDifferentTypes>();

                //var basicProvider = new OrmLitePersistenceProvider(db);

                var row = ModelWithFieldsOfDifferentTypes.Create(1);

                db.Insert(row);

                var providerRow = db.SingleById <ModelWithFieldsOfDifferentTypes>(1);

                ModelWithFieldsOfDifferentTypes.AssertIsEqual(providerRow, row);
            }
        }
        public void Can_update_ModelWithFieldsOfDifferentTypes_table()
        {
            using (var db = OpenDbConnection())
            {
                var row = CreateModelWithFieldsOfDifferentTypes(db);

                row.Id = (int)db.Insert(row, selectIdentity: true);

                row.Name = "UpdatedName";

                db.Update(row);

                var dbRow = db.SingleById <ModelWithFieldsOfDifferentTypes>(row.Id);

                ModelWithFieldsOfDifferentTypes.AssertIsEqual(dbRow, row);
            }
        }
        public void Can_GetById_from_basic_persistence_provider()
        {
            using (var db = ConnectionString.OpenDbConnection())
            {
                db.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

                var basicProvider = new OrmLitePersistenceProvider(db);

                var row = ModelWithFieldsOfDifferentTypes.Create(1);

                db.Insert(row);

                var providerRow = basicProvider.GetById <ModelWithFieldsOfDifferentTypes>(1);

                ModelWithFieldsOfDifferentTypes.AssertIsEqual(providerRow, row);
            }
        }
        public void GetById_checks_cache_first_then_returns_if_found()
        {
            var mockCache = new Mock <ICacheClient>();

            var ormCache = new OrmLitePersistenceProviderCache(mockCache.Object, ConnectionString);

            var row = ModelWithFieldsOfDifferentTypes.Create(1);

            var cacheKey = row.CreateUrn();

            mockCache.Expect(x => x.Get <ModelWithFieldsOfDifferentTypes>(cacheKey))
            .Returns(row);

            var cacheRow = ormCache.GetById <ModelWithFieldsOfDifferentTypes>(row.Id);

            mockCache.VerifyAll();
            ModelWithFieldsOfDifferentTypes.AssertIsEqual(cacheRow, row);
        }
Example #18
0
        public void Can_Insert_ObjectDictionary_and_override_PrimaryKey()
        {
            using (var db = OpenDbConnection())
            {
                db.DropAndCreateTable <ModelWithFieldsOfDifferentTypes>();

                var row = ModelWithFieldsOfDifferentTypes.Create(0);
                row.Id = 100;
                var obj = row.ToObjectDictionary();

                var retId = (int)db.Insert <ModelWithFieldsOfDifferentTypes>(obj, selectIdentity: true);
                Assert.That(retId, Is.EqualTo(row.Id));

                var fromDb = db.SingleById <ModelWithFieldsOfDifferentTypes>(row.Id);

                ModelWithFieldsOfDifferentTypes.AssertIsEqual(fromDb, row);
            }
        }
Example #19
0
        public void Can_insert_and_select_from_ModelWithFieldsOfDifferentTypes_table()
        {
            using (var db = ConnectionString.OpenDbConnection())
                using (var dbConn = db.CreateCommand())
                {
                    dbConn.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

                    var row = ModelWithFieldsOfDifferentTypes.Create(1);

                    dbConn.Insert(row);

                    var rows = dbConn.Select <ModelWithFieldsOfDifferentTypes>();

                    Assert.That(rows, Has.Count.EqualTo(1));

                    ModelWithFieldsOfDifferentTypes.AssertIsEqual(rows[0], row);
                }
        }
Example #20
0
        public async Task Can_Insert_ObjectDictionary_Async()
        {
            using (var db = OpenDbConnection())
            {
                db.DropAndCreateTable <ModelWithFieldsOfDifferentTypes>();

                var row = ModelWithFieldsOfDifferentTypes.Create(0);
                var obj = row.ToObjectDictionary();
                obj.Remove(nameof(row.Id));

                row.Id = (int)await db.InsertAsync <ModelWithFieldsOfDifferentTypes>(obj, selectIdentity : true);

                Assert.That(row.Id, Is.Not.EqualTo(0));

                var fromDb = await db.SingleByIdAsync <ModelWithFieldsOfDifferentTypes>(row.Id);

                ModelWithFieldsOfDifferentTypes.AssertIsEqual(fromDb, row);
            }
        }
        public void Can_update_ModelWithFieldsOfDifferentTypes_table()
        {
            using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open())
            {
                db.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

                var row = ModelWithFieldsOfDifferentTypes.Create(1);

                db.Insert(row);

                row.Name = "UpdatedName";

                db.Update(row);

                var dbRow = db.GetById <ModelWithFieldsOfDifferentTypes>(1);

                ModelWithFieldsOfDifferentTypes.AssertIsEqual(dbRow, row);
            }
        }
Example #22
0
        public void Can_update_ModelWithFieldsOfDifferentTypes_table()
        {
            using (var db = ConnectionString.OpenDbConnection())
            {
                db.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

                var row = ModelWithFieldsOfDifferentTypes.Create(1);

                db.Insert(row);

                row.Name = "UpdatedName";

                db.Update(row);

                var dbRow = db.GetById <ModelWithFieldsOfDifferentTypes>(1);

                ModelWithFieldsOfDifferentTypes.AssertIsEqual(dbRow, row);
            }
        }
        public void GetById_checks_cache_first_then_gets_from_db()
        {
            using (var db = ConnectionString.OpenDbConnection())
                using (var dbCmd = db.CreateCommand())
                {
                    dbCmd.CreateTable <ModelWithFieldsOfDifferentTypes>(false);

                    var mockCache = new Mock <ICacheClient>();

                    var ormCache = new OrmLitePersistenceProviderCache(mockCache.Object, db);

                    var row = ModelWithFieldsOfDifferentTypes.Create(1);
                    dbCmd.Insert(row);

                    var cacheKey = row.CreateUrn();

                    mockCache.Expect(x => x.Get <ModelWithFieldsOfDifferentTypes>(cacheKey));

                    var dbRow = ormCache.GetById <ModelWithFieldsOfDifferentTypes>(row.Id);

                    mockCache.VerifyAll();
                    ModelWithFieldsOfDifferentTypes.AssertIsEqual(dbRow, row);
                }
        }