コード例 #1
0
ファイル: ProxyTests.cs プロジェクト: thepirat000/Polly.Proxy
        public async Task TestProxy_ByClass_AsyncVoidMethod_AsyncPolicy()
        {
            var policy = Policy.Handle <ArgumentException>().RetryAsync(1);
            var cli    = new ClientTest();
            var proxy  = PollyProxy <ClientTest> .Create(cli, config => config
                                                         .When(mi => mi.Name == "FailFirstVoidAsync", policy));

            await proxy.FailFirstVoidAsync("y");

            Assert.AreEqual(false, cli._fail);
        }
コード例 #2
0
ファイル: ProxyTests.cs プロジェクト: thepirat000/Polly.Proxy
        public async Task TestProxy_ByInterface_AsyncVoidMethod_AsyncPolicy()
        {
            var policy = Policy.Handle <ArgumentException>().RetryAsync(1);
            var cli    = new ClientTest();
            var proxy  = PollyProxy <IClientTest> .Create(cli, config => config
                                                          .For("NotVirtualFailFirstVoidAsync", policy));

            await proxy.NotVirtualFailFirstVoidAsync("y");

            Assert.IsFalse(cli._fail);
        }
コード例 #3
0
ファイル: ProxyTests.cs プロジェクト: thepirat000/Polly.Proxy
        public async Task TestProxy_NoDefault_AsyncVoidMethod()
        {
            var policy   = Policy.Handle <ArgumentException>().RetryAsync(1);
            var policyNA = Policy.Handle <NullReferenceException>().RetryAsync(2);
            var cli      = new ClientTest();
            var proxy    = PollyProxy <IClientTest> .Create(cli, config => config
                                                            .For("XXXX", policyNA)
                                                            .Default(policy));

            await proxy.NotVirtualFailFirstVoidAsync("y");

            Assert.AreEqual(false, cli._fail);
        }
コード例 #4
0
ファイル: ProxyTests.cs プロジェクト: thepirat000/Polly.Proxy
        public void TestProxy_NotMatchingPolicy()
        {
            var policy = Policy.Handle <ArgumentException>().Retry(3);
            var cli    = new ClientTest();
            var proxy  = PollyProxy <IClientTest> .Create(cli, config => config
                                                          .Map(mi => mi.Name == "XXXXX" ? policy : null)
                                                          .When(mi => mi.GetCustomAttribute <IgnoreAttribute>() != null, policy)
                                                          .For("XX", policy)
                                                          .Default(null));

            Assert.Throws <ArgumentException>(() =>
            {
                var ret2 = proxy.NotVirtualFailFirst("z");  // should not retry because no matching policy
            });
        }
コード例 #5
0
ファイル: ProxyTests.cs プロジェクト: thepirat000/Polly.Proxy
        public async Task TestProxy_AsyncBy_AsyncStateMachineAttribute()
        {
            var policy = Policy.Handle <ArgumentException>().RetryAsync(1);
            var cli    = new ClientTest();
            var proxy  = PollyProxy <ClientTest> .Create(cli, config => config
                                                         .When(mi => mi.GetCustomAttribute <AsyncStateMachineAttribute>() != null, policy));

            var ret = await proxy.FailFirstAsync("y");

            cli._fail = true;
            await proxy.FailFirstVoidAsync("y");

            cli._fail = true;
            Assert.Throws <ArgumentException>(() =>
            {
                proxy.FailFirst("y");
            });
            Assert.AreEqual("y", ret);
        }
コード例 #6
0
ファイル: ProxyTests.cs プロジェクト: thepirat000/Polly.Proxy
        public async Task TestProxy_MapRule()
        {
            var policy   = Policy.Handle <ArgumentException>().RetryAsync(1);
            var policyNA = Policy.Handle <NullReferenceException>().RetryAsync(2);
            var cli      = new ClientTest();
            var proxy    = PollyProxy <IClientTest> .Create(cli, config => config
                                                            .Map(mi => mi.Name == "NotVirtualFailFirstAsync" ? policy : null)
                                                            .Default(policyNA));

            var ret = await proxy.NotVirtualFailFirstAsync("y");

            Assert.IsFalse(cli._fail);
            cli._fail = true;
            Assert.Throws <ArgumentException>(() =>
            {
                var ret2 = proxy.NotVirtualFailFirst("z");  // should not retry because of handling wrong exception
            });
            Assert.AreEqual("y", ret);
        }