예제 #1
0
        public void TestProxy_ByClass_ForExpressionVoid()
        {
            var policy = Policy.Handle <ArgumentException>().Retry(2);
            var proxy  = PollyProxy <ClientTest> .Create(config => config
                                                         .For(_ => _.FailFirstVoid(null), _ => _.Use(policy)));

            proxy.FailFirstVoid("y");
            Assert.Pass();
        }
예제 #2
0
        public void TestProxy_ByInterface_ForExpressionVoid()
        {
            var policy = Policy.Handle <ArgumentException>().Retry(2);
            var proxy  = PollyProxy <IClientTest> .Create(new ClientTest(), config => config
                                                          .For(_ => _.FailFirstVoid(""), policy));

            proxy.FailFirstVoid("y");
            Assert.Pass();
        }
예제 #3
0
        public async Task TestProxy_ByClass_AsyncMethod_AsyncPolicy()
        {
            var policy = Policy.Handle <ArgumentException>().RetryAsync(1);
            var proxy  = PollyProxy <ClientTest> .Create(config => config
                                                         .When(mi => mi.Name == "FailFirstAsync", _ => _.Use(policy)));

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

            Assert.AreEqual("y", ret);
        }
예제 #4
0
        public void TestProxy_ByInterface_ForExpression()
        {
            var policy = Policy.Handle <ArgumentException>().Retry(2);
            var proxy  = PollyProxy <IClientTest> .Create(new ClientTest(), config => config
                                                          .For(_ => _.NotVirtualFailFirst(null), policy));

            var ret = proxy.NotVirtualFailFirst("y");

            Assert.AreEqual("y", ret);
        }
예제 #5
0
        public void TestProxy_ByInterface_SyncMethod_SyncPolicy()
        {
            var policy = Policy.Handle <ArgumentException>().Retry(1);
            var proxy  = PollyProxy <IClientTest> .Create(new ClientTest(), config => config
                                                          .For("NotVirtualFailFirst", pol => pol.Use(policy)));

            var ret = proxy.NotVirtualFailFirst("y");

            Assert.AreEqual("y", ret);
        }
예제 #6
0
        public void TestProxy_ByClass_SyncMethod_AsyncPolicy()
        {
            var policy = Policy.Handle <ArgumentException>().RetryAsync(1);
            var proxy  = PollyProxy <ClientTest> .Create(config => config
                                                         .For("FailFirst", pol => pol.Use(policy)));

            var ret = proxy.FailFirst("y");

            Assert.AreEqual("y", ret);
        }
예제 #7
0
        public async Task TestProxy_ByClass_AsyncMethod_SyncPolicy()
        {
            var policy = Policy.Handle <ArgumentException>().Retry(1);
            var proxy  = PollyProxy <ClientTest> .Create(config => config
                                                         .For("FailFirstAsync", policy));

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

            Assert.AreEqual("y", ret);
        }
예제 #8
0
        public void TestProxy_CustomAttributeRule()
        {
            var policy = Policy.Handle <ArgumentException>().Retry(2);
            var proxy  = PollyProxy <IClientTest> .Create(new ClientTest(), config => config
                                                          .When(mi => mi.GetCustomAttribute <MarkAttribute>(true) != null, policy));

            var ret = proxy.FailFirst("y");

            Assert.AreEqual("y", ret);
        }
예제 #9
0
        public async Task TestProxy_ByInterface_AsyncMethod_SyncPolicy()
        {
            var policy = Policy.Handle <ArgumentException>().Retry(1);
            var proxy  = PollyProxy <IClientTest> .Create(new ClientTest(), config => config
                                                          .For("NotVirtualFailFirstAsync", policy));

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

            Assert.AreEqual("y", ret);
        }
예제 #10
0
        public void TestProxy_NoPolicy_SyncMethod()
        {
            var policyNA = Policy.Handle <NullReferenceException>().Retry(2);
            var proxy    = PollyProxy <IClientTest> .Create(new ClientTest(), config => config
                                                            .For("XXXX", policyNA));

            Assert.Throws <ArgumentException>(() =>
            {
                var ret = proxy.NotVirtualFailFirst("y");
            });
        }
예제 #11
0
        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);
        }
예제 #12
0
        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);
        }
예제 #13
0
        public async Task TestProxy_NoPolicy_AsyncVoidMethod()
        {
            var policyNA = Policy.Handle <NullReferenceException>().RetryAsync(2);
            var proxy    = PollyProxy <IClientTest> .Create(new ClientTest(), config => config
                                                            .For("XXXX", policyNA));

            Assert.ThrowsAsync <ArgumentException>(async() =>
            {
                await proxy.NotVirtualFailFirstVoidAsync("y");
            });
            await Task.CompletedTask;
        }
예제 #14
0
        public async Task TestProxy_Default_AsyncMethod()
        {
            var policy   = Policy.Handle <ArgumentException>().RetryAsync(1);
            var policyNA = Policy.Handle <NullReferenceException>().RetryAsync(2);
            var proxy    = PollyProxy <IClientTest> .Create(new ClientTest(), config => config
                                                            .For("XXXX", policyNA)
                                                            .Default(policy));

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

            Assert.AreEqual("y", ret);
        }
예제 #15
0
        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);
        }
예제 #16
0
        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
            });
        }
예제 #17
0
        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);
        }
예제 #18
0
        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);
        }