Пример #1
0
        public HttpSequencer_SequenceItemRetryDispatcher()
        {
            Port = GetAvailablePort();
            var consumerName = $"{nameof(HttpSequencer_SequenceItemRetryDispatcher)}Consumer";

            ConsumeTestYamlPact = new ConsumeHttpSequencerPact(consumerName, Port);
            ConsumeTestYamlPact.MockProviderService.ClearInteractions();
        }
Пример #2
0
        public HttpSequencer_TypicalOperation_FansOut()
        {
            Port = GetAvailablePort();
            var consumerName = $"{nameof(HttpSequencer_TypicalOperation_FansOut)}Consumer";

            ConsumeTestYamlPact = new ConsumeHttpSequencerPact(consumerName, Port);
            ConsumeTestYamlPact.MockProviderService.ClearInteractions();
        }
Пример #3
0
        public void LoadYaml_ExpectSuccess()
        {
            int testPort = GetAvailablePort();

            string yamlContents = $@"---
sequence_items:
  - command: load-yaml-expect-success
    send:
      http_method: GET
      url: http://localhost:{testPort}";

            using (var consumeTestYamlPact = new ConsumeHttpSequencerPact("FirstConsumer", testPort))
                using (var t = new TempFile())
                {
                    consumeTestYamlPact.MockProviderService.ClearInteractions();

                    /* 𝓐𝓻𝓻𝓪𝓷𝓰𝓮 */
                    File.WriteAllText(t.Filename, yamlContents);

                    consumeTestYamlPact.MockProviderService
                    .Given("There is an active endpoint")
                    .UponReceiving("A GET request to touch the endpoint")
                    .With(new ProviderServiceRequest
                    {
                        Method  = HttpVerb.Get,
                        Path    = "/",
                        Headers = new Dictionary <string, object> {
                            { "Accept", "text/plain" }
                        },
                    })
                    .WillRespondWith(new ProviderServiceResponse
                    {
                        Status  = 200,
                        Headers = new Dictionary <string, object> {
                            { "Content-Type", "application/json; charset=utf-8" }
                        },
                        Body = { }
                    });

                    var testOptions = new Options {
                        YamlFile = t.Filename
                    };

                    /* 𝓐𝓬𝓽 */
                    var consumer = new HttpSequencer.HttpSequencer();
                    var result   = consumer.RunSequenceAsync(testOptions).Result;

                    /* 𝓐𝓼𝓼𝓮𝓻𝓽 */
                    Assert.Equal(0, result);
                    consumeTestYamlPact.MockProviderService.VerifyInteractions();
                }
        }
        public HttpSequencer_SequenceItemDispatcher()
        {
            Port = GetAvailablePort();
            var consumerName = $"{nameof(HttpSequencer_SequenceItemDispatcher)}Consumer";

            ConsumeTestYamlPact = new ConsumeHttpSequencerPact(consumerName, Port);
            ConsumeTestYamlPact.MockProviderService.ClearInteractions();
            testSequenceItem = new SequenceItem
            {
                command            = "some-request",
                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}}"
                }
            };
        }
Пример #5
0
        public void InvalidUrlForSecondSequenceItem()
        {
            int testPort = GetAvailablePort();

            using (var ConsumeTestYamlPact = new ConsumeHttpSequencerPact("FirstConsumer", testPort))
            {
                ConsumeTestYamlPact.MockProviderService.ClearInteractions();


                /* 𝓐𝓻𝓻𝓪𝓷𝓰𝓮 */
                const string expectedMoreDetailString = nameof(expectedMoreDetailString);

                ConsumeTestYamlPact.MockProviderService
                .Given("There is an active endpoint that provides a list of ids")
                .UponReceiving("A GET request to retrieve the list")
                .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 Dictionary <string, object> {
                        { "Id", "00000001" }
                    }
                });

                var testYamlSequence = new YamlScript
                {
                    sequence_items = new List <SequenceItem> {
                        /* First */
                        new SequenceItem
                        {
                            command = "one-of-two-url-ok",
                            send    = new UrlRequest
                            {
                                header = new KeyValueList {
                                    new KeyValuePair <string, string>("Accept", "application/json")
                                },
                                http_method = "GET",
                                url         = $"http://localhost:{testPort}/first"
                            }
                        },
                        /* Second */
                        new SequenceItem
                        {
                            command = "two-of-two-url-doesnt-exist",
                            send    = new UrlRequest
                            {
                                header = new KeyValueList {
                                    new KeyValuePair <string, string>("Accept", "application/json")
                                },
                                http_method = "GET",
                                url         = "http://doesnt-even-exist-7djemd/totally-invalid-url/{{model.Id}}"
                            }
                        }
                    }
                };

                var testOptions = new Options {
                    YamlDirect = testYamlSequence
                };

                /* 𝓐𝓬𝓽 */
                var provider = new HttpSequencer.HttpSequencer();
                var result   = provider.RunSequenceAsync(testOptions).Result;

                /* 𝓐𝓼𝓼𝓮𝓻𝓽 */
                Assert.Equal(1, result);
                ConsumeTestYamlPact.MockProviderService.VerifyInteractions();
            }
        }