コード例 #1
0
        public void Populate_From_Nullable_Properties_With_Non_Default_Values()
        {
            var toObj   = ModelWithFieldsOfDifferentTypes.Create(1);
            var fromObj = ModelWithFieldsOfDifferentTypesAsNullables.Create(2);

            var originalToObj = ModelWithFieldsOfDifferentTypes.Create(1);

            fromObj.Name   = null;
            fromObj.Double = default(double);
            fromObj.Guid   = default(Guid);
            fromObj.Bool   = default(bool);

            toObj.PopulateWithNonDefaultValues(fromObj);

            Assert.That(toObj.Name, Is.EqualTo(originalToObj.Name));

            Assert.That(toObj.Double, Is.EqualTo(fromObj.Double));
            Assert.That(toObj.Guid, Is.EqualTo(fromObj.Guid));
            Assert.That(toObj.Bool, Is.EqualTo(fromObj.Bool));
            Assert.That(toObj.Id, Is.EqualTo(fromObj.Id));
            Assert.That(toObj.LongId, Is.EqualTo(fromObj.LongId));
            Assert.That(toObj.DateTime, Is.EqualTo(fromObj.DateTime));
        }
コード例 #2
0
        public void Can_Store_from_basic_persistence_provider()
        {
            using (var db = OpenDbConnection())
            {
                db.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

                var basicProvider = new OrmLitePersistenceProvider(db);

                var rowIds = new List <int> {
                    1, 2, 3, 4, 5
                };

                var rows = rowIds.ConvertAll(x => ModelWithFieldsOfDifferentTypes.Create(x));

                rows.ForEach(x => basicProvider.Store(x));

                var getRowIds      = new[] { 2, 4 };
                var providerRows   = db.SelectByIds <ModelWithFieldsOfDifferentTypes>(getRowIds).ToList();
                var providerRowIds = providerRows.ConvertAll(x => x.Id);

                Assert.That(providerRowIds, Is.EquivalentTo(getRowIds));
            }
        }
        public void Can_GetByIds_from_basic_persistence_provider()
        {
            using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open())
            {
                db.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

                var basicProvider = new OrmLitePersistenceProvider(db);

                var rowIds = new List <int> {
                    1, 2, 3, 4, 5
                };

                var rows = rowIds.ConvertAll(x => ModelWithFieldsOfDifferentTypes.Create(x));

                rows.ForEach(x => db.Insert(x));

                var getRowIds      = new[] { 2, 4 };
                var providerRows   = basicProvider.GetByIds <ModelWithFieldsOfDifferentTypes>(getRowIds).ToList();
                var providerRowIds = providerRows.ConvertAll(x => x.Id);

                Assert.That(providerRowIds, Is.EquivalentTo(getRowIds));
            }
        }
        public void Can_Delete_from_basic_persistence_provider()
        {
            using (var db = ConnectionString.OpenDbConnection())
            {
                db.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

                var basicProvider = new OrmLitePersistenceProvider(db);

                var rowIds = new List <int> {
                    1, 2, 3, 4, 5
                };

                var rows = rowIds.ConvertAll(x => ModelWithFieldsOfDifferentTypes.Create(x));

                rows.ForEach(x => db.Insert(x));

                var deleteRowIds = new List <int> {
                    2, 4
                };

                foreach (var row in rows)
                {
                    if (deleteRowIds.Contains(row.Id))
                    {
                        basicProvider.Delete(row);
                    }
                }

                var providerRows   = basicProvider.GetByIds <ModelWithFieldsOfDifferentTypes>(rowIds).ToList();
                var providerRowIds = providerRows.ConvertAll(x => x.Id);

                var remainingIds = new List <int>(rowIds);
                deleteRowIds.ForEach(x => remainingIds.Remove(x));

                Assert.That(providerRowIds, Is.EquivalentTo(remainingIds));
            }
        }
        public void Store_sets_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);
                }
        }
        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);
                }
        }
コード例 #7
0
        public void onBeforeTestFixture()
        {
            var results = 100.Times(x => ModelWithFieldsOfDifferentTypes.Create(x));

            testData = TypeSerializer.SerializeToString(results);
        }