コード例 #1
0
        public void SaveAndQueryTest()
        {
            Database db = new SQLiteDatabase(nameof(SaveAndQueryTest));

            db.TryEnsureSchema <DaoReferenceObject>();

            DaoReferenceObject referenceObject = new DaoReferenceObject()
            {
                IntProperty       = 10,
                DecimalProperty   = 10,
                LongProperty      = 10,
                ULongProperty     = 10,
                DateTimeProperty  = Instant.Now,
                BoolProperty      = true,
                ByteArrayProperty = "This is the byte array property".ToBytes(),
                StringProperty    = "This is the string property"
            };

            referenceObject.Id.ShouldBeNull("Id should have been null");
            referenceObject.Save(db);
            string referenceJson = referenceObject.ToJsonSafe().ToJson();

            referenceObject.Id.ShouldNotBeNull("Id should not have been null");

            DaoReferenceObject retrievedById = DaoReferenceObject.OneWhere(c => c.Id == referenceObject.Id, db);

            retrievedById.ShouldNotBeNull("failed to retrieve object by id");
            Expect.AreEqual(retrievedById.ULongProperty, referenceObject.ULongProperty);
            Expect.AreEqual(referenceObject, retrievedById);
            Expect.AreEqual(referenceJson, retrievedById.ToJsonSafe().ToJson());

            Message.PrintLine(db.ConnectionString);
        }
コード例 #2
0
        public void PropertyTypeTest()
        {
            Expect.IsTrue(_testDatabases.Count > 0);
            string methodName = MethodBase.GetCurrentMethod().Name;

            _testDatabases.Each(db =>
            {
                Message.PrintLine("{0}.{1}: {2}", ConsoleColor.DarkYellow, this.GetType().Name, methodName, db.GetType().Name);
                DateTime utc           = DateTime.UtcNow;
                DaoReferenceObject obj = new DaoReferenceObject(db)
                {
                    IntProperty      = RandomNumber.Between(0, 100),
                    DecimalProperty  = 10.15m,
                    LongProperty     = 99999,
                    DateTimeProperty = utc,
                    BoolProperty     = true
                };
                string testName       = 16.RandomLetters();
                obj.ByteArrayProperty = new TestSerializable(testName).ToBinaryBytes();
                Instant now           = new Instant();
                obj.StringProperty    = now.ToString();

                obj.Save(db);

                DaoReferenceObject retrieved = DaoReferenceObject.OneWhere(c => c.Id == obj.Id, db);
                Expect.AreEqual(obj.Id, retrieved.Id, "Ids didn't match");
                Expect.AreEqual(obj.IntProperty, retrieved.IntProperty, "IntProperty didn't match");
                Expect.AreEqual(obj.DecimalProperty, retrieved.DecimalProperty, "DecimalProperty didn't match");
                Expect.AreEqual(obj.LongProperty, retrieved.LongProperty, "LongProperty didn't match");
                DateTime shouldBe = obj.DateTimeProperty.Value.DropMilliseconds();
                DateTime _is      = retrieved.DateTimeProperty.Value.DropMilliseconds();
                Expect.AreEqual(shouldBe, _is, "DateTimeProperty didn't match");
                Expect.AreEqual(obj.BoolProperty, retrieved.BoolProperty, "BoolProperty didn't match");
                Expect.AreEqual(obj.StringProperty, retrieved.StringProperty, "StringProperty didn't match");
                TestSerializable deserialized = obj.ByteArrayProperty.FromBinaryBytes <TestSerializable>();
                Expect.AreEqual(testName, deserialized.Name);
                Instant then = Instant.FromString(retrieved.StringProperty);
                Expect.AreEqual(now.ToDateTime(), then.ToDateTime());
            });
        }
コード例 #3
0
        public void CanQueryByUlongProperty()
        {
            Database db = new SQLiteDatabase(nameof(SaveAndQueryTest));

            db.TryEnsureSchema <DaoReferenceObject>();
            DaoReferenceObject.LoadAll(db).Delete(db);
            ulong testValue = 8374384738473847;

            DaoReferenceObject referenceObject = new DaoReferenceObject()
            {
                IntProperty       = 10,
                DecimalProperty   = 10,
                LongProperty      = 10,
                ULongProperty     = testValue,
                DateTimeProperty  = Instant.Now,
                BoolProperty      = true,
                ByteArrayProperty = "This is the byte array property".ToBytes(),
                StringProperty    = "This is the string property"
            };

            referenceObject.Id.ShouldBeNull("Id should have been null");
            referenceObject.Save(db);
            string referenceJson = referenceObject.ToJsonSafe().ToJson();

            referenceObject.Id.ShouldNotBeNull("Id should not have been null");

            DaoReferenceObject[] retrieved = DaoReferenceObject.Where(c => c.ULongProperty == testValue, db).ToArray();
            Expect.AreEqual(1, retrieved.Length);
            DaoReferenceObject instance = retrieved[0];

            Expect.AreEqual(instance.ULongProperty, referenceObject.ULongProperty);
            Expect.AreEqual(referenceObject, instance);
            Expect.AreEqual(referenceJson, instance.ToJsonSafe().ToJson());
            Expect.AreEqual(testValue, instance.ULongProperty);

            Message.PrintLine(db.ConnectionString);
        }