示例#1
0
        public void FansOutThree_ExpectedFailOnTwo()
        {
            /* 𝓐𝓻𝓻𝓪𝓷𝓰𝓮 */

            ConsumeTestYamlPact.MockProviderService
            .Given("There is an active endpoint that provides a list of three ids")
            .UponReceiving("A GET request to retrieve the list of three ids")
            .With(new ProviderServiceRequest
            {
                Method  = HttpVerb.Get,
                Path    = "/first",
                Headers = new Dictionary <string, object> {
                    { "Accept", "application/json" }
                },
            })
            .WillRespondWith(new ProviderServiceResponse
            {
                Status  = 200,
                Headers = new Dictionary <string, object> {
                    { "Content-Type", "application/json; charset=utf-8" }
                },
                Body = new List <object> {
                    new { Id = "00000001" },     // <--- Expected fail
                    new { Id = "00000002" },     // <--- Expected fail
                    new { Id = "00000003" },     // <--- Expected success
                }
            });

            SharedPactScafolding.BuildFailConsumerForId(ConsumeTestYamlPact, "00000001");
            SharedPactScafolding.BuildFailConsumerForId(ConsumeTestYamlPact, "00000002");
            SharedPactScafolding.BuildSuccessConsumerForId(ConsumeTestYamlPact, "00000003");

            var testOptions = new Options {
                YamlDirect = MakeYamlSequence(Port, "expect-fail-on-two")
            };


            /* 𝓐𝓬𝓽 */

            var provider = new HttpSequencer.HttpSequencer();
            var result   = provider.RunSequenceAsync(testOptions).Result;


            /* 𝓐𝓼𝓼𝓮𝓻𝓽 */

            Assert.Equal(1, result);

            ConsumeTestYamlPact.MockProviderService.VerifyInteractions();
        }
        public void ExpectFailAndRetry()
        {
            /* 𝓐𝓻𝓻𝓪𝓷𝓰𝓮... */
            SharedPactScafolding.BuildFailConsumerForId(ConsumeTestYamlPact, "00000001");

            var processorOptions = new ProcessSequenceItem.Options
            {
                state = new RunState {
                    YamlOptions = new YamlScript {
                        sequence_items = new[] { testSequenceItem }.ToList()
                    }
                },
                parent       = null,
                model        = new { Id = "00000001" },
                sequenceItem = testSequenceItem,
                breadcrumbs  = new Stack <KeyValuePair <string, ISequenceItemAction> >()
            };


            /* 𝓐𝓬𝓽 */
            var actualRetryAfterResult = new Stack <ISequenceItemAction>();

            var processor    = new ProcessSequenceItem(processorOptions);
            var actualResult = processor.ProcessSequenceItemAsync(actualRetryAfterResult).Result;


            /* 𝓐𝓼𝓼𝓮𝓻𝓽 */
            ConsumeTestYamlPact.MockProviderService.VerifyInteractions();

            Assert.False(actualResult);

            Assert.Same(testSequenceItem, actualRetryAfterResult.Single().GetSequenceItem());

            Assert.Contains(actualRetryAfterResult,
                            item => item.ActionExecuteCount == 2);
        }
示例#3
0
        public void RetryOnce_EndingWith_Fail()
        {
            /* 𝓐𝓻𝓻𝓪𝓷𝓰𝓮... */

            /* ...the Pact server */
            SharedPactScafolding.BuildFailConsumerForId(ConsumeTestYamlPact, "00000001");

            /* ...the gubbins for the HttpSequencer component*/
            var dummyRunState     = new RunState {
            };
            var dummyRunAfterList = new SequenceItem[] { };

            var testModel        = new { Id = "00000001" };
            var testSequenceItem = new SequenceItem
            {
                command            = "something-that-previously-failed",
                max_delayed_retrys = 1,
                send = new UrlRequest
                {
                    header = new KeyValueList {
                        new KeyValuePair <string, string>("Accept", "application/json")
                    },
                    http_method = "GET",
                    url         = $"http://localhost:{Port}/second/" + "{{model.Id}}"
                }
            };

            dummyRunState.YamlOptions = new YamlScript {
                sequence_items = new[] { testSequenceItem }.ToList()
            };
            var testRetryList = new List <ISequenceItemAction>()
            {
                new SequenceItemSend(dummyRunState, testSequenceItem, testModel, dummyRunAfterList)
            };

            var processorOptions = new ProcessSequenceItem.Options
            {
                state = new RunState {
                    YamlOptions = new YamlScript {
                        sequence_items = new[] { testSequenceItem }.ToList()
                    }
                },
                parent       = null,
                model        = null,
                sequenceItem = null,
                breadcrumbs  = new Stack <KeyValuePair <string, ISequenceItemAction> >()
            };

            /* 𝓐𝓬𝓽 */

            var actualRetryAfterResult = new Stack <ISequenceItemAction>();

            var actualResult = new ProcessSequenceItem(processorOptions).SequenceItemRetryDispatcherAsync(
                new CancellationToken(),
                false,
                testRetryList,
                dummyRunState,
                actualRetryAfterResult,
                new Stack <KeyValuePair <string, ISequenceItemAction> >()).Result;


            /* 𝓐𝓼𝓼𝓮𝓻𝓽 */

            ConsumeTestYamlPact.MockProviderService.VerifyInteractions();

            Assert.False(actualResult.IsSuccess);

            Assert.Contains(actualRetryAfterResult,
                            item => item.ActionExecuteCount == 1);
        }