{"id":18937500,"url":"https://github.com/verifytests/verify.http","last_synced_at":"2025-04-15T18:32:12.968Z","repository":{"id":38422668,"uuid":"231843966","full_name":"VerifyTests/Verify.Http","owner":"VerifyTests","description":"Extends Verify to allow verification of web bits.","archived":false,"fork":false,"pushed_at":"2024-04-30T12:29:28.000Z","size":856,"stargazers_count":18,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-01T09:37:53.717Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VerifyTests.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"license.txt","code_of_conduct":"code_of_conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"SimonCropp"}},"created_at":"2020-01-04T23:42:30.000Z","updated_at":"2024-05-09T12:53:18.820Z","dependencies_parsed_at":"2024-05-09T12:53:14.376Z","dependency_job_id":"2156f98e-157b-444d-b0b1-5ccbed720e03","html_url":"https://github.com/VerifyTests/Verify.Http","commit_stats":null,"previous_names":["verifytests/verify.web"],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerifyTests%2FVerify.Http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerifyTests%2FVerify.Http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerifyTests%2FVerify.Http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerifyTests%2FVerify.Http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VerifyTests","download_url":"https://codeload.github.com/VerifyTests/Verify.Http/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249129266,"owners_count":21217319,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T12:11:27.440Z","updated_at":"2025-04-15T18:32:07.954Z","avatar_url":"https://github.com/VerifyTests.png","language":"C#","funding_links":["https://github.com/sponsors/SimonCropp"],"categories":[],"sub_categories":[],"readme":"# \u003cimg src=\"/src/icon.png\" height=\"30px\"\u003e Verify.Http\n\n[![Discussions](https://img.shields.io/badge/Verify-Discussions-yellow?svg=true\u0026label=)](https://github.com/orgs/VerifyTests/discussions)\n[![Build status](https://ci.appveyor.com/api/projects/status/rfmvbst3od5vpl7p?svg=true)](https://ci.appveyor.com/project/SimonCropp/verify-http)\n[![NuGet Status](https://img.shields.io/nuget/v/Verify.Http.svg)](https://www.nuget.org/packages/Verify.Http/)\n\nExtends [Verify](https://github.com/VerifyTests/Verify) to allow verification of Http bits.\n\n**See [Milestones](../../milestones?state=closed) for release notes.**\n\n\n## NuGet package\n\nhttps://nuget.org/packages/Verify.Http/\n\n\n## Enable\n\nEnable at any point in a test using `VerifyTests.Recording.Start()`.\n\n\n## Converters\n\nIncludes converters for the following\n\n  * `HttpMethod`\n  * `Uri`\n  * `HttpHeaders`\n  * `HttpContent`\n  * `HttpRequestMessage`\n  * `HttpResponseMessage`\n\nFor example:\n\n\u003c!-- snippet: HttpResponse --\u003e\n\u003ca id='snippet-HttpResponse'\u003e\u003c/a\u003e\n```cs\n[Fact]\npublic async Task HttpResponse()\n{\n    using var client = new HttpClient();\n\n    var result = await client.GetAsync(\"https://raw.githubusercontent.com/VerifyTests/Verify/main/license.txt\");\n\n    await Verify(result);\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/Tests.cs#L249-L261' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-HttpResponse' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n#### Resulting verified file\n\n\u003c!-- snippet: Tests.HttpResponse.verified.txt --\u003e\n\u003ca id='snippet-Tests.HttpResponse.verified.txt'\u003e\u003c/a\u003e\n```txt\n{\n  Status: 200 OK,\n  Headers: {\n    Accept-Ranges: bytes,\n    Access-Control-Allow-Origin: *,\n    Cache-Control: max-age=300,\n    Connection: keep-alive,\n    Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; sandbox,\n    Cross-Origin-Resource-Policy: cross-origin,\n    Strict-Transport-Security: max-age=31536000,\n    Vary: Authorization,Accept-Encoding,Origin,\n    Via: 1.1 varnish,\n    X-Content-Type-Options: nosniff,\n    X-Frame-Options: deny,\n    X-XSS-Protection: 1; mode=block\n  },\n  Content: {\n    Headers: {\n      Content-Type: text/plain; charset=utf-8,\n      Expires: DateTime_1\n    },\n    Value:\nMIT License\n\nCopyright (c) .NET Foundation and Contributors\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n  }\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/Tests.HttpResponse.verified.txt#L1-L46' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-Tests.HttpResponse.verified.txt' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n## Ignoring Headers\n\nHeaders are treated as properties, and hence can be ignored using `IgnoreMember`:\n\n\u003c!-- snippet: IgnoreHeader --\u003e\n\u003ca id='snippet-IgnoreHeader'\u003e\u003c/a\u003e\n```cs\n[Fact]\npublic async Task IgnoreHeader()\n{\n    using var client = new HttpClient();\n\n    var result = await client.GetAsync(\"https://raw.githubusercontent.com/VerifyTests/Verify/main/license.txt\");\n\n    await Verify(result)\n        .IgnoreMembers(\"Server\");\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/Tests.cs#L7-L20' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-IgnoreHeader' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n## HttpClient recording via Service\n\nFor code that does web calls via HttpClient, these calls can be recorded and verified.\n\n\n### Service that does http\n\nGiven a class that does some Http calls:\n\n\u003c!-- snippet: ServiceThatDoesHttp --\u003e\n\u003ca id='snippet-ServiceThatDoesHttp'\u003e\u003c/a\u003e\n```cs\n// Resolve a HttpClient. All http calls done at any\n// resolved client will be added to `recording.Sends`\npublic class MyService(HttpClient client)\n{\n    public Task MethodThatDoesHttp() =\u003e\n        // Some code that does some http calls\n        client.GetAsync(\"https://raw.githubusercontent.com/VerifyTests/Verify/main/license.txt\");\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/Tests.cs#L60-L71' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-ServiceThatDoesHttp' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n### Add to IHttpClientBuilder\n\nHttp recording can be added to a `IHttpClientBuilder`:\n\n\u003c!-- snippet: HttpClientRecording --\u003e\n\u003ca id='snippet-HttpClientRecording'\u003e\u003c/a\u003e\n```cs\nvar collection = new ServiceCollection();\ncollection.AddScoped\u003cMyService\u003e();\nvar httpBuilder = collection.AddHttpClient\u003cMyService\u003e();\n\n// Adds a AddHttpClient and adds a RecordingHandler using AddHttpMessageHandler\nvar recording = httpBuilder.AddRecording();\n\nawait using var provider = collection.BuildServiceProvider();\n\nvar myService = provider.GetRequiredService\u003cMyService\u003e();\n\nawait myService.MethodThatDoesHttp();\n\nawait Verify(recording.Sends);\n```\n\u003csup\u003e\u003ca href='/src/Tests/Tests.cs#L188-L205' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-HttpClientRecording' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n### Add globally\n\nHttp can also be added globally `IHttpClientBuilder`:\n\n\u003c!-- snippet: HttpClientRecordingGlobal --\u003e\n\u003ca id='snippet-HttpClientRecordingGlobal'\u003e\u003c/a\u003e\n```cs\nvar collection = new ServiceCollection();\ncollection.AddScoped\u003cMyService\u003e();\n\n// Adds a AddHttpClient and adds a RecordingHandler using AddHttpMessageHandler\nvar (builder, recording) = collection.AddRecordingHttpClient();\n\nawait using var provider = collection.BuildServiceProvider();\n\nvar myService = provider.GetRequiredService\u003cMyService\u003e();\n\nawait myService.MethodThatDoesHttp();\n\nawait Verify(recording.Sends);\n```\n\u003csup\u003e\u003ca href='/src/Tests/Tests.cs#L166-L182' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-HttpClientRecordingGlobal' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n#### Resulting verified file\n\n\u003c!-- snippet: Tests.HttpClientRecording.verified.txt --\u003e\n\u003ca id='snippet-Tests.HttpClientRecording.verified.txt'\u003e\u003c/a\u003e\n```txt\n[\n  {\n    RequestUri: https://raw.githubusercontent.com/VerifyTests/Verify/main/license.txt,\n    RequestMethod: GET,\n    ResponseStatus: OK 200,\n    ResponseHeaders: {\n      Accept-Ranges: bytes,\n      Access-Control-Allow-Origin: *,\n      Cache-Control: max-age=300,\n      Connection: keep-alive,\n      Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; sandbox,\n      Cross-Origin-Resource-Policy: cross-origin,\n      Strict-Transport-Security: max-age=31536000,\n      Vary: Authorization|Accept-Encoding|Origin,\n      Via: 1.1 varnish,\n      X-Content-Type-Options: nosniff,\n      X-Frame-Options: deny,\n      X-XSS-Protection: 1; mode=block\n    },\n    ResponseContent:\nMIT License\n\nCopyright (c) .NET Foundation and Contributors\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n  }\n]\n```\n\u003csup\u003e\u003ca href='/src/Tests/Tests.HttpClientRecording.verified.txt#L1-L44' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-Tests.HttpClientRecording.verified.txt' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\nThere a Pause/Resume semantics:\n\n\u003c!-- snippet: HttpClientPauseResume --\u003e\n\u003ca id='snippet-HttpClientPauseResume'\u003e\u003c/a\u003e\n```cs\nvar collection = new ServiceCollection();\ncollection.AddScoped\u003cMyService\u003e();\nvar httpBuilder = collection.AddHttpClient\u003cMyService\u003e();\n\n// Adds a AddHttpClient and adds a RecordingHandler using AddHttpMessageHandler\nvar recording = httpBuilder.AddRecording();\n\nawait using var provider = collection.BuildServiceProvider();\n\nvar myService = provider.GetRequiredService\u003cMyService\u003e();\n\n// Recording is enabled by default. So Pause to stop recording\nrecording.Pause();\nawait myService.MethodThatDoesHttp();\n\n// Resume recording\nrecording.Resume();\nawait myService.MethodThatDoesHttp();\n\nawait Verify(recording.Sends);\n```\n\u003csup\u003e\u003ca href='/src/Tests/Tests.cs#L271-L294' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-HttpClientPauseResume' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\nIf the `AddRecordingHttpClient` helper method does not meet requirements, the `RecordingHandler` can be explicitly added:\n\n\u003c!-- snippet: HttpClientRecordingExplicit --\u003e\n\u003ca id='snippet-HttpClientRecordingExplicit'\u003e\u003c/a\u003e\n```cs\nvar collection = new ServiceCollection();\n\nvar builder = collection.AddHttpClient(\"name\");\n\n// Change to not recording at startup\nvar recording = new RecordingHandler(recording: false);\n\nbuilder.AddHttpMessageHandler(() =\u003e recording);\n\nawait using var provider = collection.BuildServiceProvider();\n\nvar factory = provider.GetRequiredService\u003cIHttpClientFactory\u003e();\n\nvar client = factory.CreateClient(\"name\");\n\nawait client.GetAsync(\"https://www.google.com/\");\n\nrecording.Resume();\nawait client.GetAsync(\"https://raw.githubusercontent.com/VerifyTests/Verify/main/license.txt\");\n\nawait Verify(recording.Sends);\n```\n\u003csup\u003e\u003ca href='/src/Tests/Tests.cs#L300-L324' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-HttpClientRecordingExplicit' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n## Http Recording via listener\n\nHttp Recording allows, when a method is being tested, for any http requests made as part of that method call to be recorded and verified.\n\n\n### Usage\n\nCall `HttpRecording.StartRecording();` before the method being tested is called.\n\nThe perform the verification as usual:\n\n\u003c!-- snippet: HttpRecording --\u003e\n\u003ca id='snippet-HttpRecording'\u003e\u003c/a\u003e\n```cs\n[Fact]\npublic async Task TestHttpRecording()\n{\n    Recording.Start();\n\n    var sizeOfResponse = await MethodThatDoesHttpCalls();\n\n    await Verify(\n            new\n            {\n                sizeOfResponse\n            });\n}\n\nstatic async Task\u003cint\u003e MethodThatDoesHttpCalls()\n{\n    using var client = new HttpClient();\n\n    var jsonResult = await client.GetStringAsync(\"https://github.com/VerifyTests/Verify.Http/raw/main/src/global.json\");\n    var ymlResult = await client.GetStringAsync(\"https://github.com/VerifyTests/Verify.Http/raw/main/src/appveyor.yml\");\n    return jsonResult.Length + ymlResult.Length;\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/Tests.cs#L102-L127' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-HttpRecording' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n#### Resulting verified file\n\nThe requests/response pairs will be appended to the verified file.\n\n\u003c!-- snippet: Tests.TestHttpRecording.verified.txt --\u003e\n\u003ca id='snippet-Tests.TestHttpRecording.verified.txt'\u003e\u003c/a\u003e\n```txt\n{\n  target: {\n    sizeOfResponse: 785\n  },\n  httpCall: [\n    {\n      Status: Created,\n      Request: {\n        Uri: https://github.com/VerifyTests/Verify.Http/raw/main/src/global.json,\n        Headers: {}\n      },\n      Response: {\n        Status: 302 Found,\n        Headers: {\n          Access-Control-Allow-Origin: ,\n          Cache-Control: no-cache,\n          Content-Security-Policy: default-src 'none'; base-uri 'self'; child-src github.com/assets-cdn/worker/ github.com/webpack/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.com/assets-cdn/worker/ github.com/webpack/ github.com/assets/ gist.github.com/assets-cdn/worker/,\n          Location: https://raw.githubusercontent.com/VerifyTests/Verify.Http/main/src/global.json,\n          Referrer-Policy: no-referrer-when-downgrade,\n          Strict-Transport-Security: max-age=31536000; includeSubdomains; preload,\n          Vary: X-PJAX,X-PJAX-Container,Turbo-Visit,Turbo-Frame,Accept-Encoding,Accept,X-Requested-With,\n          X-Content-Type-Options: nosniff,\n          X-Frame-Options: deny,\n          X-XSS-Protection: 0\n        },\n        ContentHeaders: {\n          Content-Type: text/html; charset=utf-8\n        },\n        ContentString: \n      }\n    },\n    {\n      Status: Created,\n      Request: {\n        Uri: https://raw.githubusercontent.com/VerifyTests/Verify.Http/main/src/global.json,\n        Headers: {}\n      },\n      Response: {\n        Status: 200 OK,\n        Headers: {\n          Accept-Ranges: bytes,\n          Access-Control-Allow-Origin: *,\n          Cache-Control: max-age=300,\n          Connection: keep-alive,\n          Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; sandbox,\n          Cross-Origin-Resource-Policy: cross-origin,\n          Strict-Transport-Security: max-age=31536000,\n          Vary: Authorization,Accept-Encoding,Origin,\n          Via: 1.1 varnish,\n          X-Content-Type-Options: nosniff,\n          X-Frame-Options: deny,\n          X-XSS-Protection: 1; mode=block\n        },\n        ContentHeaders: {\n          Content-Type: text/plain; charset=utf-8,\n          Expires: DateTime_1\n        },\n        ContentString:\n{\n  \"sdk\": {\n    \"version\": \"9.0.100-rc.2.24474.11\",\n    \"allowPrerelease\": true,\n    \"rollForward\": \"latestFeature\"\n  }\n}\n      }\n    },\n    {\n      Status: Created,\n      Request: {\n        Uri: https://github.com/VerifyTests/Verify.Http/raw/main/src/appveyor.yml,\n        Headers: {}\n      },\n      Response: {\n        Status: 302 Found,\n        Headers: {\n          Access-Control-Allow-Origin: ,\n          Cache-Control: no-cache,\n          Content-Security-Policy: default-src 'none'; base-uri 'self'; child-src github.com/assets-cdn/worker/ github.com/webpack/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.com/assets-cdn/worker/ github.com/webpack/ github.com/assets/ gist.github.com/assets-cdn/worker/,\n          Location: https://raw.githubusercontent.com/VerifyTests/Verify.Http/main/src/appveyor.yml,\n          Referrer-Policy: no-referrer-when-downgrade,\n          Strict-Transport-Security: max-age=31536000; includeSubdomains; preload,\n          Vary: X-PJAX,X-PJAX-Container,Turbo-Visit,Turbo-Frame,Accept-Encoding,Accept,X-Requested-With,\n          X-Content-Type-Options: nosniff,\n          X-Frame-Options: deny,\n          X-XSS-Protection: 0\n        },\n        ContentHeaders: {\n          Content-Type: text/html; charset=utf-8\n        },\n        ContentString: \n      }\n    },\n    {\n      Status: Created,\n      Request: {\n        Uri: https://raw.githubusercontent.com/VerifyTests/Verify.Http/main/src/appveyor.yml,\n        Headers: {}\n      },\n      Response: {\n        Status: 200 OK,\n        Headers: {\n          Accept-Ranges: bytes,\n          Access-Control-Allow-Origin: *,\n          Cache-Control: max-age=300,\n          Connection: keep-alive,\n          Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; sandbox,\n          Cross-Origin-Resource-Policy: cross-origin,\n          Strict-Transport-Security: max-age=31536000,\n          Vary: Authorization,Accept-Encoding,Origin,\n          Via: 1.1 varnish,\n          X-Content-Type-Options: nosniff,\n          X-Frame-Options: deny,\n          X-XSS-Protection: 1; mode=block\n        },\n        ContentHeaders: {\n          Content-Type: text/plain; charset=utf-8,\n          Expires: DateTime_1\n        },\n        ContentString:\nimage: Visual Studio 2022\nenvironment:\n  DOTNET_NOLOGO: true\n  DOTNET_CLI_TELEMETRY_OPTOUT: true\n  DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true\nbuild_script:\n- pwsh: |\n    Invoke-WebRequest \"https://dot.net/v1/dotnet-install.ps1\" -OutFile \"./dotnet-install.ps1\"\n    ./dotnet-install.ps1 -JSonFile src/global.json -Architecture x64 -InstallDir 'C:\\Program Files\\dotnet'\n- dotnet build src --configuration Release\n- dotnet test src --configuration Release --no-build --no-restore --filter Category!=Integration\ntest: off\non_failure:\n  - ps: Get-ChildItem *.received.* -recurse | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }\nartifacts:\n- path: nugets\\*.nupkg\n      }\n    }\n  ]\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/Tests.TestHttpRecording.verified.txt#L1-L140' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-Tests.TestHttpRecording.verified.txt' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n### Explicit Usage\n\nThe above usage results in the http calls being automatically added snapshot file. Calls can also be explicitly read and recorded using `HttpRecording.FinishRecording()`. This enables:\n\n * Filtering what http calls are included in the snapshot.\n * Only verifying a subset of information for each http call.\n * Performing additional asserts on http calls.\n\nFor example:\n\n\u003c!-- snippet: HttpRecordingExplicit --\u003e\n\u003ca id='snippet-HttpRecordingExplicit'\u003e\u003c/a\u003e\n```cs\n[Fact]\npublic async Task TestHttpRecordingExplicit()\n{\n    Recording.Start();\n\n    var responseSize = await MethodThatDoesHttpCalls();\n\n    var httpCalls = Recording.Stop()\n        .Select(_ =\u003e _.Data)\n        .OfType\u003cHttpCall\u003e()\n        .ToList();\n\n    // Ensure all calls finished in under 5 seconds\n    var threshold = TimeSpan.FromSeconds(5);\n    foreach (var call in httpCalls)\n    {\n        Assert.True(call.Duration \u003c threshold);\n    }\n\n    await Verify(\n        new\n        {\n            responseSize,\n            // Only use the Uri in the snapshot\n            httpCalls = httpCalls.Select(_ =\u003e _.Request.Uri)\n        });\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/Tests.cs#L130-L160' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-HttpRecordingExplicit' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n#### Resulting verified file\n\n\u003c!-- snippet: Tests.TestHttpRecordingExplicit.verified.txt --\u003e\n\u003ca id='snippet-Tests.TestHttpRecordingExplicit.verified.txt'\u003e\u003c/a\u003e\n```txt\n{\n  responseSize: 785,\n  httpCalls: [\n    https://github.com/VerifyTests/Verify.Http/raw/main/src/global.json,\n    https://raw.githubusercontent.com/VerifyTests/Verify.Http/main/src/global.json,\n    https://github.com/VerifyTests/Verify.Http/raw/main/src/appveyor.yml,\n    https://raw.githubusercontent.com/VerifyTests/Verify.Http/main/src/appveyor.yml\n  ]\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/Tests.TestHttpRecordingExplicit.verified.txt#L1-L9' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-Tests.TestHttpRecordingExplicit.verified.txt' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n## Mocking\n\n`MockHttpClient` allows mocking of http responses and recording of http requests.\n\n\n### Default Response\n\nThe default behavior is to return a `HttpResponseMessage` with a status code of `200 OK`.\n\n\u003c!-- snippet: DefaultContent --\u003e\n\u003ca id='snippet-DefaultContent'\u003e\u003c/a\u003e\n```cs\n[Fact]\npublic async Task DefaultContent()\n{\n    using var client = new MockHttpClient();\n\n    var result = await client.GetAsync(\"https://fake/get\");\n\n    await Verify(result);\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/MockHttpClientTests.cs#L37-L49' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-DefaultContent' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n#### Resulting verified file\n\n\u003c!-- snippet: MockHttpClientTests.DefaultContent.verified.txt --\u003e\n\u003ca id='snippet-MockHttpClientTests.DefaultContent.verified.txt'\u003e\u003c/a\u003e\n```txt\n{\n  Version: 1.1,\n  Status: 200 OK\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/MockHttpClientTests.DefaultContent.verified.txt#L1-L4' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-MockHttpClientTests.DefaultContent.verified.txt' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n### Verifying Calls\n\nRequest-Response pairs can be verified using `MockHttpClient.Calls`\n\n\u003c!-- snippet: RecordedCalls --\u003e\n\u003ca id='snippet-RecordedCalls'\u003e\u003c/a\u003e\n```cs\n[Fact]\npublic async Task RecordedCalls()\n{\n    using var client = new MockHttpClient();\n\n    await client.GetAsync(\"https://fake/get1\");\n    await client.GetAsync(\"https://fake/get2\");\n\n    await Verify(client.Calls);\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/MockHttpClientTests.cs#L51-L64' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-RecordedCalls' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n#### Resulting verified file\n\n\u003c!-- snippet: MockHttpClientTests.RecordedCalls.verified.txt --\u003e\n\u003ca id='snippet-MockHttpClientTests.RecordedCalls.verified.txt'\u003e\u003c/a\u003e\n```txt\n[\n  {\n    Request: https://fake/get1,\n    Response: 200 Ok\n  },\n  {\n    Request: https://fake/get2,\n    Response: 200 Ok\n  }\n]\n```\n\u003csup\u003e\u003ca href='/src/Tests/MockHttpClientTests.RecordedCalls.verified.txt#L1-L10' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-MockHttpClientTests.RecordedCalls.verified.txt' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n### Explicit Content Response\n\nAlways return an explicit `StringContent` and media-type:\n\n\u003c!-- snippet: ExplicitContent --\u003e\n\u003ca id='snippet-ExplicitContent'\u003e\u003c/a\u003e\n```cs\n[Fact]\npublic async Task ExplicitContent()\n{\n    using var client = new MockHttpClient(\n        content: \"\"\"{ \"a\": \"b\" }\"\"\",\n        mediaType: \"application/json\");\n\n    var result = await client.GetAsync(\"https://fake/get\");\n\n    await Verify(result);\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/MockHttpClientTests.cs#L21-L35' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-ExplicitContent' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n#### Resulting verified file\n\n\u003c!-- snippet: MockHttpClientTests.ExplicitContent.verified.txt --\u003e\n\u003ca id='snippet-MockHttpClientTests.ExplicitContent.verified.txt'\u003e\u003c/a\u003e\n```txt\n{\n  Status: 200 OK,\n  Content: {\n    Headers: {\n      Content-Type: application/json; charset=utf-8\n    },\n    Value: {\n      a: b\n    }\n  }\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/MockHttpClientTests.ExplicitContent.verified.txt#L1-L11' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-MockHttpClientTests.ExplicitContent.verified.txt' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n### Explicit HttpStatusCode Response\n\nAlways return an explicit `HttpStatusCode`:\n\n\u003c!-- snippet: ExplicitStatusCode --\u003e\n\u003ca id='snippet-ExplicitStatusCode'\u003e\u003c/a\u003e\n```cs\n[Fact]\npublic async Task ExplicitStatusCode()\n{\n    using var client = new MockHttpClient(HttpStatusCode.Ambiguous);\n\n    var result = await client.GetAsync(\"https://fake/get\");\n\n    await Verify(result);\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/MockHttpClientTests.cs#L66-L78' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-ExplicitStatusCode' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n#### Resulting verified file\n\n\u003c!-- snippet: MockHttpClientTests.ExplicitStatusCode.verified.txt --\u003e\n\u003ca id='snippet-MockHttpClientTests.ExplicitStatusCode.verified.txt'\u003e\u003c/a\u003e\n```txt\n{\n  Version: 1.1,\n  Status: 300 Multiple Choices\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/MockHttpClientTests.ExplicitStatusCode.verified.txt#L1-L4' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-MockHttpClientTests.ExplicitStatusCode.verified.txt' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n### Explicit HttpResponseMessage\n\nAlwars return an explicit `HttpResponseMessage`:\n\n\u003c!-- snippet: ExplicitResponse --\u003e\n\u003ca id='snippet-ExplicitResponse'\u003e\u003c/a\u003e\n```cs\n[Fact]\npublic async Task ExplicitResponse()\n{\n    var response = new HttpResponseMessage(HttpStatusCode.OK)\n    {\n        Content = new StringContent(\"Hello\")\n    };\n    using var client = new MockHttpClient(response);\n\n    var result = await client.GetAsync(\"https://fake/get\");\n\n    await Verify(result);\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/MockHttpClientTests.cs#L80-L96' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-ExplicitResponse' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n#### Resulting verified file\n\n\u003c!-- snippet: MockHttpClientTests.ExplicitResponse.verified.txt --\u003e\n\u003ca id='snippet-MockHttpClientTests.ExplicitResponse.verified.txt'\u003e\u003c/a\u003e\n```txt\n{\n  Status: 200 OK,\n  Content: {\n    Headers: {\n      Content-Type: text/plain; charset=utf-8\n    },\n    Value: Hello\n  }\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/MockHttpClientTests.ExplicitResponse.verified.txt#L1-L9' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-MockHttpClientTests.ExplicitResponse.verified.txt' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n### HttpResponseMessage builder\n\nUse custom code to create a `HttpResponseMessage` base on a `HttpRequestMessage`:\n\n\u003c!-- snippet: ResponseBuilder --\u003e\n\u003ca id='snippet-ResponseBuilder'\u003e\u003c/a\u003e\n```cs\n[Fact]\npublic async Task ResponseBuilder()\n{\n    using var client = new MockHttpClient(\n        request =\u003e\n        {\n            var content = $\"Hello to {request.RequestUri}\";\n            var response = new HttpResponseMessage(HttpStatusCode.OK)\n            {\n                Content = new StringContent(content),\n            };\n            return response;\n        });\n\n    var result1 = await client.GetAsync(\"https://fake/get1\");\n    var result2 = await client.GetAsync(\"https://fake/get2\");\n\n    await Verify(new\n    {\n        result1,\n        result2\n    });\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/MockHttpClientTests.cs#L125-L151' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-ResponseBuilder' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n#### Resulting verified file\n\n\u003c!-- snippet: MockHttpClientTests.ResponseBuilder.verified.txt --\u003e\n\u003ca id='snippet-MockHttpClientTests.ResponseBuilder.verified.txt'\u003e\u003c/a\u003e\n```txt\n{\n  result1: {\n    Status: 200 OK,\n    Content: {\n      Headers: {\n        Content-Type: text/plain; charset=utf-8\n      },\n      Value: Hello to https://fake/get1\n    }\n  },\n  result2: {\n    Status: 200 OK,\n    Content: {\n      Headers: {\n        Content-Type: text/plain; charset=utf-8\n      },\n      Value: Hello to https://fake/get2\n    }\n  }\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/MockHttpClientTests.ResponseBuilder.verified.txt#L1-L20' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-MockHttpClientTests.ResponseBuilder.verified.txt' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n### Enumeration of HttpResponseMessage\n\nUse a sequence of `HttpResponseMessage` to return a sequence of requests:\n\n\u003c!-- snippet: EnumerableResponses --\u003e\n\u003ca id='snippet-EnumerableResponses'\u003e\u003c/a\u003e\n```cs\n[Fact]\npublic async Task EnumerableResponses()\n{\n    using var client = new MockHttpClient(\n        new HttpResponseMessage(HttpStatusCode.OK)\n        {\n            Content = new StringContent(\"Hello\")\n        },\n        new HttpResponseMessage(HttpStatusCode.OK)\n        {\n            Content = new StringContent(\"World\")\n        });\n\n    var result1 = await client.GetAsync(\"https://fake/get1\");\n    var result2 = await client.GetAsync(\"https://fake/get2\");\n\n    await Verify(new\n    {\n        result1,\n        result2\n    });\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/MockHttpClientTests.cs#L98-L123' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-EnumerableResponses' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n#### Resulting verified file\n\n\u003c!-- snippet: MockHttpClientTests.EnumerableResponses.verified.txt --\u003e\n\u003ca id='snippet-MockHttpClientTests.EnumerableResponses.verified.txt'\u003e\u003c/a\u003e\n```txt\n{\n  result1: {\n    Status: 200 OK,\n    Content: {\n      Headers: {\n        Content-Type: text/plain; charset=utf-8\n      },\n      Value: Hello\n    }\n  },\n  result2: {\n    Status: 200 OK,\n    Content: {\n      Headers: {\n        Content-Type: text/plain; charset=utf-8\n      },\n      Value: World\n    }\n  }\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/MockHttpClientTests.EnumerableResponses.verified.txt#L1-L20' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-MockHttpClientTests.EnumerableResponses.verified.txt' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n## Icon\n\n[Spider](https://thenounproject.com/term/spider/904683/) designed by [marialuisa iborra](https://thenounproject.com/marialuisa.iborra/) from [The Noun Project](https://thenounproject.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fverifytests%2Fverify.http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fverifytests%2Fverify.http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fverifytests%2Fverify.http/lists"}