Пример #1
0
        public void Can_Save_into_ModelWithFieldsOfDifferentTypes_table()
        {
            using (var db = OpenDbConnection())
            {
                db.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

                var row = ModelWithFieldsOfDifferentTypes.Create(1);

                db.Save(row);
            }
        }
Пример #2
0
        public void Populate_Different_Objects_with_different_property_types()
        {
            var toObj   = ModelWithFieldsOfDifferentTypes.Create(1);
            var fromObj = ModelWithOnlyStringFields.Create("2");

            var obj3 = ReflectionUtils.PopulateObject(toObj, fromObj);

            Assert.IsTrue(obj3 == toObj);
            Assert.That(obj3.Id, Is.EqualTo(2));
            Assert.That(obj3.Name, Is.EqualTo(fromObj.Name));
        }
Пример #3
0
        public void Can_insert_into_ModelWithFieldsOfDifferentTypes_table()
        {
            using (var db = ConnectionString.OpenDbConnection())
            {
                db.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

                var row = ModelWithFieldsOfDifferentTypes.Create(1);

                db.Insert(row);
            }
        }
Пример #4
0
        public void Can_insert_into_ModelWithFieldsOfDifferentTypes_table()
        {
            using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open())
            {
                db.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

                var row = ModelWithFieldsOfDifferentTypes.Create(1);

                db.Insert(row);
            }
        }
Пример #5
0
        /// <summary>Creates model with fields of different types.</summary>
        /// <returns>The new model with fields of different types.</returns>
        private void CreateModelWithFieldsOfDifferentTypes(int count = 10)
        {
            using (var conn = OpenDbConnection())
            {
                conn.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

                for (int i = 0; i < count; i++)
                {
                    conn.Insert(ModelWithFieldsOfDifferentTypes.Create(i));
                }
            }
        }
        public void Caches_results_as_string()
        {
            var dto         = ModelWithFieldsOfDifferentTypes.Create(1);
            var expectedXml = JsonDataContractSerializer.Instance.SerializeToString(dto);

            var cacheManager = new JsonCacheManager(CreateCacheClient());

            var cacheKey = dto.CreateUrn();
            var dtoXml   = cacheManager.ResolveText(cacheKey, () => dto);

            Assert.That(dtoXml, Is.EqualTo(expectedXml));
        }
Пример #7
0
        public void Can_delete_ModelWithFieldsOfDifferentTypes_table_with_filter()
        {
            var row = ModelWithFieldsOfDifferentTypes.Create(1);

            db.Insert(row);

            db.Delete <ModelWithFieldsOfDifferentTypes>(x => x.Long <= row.Long);

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

            Assert.That(dbRow, Is.Null);
        }
        public void Can_delete_with_optional_string_params()
        {
            var row = ModelWithFieldsOfDifferentTypes.Create(1);

            db.Insert(row);

            db.Delete <ModelWithFieldsOfDifferentTypes>(where : "LongId <= {0}".SqlFormat(row.LongId));

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

            Assert.That(dbRow, Is.Null);
        }
Пример #9
0
        public void Can_delete_with_tableName_and_optional_string_params()
        {
            var row = ModelWithFieldsOfDifferentTypes.Create(1);

            db.Insert(row);

            db.DeleteFmt(table: "ModelWithFieldsOfDifferentTypes", where : "LongId".SqlColumn() + " <= {0}".SqlFmt(row.LongId));

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

            Assert.That(dbRow, Is.Null);
        }
        public void Can_DeleteById_from_ModelWithFieldsOfDifferentTypes_table()
        {
            var rowIds = new List <int>(new[] { 1, 2, 3 });

            rowIds.ForEach(x => db.Insert(ModelWithFieldsOfDifferentTypes.Create(x)));

            db.DeleteById <ModelWithFieldsOfDifferentTypes>(2);

            var rows     = db.GetByIds <ModelWithFieldsOfDifferentTypes>(rowIds);
            var dbRowIds = rows.ConvertAll(x => x.Id);

            Assert.That(dbRowIds, Is.EquivalentTo(new[] { 1, 3 }));
        }
        public void Can_convert_ModelWithFieldsOfDifferentTypes_to_object_Dictionary()
        {
            var model            = ModelWithFieldsOfDifferentTypes.Create(1);
            var modelString      = TypeSerializer.SerializeToString(model);
            var translateToModel = TypeSerializer.DeserializeFromString <Dictionary <string, object> >(modelString);

            Assert.That(translateToModel["Id"], Is.EqualTo(model.Id.ToString()));
            Assert.That(translateToModel["Bool"], Is.EqualTo(model.Bool.ToString()));
            Assert.That(translateToModel["DateTime"], Is.EqualTo(DateTimeSerializer.ToShortestXsdDateTimeString(model.DateTime)));
            Assert.That(translateToModel["Double"], Is.EqualTo(model.Double.ToString(CultureInfo.InvariantCulture)));
            Assert.That(translateToModel["Guid"], Is.EqualTo(model.Guid.ToString("N")));
            Assert.That(translateToModel["LongId"], Is.EqualTo(model.LongId.ToString()));
            Assert.That(translateToModel["Name"], Is.EqualTo(model.Name));
        }
        public void Can_update_ModelWithFieldsOfDifferentTypes_table_with_filter()
        {
            var row = ModelWithFieldsOfDifferentTypes.Create(1);

            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_with_optional_string_params()
        {
            var row = ModelWithFieldsOfDifferentTypes.Create(1);

            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);
        }
Пример #14
0
        public void Can_GetById_int_from_ModelWithFieldsOfDifferentTypes_table()
        {
            using (var db = OpenDbConnection())
            {
                db.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

                var rowIds = new List <int>(new[] { 1, 2, 3 });

                rowIds.ForEach(x => db.Insert(ModelWithFieldsOfDifferentTypes.Create(x)));

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

                Assert.That(row.Id, Is.EqualTo(1));
            }
        }
Пример #15
0
        public void Can_GetById_int_from_ModelWithFieldsOfDifferentTypes_table()
        {
            using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open())
            {
                db.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

                var rowIds = new List <int>(new[] { 1, 2, 3 });

                rowIds.ForEach(x => db.Insert(ModelWithFieldsOfDifferentTypes.Create(x)));

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

                Assert.That(row.Id, Is.EqualTo(1));
            }
        }
        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);
        }
Пример #17
0
        public void Can_DeleteById_from_ModelWithFieldsOfDifferentTypes_table()
        {
            var rowIds = new List <int>(new[] { 1, 2, 3 });

            for (var i = 0; i < rowIds.Count; i++)
            {
                rowIds[i] = (int)db.Insert(ModelWithFieldsOfDifferentTypes.Create(rowIds[i]), selectIdentity: true);
            }

            db.DeleteById <ModelWithFieldsOfDifferentTypes>(rowIds[1]);

            var rows     = db.SelectByIds <ModelWithFieldsOfDifferentTypes>(rowIds);
            var dbRowIds = rows.ConvertAll(x => x.Id);

            Assert.That(dbRowIds, Is.EquivalentTo(new[] { rowIds[0], rowIds[2] }));
        }
        public void Can_SaveAll_and_select_from_ModelWithFieldsOfDifferentTypes_table_with_no_ids()
        {
            using var db = OpenDbConnection();
            db.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

            var rowIds = new List <int> {
                1, 2, 3, 4, 5
            };
            var newRows = rowIds.ConvertAll(x => ModelWithFieldsOfDifferentTypes.Create(default(int)));

            db.SaveAll(newRows);

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

            Assert.That(rows, Has.Count.EqualTo(newRows.Count));
        }
Пример #19
0
        public void Can_GetByIds_int_from_ModelWithFieldsOfDifferentTypes_table()
        {
            using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open())
            {
                db.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

                var rowIds = new List <int>(new[] { 1, 2, 3 });

                rowIds.ForEach(x => db.Insert(ModelWithFieldsOfDifferentTypes.Create(x)));

                var rows     = db.SelectByIds <ModelWithFieldsOfDifferentTypes>(rowIds);
                var dbRowIds = rows.ConvertAll(x => x.Id);

                Assert.That(dbRowIds, Is.EquivalentTo(rowIds));
            }
        }
Пример #20
0
        public void Populate_Same_Objects()
        {
            var toObj   = ModelWithFieldsOfDifferentTypes.Create(1);
            var fromObj = ModelWithFieldsOfDifferentTypes.Create(2);

            var obj3 = AutoMappingUtils.PopulateWith(toObj, fromObj);

            Assert.IsTrue(obj3 == toObj);
            Assert.That(obj3.Bool, Is.EqualTo(fromObj.Bool));
            Assert.That(obj3.DateTime, Is.EqualTo(fromObj.DateTime));
            Assert.That(obj3.Double, Is.EqualTo(fromObj.Double));
            Assert.That(obj3.Guid, Is.EqualTo(fromObj.Guid));
            Assert.That(obj3.Id, Is.EqualTo(fromObj.Id));
            Assert.That(obj3.LongId, Is.EqualTo(fromObj.LongId));
            Assert.That(obj3.Name, Is.EqualTo(fromObj.Name));
        }
Пример #21
0
        public void ICSharp_can_gzip_and_gunzip()
        {
            const int sizeWhenDoesntWork = 6;

            var dto = ModelWithFieldsOfDifferentTypes.Create(1);

            var dtoXml = DataContractSerializer.Instance.Parse(dto);

            var zipXml = dtoXml.GZip();

            Assert.That(zipXml.Length, Is.GreaterThan(sizeWhenDoesntWork));

            var unzipXml = zipXml.GUnzip();

            Assert.That(unzipXml, Is.EqualTo(dtoXml));
        }
        public void Can_GetByIds_int_from_ModelWithFieldsOfDifferentTypes_table()
        {
            using (var db = OpenDbConnection())
            {
                db.DropAndCreateTable <ModelWithFieldsOfDifferentTypes>();

                var rowIds = new List <int>(new[] { 1, 2, 3 });

                rowIds.ForEach(x => db.Insert(ModelWithFieldsOfDifferentTypes.Create(x)));

                var rows     = db.SelectByIds <ModelWithFieldsOfDifferentTypes>(rowIds);
                var dbRowIds = rows.ConvertAll(x => x.Id);

                Assert.That(dbRowIds, Is.EquivalentTo(rowIds));
            }
        }
Пример #23
0
        public void Can_Select_Into_ModelWithIdAndName_from_ModelWithFieldsOfDifferentTypes_table()
        {
            using (var db = OpenDbConnection())
            {
                db.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

                var rowIds = new List <int>(new[] { 1, 2, 3 });

                rowIds.ForEach(x => db.Insert(ModelWithFieldsOfDifferentTypes.Create(x)));

                var rows     = db.Select <ModelWithIdAndName>(typeof(ModelWithFieldsOfDifferentTypes));
                var dbRowIds = rows.ConvertAll(x => x.Id);

                Assert.That(dbRowIds, Is.EquivalentTo(rowIds));
            }
        }
        public void Can_Select_subset_ModelWithIdAndName_from_ModelWithFieldsOfDifferentTypes_table()
        {
            using (var db = OpenDbConnection())
            {
                db.DropAndCreateTable <ModelWithFieldsOfDifferentTypes>();

                var rowIds = new List <int>(new[] { 1, 2, 3 });

                rowIds.ForEach(x => db.Insert(ModelWithFieldsOfDifferentTypes.Create(x)));

                var rows     = db.SelectFmt <ModelWithIdAndName>("SELECT Id, Name FROM ModelWithFieldsOfDifferentTypes");
                var dbRowIds = rows.ConvertAll(x => x.Id);

                Assert.That(dbRowIds, Is.EquivalentTo(rowIds));
            }
        }
        public void Can_update_with_anonymousType_and_expr_filter()
        {
            var row = ModelWithFieldsOfDifferentTypes.Create(1);

            db.Insert(row);
            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.GetById <ModelWithFieldsOfDifferentTypes>(row.Id);

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

                var rowIds = new List <int>(new[] { 1, 2, 3 });

                rowIds.ForEach(x => db.Insert(ModelWithFieldsOfDifferentTypes.Create(x)));

                var rows     = db.Select <ModelWithIdAndName>("SELECT \"Id\", \"Name\" FROM \"ModelWithFieldsOfDifferentTypes\"");
                var dbRowIds = rows.ConvertAll(x => x.Id);

                Assert.That(dbRowIds, Is.EquivalentTo(rowIds));
            }
        }
        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);
            }
        }
Пример #28
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);
            }
        }
Пример #29
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);
            }
        }
Пример #30
0
        public void Can_delete_all_rows()
        {
            var row1 = ModelWithFieldsOfDifferentTypes.Create(1);
            var row2 = ModelWithFieldsOfDifferentTypes.Create(2);
            var row3 = ModelWithFieldsOfDifferentTypes.Create(3);

            db.Save(row1);
            db.Save(row2);
            db.Save(row3);

            db.DeleteAll(new[] { row1, row3 });

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

            Assert.That(remaining.Count, Is.EqualTo(1));
            Assert.That(remaining[0].Id, Is.EqualTo(row2.Id));
        }