コード例 #1
0
    public async Task ReturnDelegateResult(string identifier)
    {
        var strategy = new DelegateStrategy(async c => await Task.FromResult(identifier));
        var result   = await strategy.GetIdentifierAsync(new object());

        Assert.Equal(identifier, result);
    }
コード例 #2
0
    public async Task ReturnDelegateResult()
    {
        var strategy = new DelegateStrategy(c => Task.FromResult("test_test"));
        var result   = await strategy.GetIdentifierAsync(new object());

        Assert.Equal("test_test", result);
    }
コード例 #3
0
        public async Task BeAbleToReturnNull()
        {
            var strategy = new DelegateStrategy(async _ => await Task.FromResult <string?>(null));
            var result   = await strategy.GetIdentifierAsync(new object());

            Assert.Null(result);
        }
コード例 #4
0
        public static void TestDelegateStrategy()
        {
            var strategyTest = new DelegateStrategy(SortAlgorithms.SortFast);

            strategyTest.DoSomeWork();
            strategyTest.Strategy = SortAlgorithms.SortSlow;
            strategyTest.DoSomeWork();
        }
コード例 #5
0
    public void CallDelegate()
    {
        int i        = 0;
        var strategy = new DelegateStrategy(c => Task.FromResult((i++).ToString()));

        strategy.GetIdentifierAsync(new object()).Wait();

        Assert.Equal(1, i);
    }