Welcome to mirror list, hosted at ThFree Co, Russian Federation.

LazyFixture.cs « LibGit2Sharp.Tests - github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 14b797ea6f99158904a4a30b9b61ba9ddc4a573e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using LibGit2Sharp.Core.Compat;
using Xunit;

namespace LibGit2Sharp.Tests
{
    public class LazyFixture
    {
        [Fact]
        public void CanReturnTheValue()
        {
            var lazy = new Lazy<int>(() => 2);
            Assert.Equal(2, lazy.Value);
        }

        [Fact]
        public void IsLazilyEvaluated()
        {
            int i = 0;

            var evaluator = new Func<int>(() => ++i);

            var lazy = new Lazy<int>(evaluator);
            Assert.Equal(1, lazy.Value);
        }

        [Fact]
        public void IsEvaluatedOnlyOnce()
        {
            int i = 0;

            var evaluator = new Func<int>(() => ++i);

            var lazy = new Lazy<int>(evaluator);

            Assert.Equal(1, lazy.Value);
            Assert.Equal(1, lazy.Value);
        }
    }
}