Example #1
0
        public void RealmValue_WhenCastingIsWrong_ThrowsException()
        {
            RealmValue rv = 10;

            Assert.That(() => rv.AsString(), Throws.Exception.TypeOf <InvalidCastException>());
            Assert.That(() => rv.AsFloat(), Throws.Exception.TypeOf <InvalidCastException>());

            rv = Guid.NewGuid().ToString();

            Assert.That(() => rv.AsInt16(), Throws.Exception.TypeOf <InvalidCastException>());
            Assert.That(() => rv.AsGuid(), Throws.Exception.TypeOf <InvalidCastException>());

            rv = true;

            Assert.That(() => rv.AsInt16(), Throws.Exception.TypeOf <InvalidCastException>());
        }
Example #2
0
        public void GuidTests(Guid value, bool isManaged)
        {
            RealmValue rv = value;

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

            Assert.That(rv == value);
            Assert.That(rv.Type, Is.EqualTo(RealmValueType.Guid));

            Assert.That((Guid)rv == value);
            Assert.That(rv.As <Guid>() == value);
            Assert.That((Guid?)rv == value);
            Assert.That(rv.As <Guid?>() == value);
            Assert.That(rv.AsGuid() == value);
            Assert.That(rv.AsNullableGuid() == value);
            Assert.That(rv != RealmValue.Null);
        }