Exemple #1
0
        public void RunNumericTests(RealmValue rv, long value, bool isManaged)
        {
            if (isManaged)
            {
                var retrievedObject = PersistAndFind(rv);
                rv = retrievedObject.RealmValueProperty;
            }

            Assert.That(rv == value);
            Assert.That(rv.Type, Is.EqualTo(RealmValueType.Int));
            Assert.That(rv != RealmValue.Null);

            // 8 - byte
            var byteValue = (byte)value;

            Assert.That((byte)rv == byteValue);
            Assert.That(rv.As <byte>() == byteValue);
            Assert.That((byte?)rv == byteValue);
            Assert.That(rv.As <byte?>() == byteValue);
            Assert.That(rv.AsByte() == byteValue);
            Assert.That(rv.AsNullableByte() == byteValue);
            Assert.That(rv.AsByteRealmInteger() == byteValue);
            Assert.That(rv.AsNullableByteRealmInteger() == byteValue);

            // 16 - short
            var shortValue = (short)value;

            Assert.That((short)rv == shortValue);
            Assert.That(rv.As <short>() == shortValue);
            Assert.That((short?)rv == shortValue);
            Assert.That(rv.As <short?>() == shortValue);
            Assert.That(rv.AsInt16() == shortValue);
            Assert.That(rv.AsNullableInt16() == shortValue);
            Assert.That(rv.AsInt16RealmInteger() == shortValue);
            Assert.That(rv.AsNullableInt16RealmInteger() == shortValue);

            // 32 - int
            var intValue = (int)value;

            Assert.That((int)rv == intValue);
            Assert.That(rv.As <int>() == intValue);
            Assert.That((int?)rv == intValue);
            Assert.That(rv.As <int?>() == intValue);
            Assert.That(rv.AsInt32() == intValue);
            Assert.That(rv.AsNullableInt32() == intValue);
            Assert.That(rv.AsInt32RealmInteger() == intValue);
            Assert.That(rv.AsNullableInt32RealmInteger() == intValue);

            // 64 - long
            Assert.That((long)rv == value);
            Assert.That(rv.As <long>() == value);
            Assert.That((long?)rv == value);
            Assert.That(rv.As <long?>() == value);
            Assert.That(rv.AsInt64() == value);
            Assert.That(rv.AsNullableInt64() == value);
            Assert.That(rv.AsInt64RealmInteger() == value);
            Assert.That(rv.AsNullableInt64RealmInteger() == value);
        }
Exemple #2
0
        public void NullTests(bool isManaged)
        {
            RealmValue rv = RealmValue.Null;

            if (isManaged)
            {
                var retrievedObject = PersistAndFind(rv);
                rv = retrievedObject.RealmValueProperty;
            }

            Assert.That(rv == RealmValue.Null);
            Assert.That(rv.Type, Is.EqualTo(RealmValueType.Null));

            Assert.That(rv.AsNullableBool() == null);
            Assert.That(rv.AsNullableChar() == null);
            Assert.That(rv.AsNullableDate() == null);
            Assert.That(rv.AsNullableDecimal() == null);
            Assert.That(rv.AsNullableDecimal128() == null);
            Assert.That(rv.AsNullableDouble() == null);
            Assert.That(rv.AsNullableFloat() == null);
            Assert.That(rv.AsNullableGuid() == null);
            Assert.That(rv.AsNullableObjectId() == null);
            Assert.That(rv.AsNullableByte() == null);
            Assert.That(rv.AsNullableByteRealmInteger() == null);
            Assert.That(rv.AsNullableInt16() == null);
            Assert.That(rv.AsNullableInt16RealmInteger() == null);
            Assert.That(rv.AsNullableInt32() == null);
            Assert.That(rv.AsNullableInt32RealmInteger() == null);
            Assert.That(rv.AsNullableInt64() == null);
            Assert.That(rv.AsNullableInt64RealmInteger() == null);

            Assert.That((bool?)rv == null);
            Assert.That((DateTimeOffset?)rv == null);
            Assert.That((decimal?)rv == null);
            Assert.That((Decimal128?)rv == null);
            Assert.That((double?)rv == null);
            Assert.That((float?)rv == null);
            Assert.That((Guid?)rv == null);
            Assert.That((ObjectId?)rv == null);
            Assert.That((byte?)rv == null);
            Assert.That((RealmInteger <byte>?)rv == null);
            Assert.That((short?)rv == null);
            Assert.That((RealmInteger <short>?)rv == null);
            Assert.That((int?)rv == null);
            Assert.That((RealmInteger <int>?)rv == null);
            Assert.That((long?)rv == null);
            Assert.That((RealmInteger <long>?)rv == null);
        }