Пример #1
0
        public void Map()
        {
            Nullable <int> n  = 2;
            Nullable <int> n0 = null;

            Assert.Throws <ArgumentNullException>(() => NullableExtensions.Map <int, int>(n, null));

            Func <int, int> selector = i => i * 2;

            Assert.True(n.Map(selector).HasValue);
            Assert.Equal(4, n.Map(selector).Value);
            Assert.False(n0.Map(selector).HasValue);

            // selector not called
            Assert.False(n0.Map(new Func <int, int>(_ => throw new InvalidOperationException("Should not be called"))).HasValue);
        }