Пример #1
0
        public void Just()
        {
            var             a     = new object();
            IMaybe <object> justA = Maybe.Just(a);

            Assert.That(justA.Exists, Is.True);
            Assert.That(a, Is.SameAs(justA.Value));

            Assert.That(Maybe.Of(a), Is.EqualTo(justA));
            Assert.That(justA.Equals(null), Is.False);
            Assert.That(Maybe.Just(a), Is.EqualTo(justA));
            Assert.That(Maybe.Just("b"), Is.Not.EqualTo(justA));
            Assert.That(Maybe.Just <object>("b"), Is.Not.EqualTo(justA));
            Assert.That(Maybe.Nothing <string>(), Is.Not.EqualTo(justA));
            Assert.True(justA.Equals(justA));

            Assert.That(Maybe.Just("a").ToString(), Is.EqualTo("Just(a)"));

            Assert.That(justA.GetHashCode(), Is.EqualTo(justA.Value.GetHashCode()));

            Assert.That(justA.GetOrElse(new object()), Is.SameAs(a));

            bool called = false;

            justA.GetOrElseGet(() =>
            {
                called = true;
                return(new object());
            });
            Assert.That(called, Is.False);
        }