예제 #1
0
        public void CatchByStatusCode()
        {
            var stubBlueprints = Yaml <StubBlueprintManager>(@"
                Blueprints:
                  the-test:
                    Files:
                      workflow.yaml: |
                        operations:
                        - message: Catching 404
                          request: notfound.yaml
                          catch:
                            condition: result.status == `404`
                        - message: Not Catching 503
                          request: servererror.yaml
                          catch:
                            condition: result.status == `404`
                        - message: Still Running
                      notfound.yaml: |
                        method: GET
                        url: https://localhost/notfound
                      servererror.yaml: |
                        method: GET
                        url: https://localhost/servererror
            ");

            var stubHttpClients = Yaml <StubHttpClientHandlerFactory>(@"
                Responses:
                  https://localhost/notfound:
                    GET:
                      status: 404
                      body: Page error
                  https://localhost/servererror:
                    GET:
                      status: 503
                      body: Page error
            ");

            InitializeServices(stubBlueprints, stubHttpClients);

            var ex = Assert.ThrowsException <RequestException>(() => Services.App.Execute("deploy", "the-test"));

            Assert.IsTrue(ex.Message.Contains("503"));

            Assert.AreEqual(503, ex.Response.status);

            Console.AssertContainsInOrder("Catching 404", "Not Catching 503");

            Console.AssertNotContains("Still Running");
        }