コード例 #1
0
        public void RetryOnce_EndingWith_Success()
        {
            /* 𝓐𝓻𝓻𝓪𝓷𝓰𝓮... */

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

            /* ...the gubbins for the HttpSequencer component to work*/

            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}}"
                }
            };

            var dummyRunAfterList = new SequenceItem[] { };
            var dummyRunState     = new RunState {
                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.True(actualResult.IsSuccess);

            Assert.Empty(actualRetryAfterResult);
        }