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); }
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; }); }
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))); }
private static T GetValue <T>(Undefinable <T> option) => option.GetValueOrDefault(default(T));
private static bool HasValue <T>(Undefinable <T> option) => option.IsDefined;
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)); }
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)); }
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)); }
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)); }