-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathVanityTests.cs
More file actions
82 lines (70 loc) · 1.96 KB
/
Copy pathVanityTests.cs
File metadata and controls
82 lines (70 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Waher.Networking.HTTP.Vanity;
namespace Waher.Networking.HTTP.Test
{
[TestClass]
public class VanityTests
{
private static HttpServer server;
[ClassInitialize]
public static void ClassInitialize(TestContext _)
{
server = [];
server.RegisterVanityResource("/Test/(?'Op'view|edit)/(?'Type'video|photo)/(?'Id'\\d+)", "/Test/Display.md?op={Op}&t={Type}&id={Id}");
server.RegisterVanityResource("/Test/(?'Op'print|export)/(?'Type'video|photo)/(?'Id'\\d+)", "/Test/Output.md?op={Op}&t={Type}&id={Id}");
server.RegisterVanityResource("/Test2/(?'Op'view|edit)/(?'Type'video|photo)/(?'Id'\\d+)", "/Test2/Display.md?op={Op}&t={Type}&id={Id}");
server.RegisterVanityResource("/Test/other/(?'Type'video|photo)/(?'Id'\\d+)", "/Test/Other.md?t={Type}&id={Id}");
}
[ClassCleanup]
public static async Task ClassCleanup()
{
if (server is not null)
{
await server.DisposeAsync();
server = null;
}
}
private static void Test(string Url, string Result)
{
server.CheckVanityResource(ref Url);
Assert.AreEqual(Result, Url);
}
[TestMethod]
public void Test_01_NoMatch()
{
Test("/Other", "/Other");
}
[TestMethod]
public void Test_02_Incipient()
{
Test("/Test", "/Test");
}
[TestMethod]
public void Test_03_Match_1()
{
Test("/Test/view/photo/123", "/Test/Display.md?op=view&t=photo&id=123");
}
[TestMethod]
public void Test_04_Match_2()
{
Test("/Test/edit/video/456", "/Test/Display.md?op=edit&t=video&id=456");
}
[TestMethod]
public void Test_05_Match_3()
{
Test("/Test/print/video/789", "/Test/Output.md?op=print&t=video&id=789");
}
[TestMethod]
public void Test_06_Match_4()
{
Test("/Test2/edit/photo/234", "/Test2/Display.md?op=edit&t=photo&id=234");
}
[TestMethod]
public void Test_07_Match_5()
{
Test("/Test/other/photo/345", "/Test/Other.md?t=photo&id=345");
}
}
}