|
| 1 | +<!-- |
| 2 | +GENERATED FILE - DO NOT EDIT |
| 3 | +This file was generated by [MarkdownSnippets](https://github.com/SimonCropp/MarkdownSnippets). |
| 4 | +Source File: /readme.source.md |
| 5 | +To change this file edit the source file and then run MarkdownSnippets. |
| 6 | +--> |
| 7 | + |
| 8 | +# <img src="/src/icon.png" height="30px"> Verify.Web |
| 9 | + |
| 10 | +[](https://ci.appveyor.com/project/SimonCropp/verify-web) |
| 11 | +[](https://www.nuget.org/packages/Verify.Web/) |
| 12 | + |
| 13 | +Extends [Verify](https://github.com/SimonCropp/Verify) to allow verification of web bits. |
| 14 | + |
| 15 | +Converts documents (pdf, docx, xslx, and pptx) to png for verification. |
| 16 | + |
| 17 | + |
| 18 | +<!-- toc --> |
| 19 | +## Contents |
| 20 | + |
| 21 | + * [Usage](#usage) |
| 22 | + * [Controller](#controller)<!-- endtoc --> |
| 23 | + |
| 24 | + |
| 25 | +## NuGet package |
| 26 | + |
| 27 | +https://nuget.org/packages/Verify.Web/ |
| 28 | + |
| 29 | + |
| 30 | +## Usage |
| 31 | + |
| 32 | +Enable VerifyWeb once at assembly load time: |
| 33 | + |
| 34 | +<!-- snippet: Enable --> |
| 35 | +<a id='snippet-enable'/></a> |
| 36 | +```cs |
| 37 | +VerifyWeb.Enable(); |
| 38 | +``` |
| 39 | +<sup><a href='/src/Tests/GlobalSetup.cs#L9-L11' title='File snippet `enable` was extracted from'>snippet source</a> | <a href='#snippet-enable' title='Navigate to start of snippet `enable`'>anchor</a></sup> |
| 40 | +<!-- endsnippet --> |
| 41 | + |
| 42 | + |
| 43 | +### Controller |
| 44 | + |
| 45 | +Given the following controller: |
| 46 | + |
| 47 | +<!-- snippet: MyController.cs --> |
| 48 | +<a id='snippet-MyController.cs'/></a> |
| 49 | +```cs |
| 50 | +using System.Collections.Generic; |
| 51 | +using Microsoft.AspNetCore.Mvc; |
| 52 | + |
| 53 | +public class MyController : |
| 54 | + Controller |
| 55 | +{ |
| 56 | + public ActionResult<List<DataItem>> Method(string input) |
| 57 | + { |
| 58 | + var headers = HttpContext.Response.Headers; |
| 59 | + headers.Add("headerKey", "headerValue"); |
| 60 | + headers.Add("receivedInput", input); |
| 61 | + |
| 62 | + var cookies = HttpContext.Response.Cookies; |
| 63 | + cookies.Append("cookieKey", "cookieValue"); |
| 64 | + |
| 65 | + var items = new List<DataItem> |
| 66 | + { |
| 67 | + new DataItem("Value1"), |
| 68 | + new DataItem("Value2") |
| 69 | + }; |
| 70 | + return new ActionResult<List<DataItem>>(items); |
| 71 | + } |
| 72 | + |
| 73 | + public class DataItem |
| 74 | + { |
| 75 | + public string Value { get; } |
| 76 | + |
| 77 | + public DataItem(string value) |
| 78 | + { |
| 79 | + Value = value; |
| 80 | + } |
| 81 | + } |
| 82 | +} |
| 83 | +``` |
| 84 | +<sup><a href='/src/Tests/Snippets/MyController.cs#L1-L33' title='File snippet `MyController.cs` was extracted from'>snippet source</a> | <a href='#snippet-MyController.cs' title='Navigate to start of snippet `MyController.cs`'>anchor</a></sup> |
| 85 | +<!-- endsnippet --> |
| 86 | + |
| 87 | +This test: |
| 88 | + |
| 89 | +<!-- snippet: MyControllerTests.cs --> |
| 90 | +<a id='snippet-MyControllerTests.cs'/></a> |
| 91 | +```cs |
| 92 | +using System.Threading.Tasks; |
| 93 | +using Microsoft.AspNetCore.Http; |
| 94 | +using Microsoft.AspNetCore.Mvc; |
| 95 | +using VerifyXunit; |
| 96 | +using Xunit; |
| 97 | +using Xunit.Abstractions; |
| 98 | + |
| 99 | +public class MyControllerTests : |
| 100 | + VerifyBase |
| 101 | +{ |
| 102 | + public MyControllerTests(ITestOutputHelper output) : |
| 103 | + base(output) |
| 104 | + { |
| 105 | + } |
| 106 | + |
| 107 | + [Fact] |
| 108 | + public Task Test() |
| 109 | + { |
| 110 | + var context = new ControllerContext |
| 111 | + { |
| 112 | + HttpContext = new DefaultHttpContext() |
| 113 | + }; |
| 114 | + var controller = new MyController |
| 115 | + { |
| 116 | + ControllerContext = context |
| 117 | + }; |
| 118 | + |
| 119 | + var result = controller.Method("inputValue"); |
| 120 | + return Verify( |
| 121 | + new |
| 122 | + { |
| 123 | + result, |
| 124 | + context |
| 125 | + }); |
| 126 | + } |
| 127 | +} |
| 128 | +``` |
| 129 | +<sup><a href='/src/Tests/Snippets/MyControllerTests.cs#L1-L36' title='File snippet `MyControllerTests.cs` was extracted from'>snippet source</a> | <a href='#snippet-MyControllerTests.cs' title='Navigate to start of snippet `MyControllerTests.cs`'>anchor</a></sup> |
| 130 | +<!-- endsnippet --> |
| 131 | + |
| 132 | +Will result in the following verified file: |
| 133 | + |
| 134 | +<!-- snippet: MyControllerTests.Test.verified.txt --> |
| 135 | +<a id='snippet-MyControllerTests.Test.verified.txt'/></a> |
| 136 | +```txt |
| 137 | +
|
| 138 | +``` |
| 139 | +<sup><a href='/src/Tests/Snippets/MyControllerTests.Test.verified.txt#L1-L1' title='File snippet `MyControllerTests.Test.verified.txt` was extracted from'>snippet source</a> | <a href='#snippet-MyControllerTests.Test.verified.txt' title='Navigate to start of snippet `MyControllerTests.Test.verified.txt`'>anchor</a></sup> |
| 140 | +<!-- endsnippet --> |
| 141 | + |
| 142 | + |
| 143 | +## Icon |
| 144 | + |
| 145 | +[Swirl](https://thenounproject.com/term/swirl/1568686/) designed by [creativepriyanka](https://thenounproject.com/creativepriyanka) from [The Noun Project](https://thenounproject.com/creativepriyanka). |
0 commit comments