|
| 1 | +using InertiaCore.Models; |
| 2 | +using Microsoft.AspNetCore.Http; |
| 3 | +using Microsoft.AspNetCore.Mvc; |
| 4 | + |
| 5 | +namespace InertiaCoreTests; |
| 6 | + |
| 7 | +public partial class Tests |
| 8 | +{ |
| 9 | + [Test] |
| 10 | + [Description("Test if history encryption is sent correctly.")] |
| 11 | + public async Task TestHistoryEncryptionResult() |
| 12 | + { |
| 13 | + _factory.EncryptHistory(); |
| 14 | + |
| 15 | + var response = _factory.Render("Test/Page", new |
| 16 | + { |
| 17 | + Test = "Test" |
| 18 | + }); |
| 19 | + |
| 20 | + var headers = new HeaderDictionary |
| 21 | + { |
| 22 | + { "X-Inertia", "true" } |
| 23 | + }; |
| 24 | + |
| 25 | + var context = PrepareContext(headers); |
| 26 | + |
| 27 | + response.SetContext(context); |
| 28 | + await response.ProcessResponse(); |
| 29 | + |
| 30 | + var result = response.GetResult(); |
| 31 | + |
| 32 | + Assert.Multiple(() => |
| 33 | + { |
| 34 | + Assert.That(result, Is.InstanceOf<JsonResult>()); |
| 35 | + |
| 36 | + var json = (result as JsonResult)?.Value; |
| 37 | + Assert.That(json, Is.InstanceOf<Page>()); |
| 38 | + |
| 39 | + Assert.That((json as Page)?.ClearHistory, Is.EqualTo(false)); |
| 40 | + Assert.That((json as Page)?.EncryptHistory, Is.EqualTo(true)); |
| 41 | + Assert.That((json as Page)?.Component, Is.EqualTo("Test/Page")); |
| 42 | + Assert.That((json as Page)?.Props, Is.EqualTo(new Dictionary<string, object?> |
| 43 | + { |
| 44 | + { "test", "Test" }, |
| 45 | + { "errors", new Dictionary<string, string>(0) } |
| 46 | + })); |
| 47 | + }); |
| 48 | + } |
| 49 | + |
| 50 | + [Test] |
| 51 | + [Description("Test if clear history is sent correctly.")] |
| 52 | + public async Task TestClearHistoryResult() |
| 53 | + { |
| 54 | + _factory.ClearHistory(); |
| 55 | + |
| 56 | + var response = _factory.Render("Test/Page", new |
| 57 | + { |
| 58 | + Test = "Test" |
| 59 | + }); |
| 60 | + |
| 61 | + var headers = new HeaderDictionary |
| 62 | + { |
| 63 | + { "X-Inertia", "true" } |
| 64 | + }; |
| 65 | + |
| 66 | + var context = PrepareContext(headers); |
| 67 | + |
| 68 | + response.SetContext(context); |
| 69 | + await response.ProcessResponse(); |
| 70 | + |
| 71 | + var result = response.GetResult(); |
| 72 | + |
| 73 | + Assert.Multiple(() => |
| 74 | + { |
| 75 | + Assert.That(result, Is.InstanceOf<JsonResult>()); |
| 76 | + |
| 77 | + var json = (result as JsonResult)?.Value; |
| 78 | + Assert.That(json, Is.InstanceOf<Page>()); |
| 79 | + |
| 80 | + Assert.That((json as Page)?.ClearHistory, Is.EqualTo(true)); |
| 81 | + Assert.That((json as Page)?.EncryptHistory, Is.EqualTo(false)); |
| 82 | + Assert.That((json as Page)?.Component, Is.EqualTo("Test/Page")); |
| 83 | + Assert.That((json as Page)?.Props, Is.EqualTo(new Dictionary<string, object?> |
| 84 | + { |
| 85 | + { "test", "Test" }, |
| 86 | + { "errors", new Dictionary<string, string>(0) } |
| 87 | + })); |
| 88 | + }); |
| 89 | + } |
| 90 | +} |
0 commit comments