Пример #1
0
        public void NullableRealmInteger_HasDefaultValue(int?defaultValue)
        {
            var byteValue = defaultValue.HasValue ? (byte?)Math.Max(defaultValue.Value, 0) : null;

            var counter = new CounterObject
            {
                NullableByteProperty  = byteValue,
                NullableInt16Property = (short?)defaultValue,
                NullableInt32Property = defaultValue,
                NullableInt64Property = defaultValue,
            };

            Assert.That(counter.NullableByteProperty == byteValue);
            Assert.That(counter.NullableInt16Property == defaultValue);
            Assert.That(counter.NullableInt32Property == defaultValue);
            Assert.That(counter.NullableInt64Property == defaultValue);

            _realm.Write(() =>
            {
                _realm.Add(counter);
            });

            Assert.That(counter.NullableByteProperty == byteValue);
            Assert.That(counter.NullableInt16Property == defaultValue);
            Assert.That(counter.NullableInt32Property == defaultValue);
            Assert.That(counter.NullableInt64Property == defaultValue);
        }
Пример #2
0
        public void RealmInteger_HasDefaultValue(int defaultValue)
        {
            var byteValue = (byte)Math.Max(defaultValue, 0);

            var counter = new CounterObject
            {
                ByteProperty  = byteValue,
                Int16Property = (short)defaultValue,
                Int32Property = defaultValue,
                Int64Property = defaultValue,
            };

            Assert.That(counter.ByteProperty == byteValue);
            Assert.That(counter.Int16Property == defaultValue);
            Assert.That(counter.Int32Property == defaultValue);
            Assert.That(counter.Int64Property == defaultValue);

            _realm.Write(() =>
            {
                _realm.Add(counter);
            });

            Assert.That(counter.ByteProperty == byteValue);
            Assert.That(counter.Int16Property == defaultValue);
            Assert.That(counter.Int32Property == defaultValue);
            Assert.That(counter.Int64Property == defaultValue);
        }
        private void AddCounterObjects(out CounterObject zeros, out CounterObject ones)
        {
            var counter0 = new CounterObject
            {
                Id = 0
            };

            var counter1 = new CounterObject
            {
                Id                    = 1,
                ByteProperty          = 1,
                Int16Property         = 1,
                Int32Property         = 1,
                Int64Property         = 1,
                NullableByteProperty  = 1,
                NullableInt16Property = 1,
                NullableInt32Property = 1,
                NullableInt64Property = 1
            };

            _realm.Write(() =>
            {
                _realm.Add(counter0);
                _realm.Add(counter1);
            });

            zeros = counter0;
            ones  = counter1;
        }
Пример #4
0
        public void RealmInteger_WhenByte_IncrementTests(byte original, byte value, bool managed)
        {
            var counter = new CounterObject
            {
                ByteProperty = original,
            };

            var sum = (byte)(original + value);

            if (managed)
            {
                _realm.Write(() => _realm.Add(counter));
                _realm.Write(() => counter.ByteProperty.Increment(value));
                Assert.That((byte)counter.ByteProperty, Is.EqualTo(sum));
            }
            else
            {
                Assert.That(() => counter.ByteProperty.Increment(value), Throws.TypeOf <NotSupportedException>());
            }
        }
Пример #5
0
        public void RealmInteger_WhenLong_IncrementTests(long original, long value, bool managed)
        {
            var counter = new CounterObject
            {
                Int64Property = original,
            };

            var sum = original + value;

            if (managed)
            {
                _realm.Write(() => _realm.Add(counter));
                _realm.Write(() => counter.Int64Property.Increment(value));
                Assert.That((long)counter.Int64Property, Is.EqualTo(sum));
            }
            else
            {
                Assert.That(() => counter.Int64Property.Increment(value), Throws.TypeOf <NotSupportedException>());
            }
        }