Example #1
0
        public void Undefinable_nullable_int_that_is_empty_is_defined()
        {
            Undefinable <int?> i = null;

            Assert.That(i.IsDefined, Is.True);
            Assert.That(i.Value, Is.Null);
        }
Example #2
0
        public void Undefined_int_that_is_undefined_resolves_undefined_values_correctly()
        {
            Undefinable <int> i = default;

            Assert.That(i.IsDefined, Is.False);
            Assert.Throws <InvalidOperationException>(() => { var a = i.Value; });
        }
Example #3
0
        public void Undefinable_nullable_int_with_a_value_resolves_equality_correctly()
        {
            Undefinable <int?> i = 10;

            Assert.That(i.IsDefined, Is.True);
            Assert.That(i.Value, Is.EqualTo(10));
            Assert.That(10, Is.EqualTo(i));
            Assert.That(i, Is.EqualTo(new Undefinable <int?>(10)));
            Assert.That(i, Is.EqualTo(new Undefinable <int>(10)));
        }
Example #4
0
 private static T GetValue <T>(Undefinable <T> option) => option.GetValueOrDefault(default(T));
Example #5
0
 private static bool HasValue <T>(Undefinable <T> option) => option.IsDefined;
Example #6
0
 public void TestNullableInequality(Undefinable <int?> a, Undefinable <int?> b, bool expected)
 {
     Assert.That(a != b, Is.EqualTo(!expected));
     Assert.That(b != a, Is.EqualTo(!expected));
 }
Example #7
0
 public void TestNullableEquality(Undefinable <int?> a, Undefinable <int?> b, bool expected)
 {
     Assert.That(a == b, Is.EqualTo(expected));
     Assert.That(b == a, Is.EqualTo(expected));
 }
Example #8
0
 public void TestNullableAndNonNullableEquality(Undefinable <int?> a, Undefinable <int> b, bool expected)
 {
     //only .Equals is supported for now
     Assert.That(a.Equals(b), Is.EqualTo(expected));
     Assert.That(b.Equals(a), Is.EqualTo(expected));
 }
Example #9
0
        public void TestUndefinedSerializationUsingNullables(Undefinable <int?> a, Undefinable <int?> b, String expectedJson)
        {
            var json = JsonConvert.SerializeObject(new { A = a, B = b }, settings);

            Assert.That(json, Is.EqualTo(expectedJson));
        }