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); }
private RealmValueObject PersistAndFind(RealmValue rv) { _realm.Write(() => { _realm.Add(new RealmValueObject { RealmValueProperty = rv }); }); return(_realm.All <RealmValueObject>().First()); }
public void RealmValueTests(RealmValue rv) { dynamic ato = null; _realm.Write(() => { ato = _realm.DynamicApi.CreateObject("AllTypesObject", null); ato.RealmValueProperty = rv; }); Assert.That((RealmValue)ato.RealmValueProperty, Is.EqualTo(rv)); }
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); }
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>()); }
public void DataTests(byte[] value, bool isManaged) { RealmValue rv = value; if (isManaged) { var retrievedObject = PersistAndFind(rv); rv = retrievedObject.RealmValueProperty; } Assert.That(rv.Type, Is.EqualTo(RealmValueType.Data)); Assert.That((byte[])rv, Is.EqualTo(value)); Assert.That(rv.As <byte[]>(), Is.EqualTo(value)); Assert.That(rv.AsData(), Is.EqualTo(value)); Assert.That(rv != RealmValue.Null); }
public void ObjectTests(RealmObjectBase value, bool isManaged) { RealmValue rv = value; if (isManaged) { var retrievedObject = PersistAndFind(rv); rv = retrievedObject.RealmValueProperty; } Assert.That(rv.Type, Is.EqualTo(RealmValueType.Object)); Assert.That((RealmObjectBase)rv, Is.EqualTo(value)); Assert.That(rv.As <RealmObjectBase>(), Is.EqualTo(value)); Assert.That(rv.AsRealmObject(), Is.EqualTo(value)); Assert.That(rv != RealmValue.Null); }
public void RealmValueTests_WithObject() { dynamic ato = null; RealmValue rv = RealmValue.Null; _realm.Write(() => { var intObject = _realm.DynamicApi.CreateObject("IntPropertyObject", ObjectId.GenerateNewId()); intObject.Int = 10; rv = intObject; ato = _realm.DynamicApi.CreateObject("AllTypesObject", null); ato.RealmValueProperty = rv; }); Assert.That((RealmValue)ato.RealmValueProperty, Is.EqualTo(rv)); }
public void StringTests(string 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.String)); Assert.That((string)rv == value); Assert.That(rv.As <string>() == value); Assert.That(rv.AsString() == value); Assert.That(rv != RealmValue.Null); }
public static IEnumerable <object> RealmValueTestValues() { yield return(new RealmValue[] { RealmValue.Null, RealmValue.Create(10, RealmValueType.Int), RealmValue.Create(true, RealmValueType.Bool), RealmValue.Create("abc", RealmValueType.String), RealmValue.Create(new byte[] { 0, 1, 2 }, RealmValueType.Data), RealmValue.Create(DateTimeOffset.FromUnixTimeSeconds(1616137641), RealmValueType.Date), RealmValue.Create(1.5f, RealmValueType.Float), RealmValue.Create(2.5d, RealmValueType.Double), RealmValue.Create(5m, RealmValueType.Decimal128), RealmValue.Create(new ObjectId("5f63e882536de46d71877979"), RealmValueType.ObjectId), RealmValue.Create(new Guid("{F2952191-A847-41C3-8362-497F92CB7D24}"), RealmValueType.Guid), RealmValue.Create(new IntPropertyObject { Int = 10 }, RealmValueType.Object) }); }
public void RealmValue_WhenManaged_ObjectGetsPersisted() { var value = new InternalObject { IntProperty = 10, StringProperty = "brown" }; RealmValue rv = value; _realm.Write(() => { _realm.Add(new RealmValueObject { RealmValueProperty = rv }); }); var objs = _realm.All <InternalObject>().ToList(); Assert.That(objs.Count, Is.EqualTo(1)); Assert.That(objs[0], Is.EqualTo(value)); }
public void FloatTests(float 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.Float)); Assert.That((float)rv == value); Assert.That(rv.As <float>() == value); Assert.That((float?)rv == value); Assert.That(rv.As <float?>() == value); Assert.That(rv.AsFloat() == value); Assert.That(rv.AsNullableFloat() == value); Assert.That(rv != RealmValue.Null); }
public void DoubleTests(double 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.Double)); Assert.That((double)rv == value); Assert.That(rv.As <double>() == value); Assert.That((double?)rv == value); Assert.That(rv.As <double?>() == value); Assert.That(rv.AsDouble() == value); Assert.That(rv.AsNullableDouble() == value); Assert.That(rv != RealmValue.Null); }
public void RealmValue_WhenRealmInteger_Increments() { RealmValue rv = 10; var retrievedObject = PersistAndFind(rv); Assert.That(retrievedObject.RealmValueProperty.AsInt32() == 10); _realm.Write(() => { retrievedObject.RealmValueProperty.AsInt32RealmInteger().Increment(); }); Assert.That(retrievedObject.RealmValueProperty.AsInt32() == 11); _realm.Write(() => { retrievedObject.RealmValueProperty.AsInt32RealmInteger().Decrement(); }); Assert.That(retrievedObject.RealmValueProperty.AsInt32() == 10); }
public void DecimalTests(decimal 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.Decimal128)); Assert.That((decimal)rv == value); Assert.That(rv.As <decimal>() == value); Assert.That((decimal?)rv == value); Assert.That(rv.As <decimal?>() == value); Assert.That(rv.AsDecimal() == value); Assert.That(rv.AsNullableDecimal() == value); Assert.That(rv != RealmValue.Null); }
public void BoolTests(bool 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.Bool)); Assert.That((bool)rv == value); Assert.That(rv.As <bool>() == value); Assert.That((bool?)rv == value); Assert.That(rv.As <bool?>() == value); Assert.That(rv.AsBool() == value); Assert.That(rv.AsNullableBool() == value); Assert.That(rv != RealmValue.Null); }
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); }
public void DateTests(DateTimeOffset 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.Date)); Assert.That((DateTimeOffset)rv == value); Assert.That(rv.As <DateTimeOffset>() == value); Assert.That((DateTimeOffset?)rv == value); Assert.That(rv.As <DateTimeOffset?>() == value); Assert.That(rv.AsDate() == value); Assert.That(rv.AsNullableDate() == value); Assert.That(rv != RealmValue.Null); }