-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkTests.cs
More file actions
81 lines (64 loc) · 2.32 KB
/
LinkTests.cs
File metadata and controls
81 lines (64 loc) · 2.32 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
using Bogus;
using FluentAssertions;
using System.Collections.Generic;
using Xunit;
using Xunit.Categories;
namespace Candoumbe.Forms.UnitTests;
[Feature(nameof(Candoumbe.Forms))]
[Feature(nameof(Link))]
public class LinkTests
{
private static readonly Faker Faker = new();
[Fact]
public void Ctor_builds_valid_instance()
{
// Act
Link link = new();
// Assert
link.Href.Should().BeNull();
link.Method.Should().BeNull();
link.Relations.Should().BeEmpty();
link.Template.Should().BeNull();
link.Title.Should().BeNull();
link.Relations.Should().BeEmpty();
}
[Theory]
[InlineData("a/link/", false, "a relative link with no placeholder")]
[InlineData("a/link/{id}", true, "the relative link contains a placeholder")]
[InlineData("a/link/?id={id}", true, "the relative link contains a placeholder in its query string")]
public void Compute_template_correctly(string href, bool expected, string reason)
{
// Arrange
// Act
Link link = new() { Href = href };
// Assert
link.Template.Should()
.Be(expected, reason);
}
[Theory]
[InlineData(null, false, "null is not a URI template")]
[InlineData("", false, "empty string is not a URI template")]
[InlineData("a/link/", false, "a relative link with no placeholder")]
[InlineData("a/link/{id}", true, "the relative link contains a placeholder")]
[InlineData("a/link/?id={id}", true, "the relative link contains a placeholder in its query string")]
[InlineData("a/{resource}/{id}", true, "the relative link contains two placeholders")]
public void IsTemplate_returns_correct_result(string href, bool expected, string reason)
{
// Act
bool result = Link.IsTemplate(href);
// Assert
result.Should().Be(expected, reason);
}
[Fact]
public void Given_existing_link_already_relations_When_adding_a_relation_that_already_exists_Then_there_should_be_no_duplicates()
{
// Arrange
string relation = Faker.Lorem.Word();
// Act
Link link = new() { Relations = new HashSet<string> { relation, relation } };
// Assert
link.Relations.Should()
.HaveCount(1).And
.OnlyContain(rel => rel == relation);
}
}