Skip to content

Commit 36ba668

Browse files
committed
Added Tests for Skills
1 parent 04e20ea commit 36ba668

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed

LinkDotNet.Blog.UnitTests/Domain/EnumerationTests.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,18 @@ public void NullEnumerationNeverEqual()
7676
[Fact]
7777
public void ShouldDifferentEnumerations()
7878
{
79-
var isEqual = TestEnumeration.One == TestEnumeration.Two;
79+
var isEqual = TestEnumeration.One != TestEnumeration.Two;
8080

81-
isEqual.Should().BeFalse();
81+
isEqual.Should().BeTrue();
82+
}
83+
84+
[Fact]
85+
public void GivenTwoEqualEnumerationThenHashcodeEqual()
86+
{
87+
var hashCode1 = TestEnumeration.One.GetHashCode();
88+
var hashCode2 = TestEnumeration.Create(TestEnumeration.One.Key).GetHashCode();
89+
90+
hashCode1.Should().Be(hashCode2);
8291
}
8392
}
8493
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using FluentAssertions;
3+
using LinkDotNet.Domain;
4+
using Xunit;
5+
6+
namespace LinkDotNet.Blog.UnitTests.Domain
7+
{
8+
public class SkillTests
9+
{
10+
[Fact]
11+
public void ShouldCreateSkillTrimmedWhitespaces()
12+
{
13+
var skill = Skill.Create(" C# ", "url", " Backend ", ProficiencyLevel.Expert.Key);
14+
15+
skill.Name.Should().Be("C#");
16+
skill.IconUrl.Should().Be("url");
17+
skill.Capability.Should().Be("Backend");
18+
skill.ProficiencyLevel.Should().Be(ProficiencyLevel.Expert);
19+
}
20+
21+
[Theory]
22+
[InlineData(null)]
23+
[InlineData("")]
24+
[InlineData(" ")]
25+
public void ShouldThrowWhenWhitespaceName(string name)
26+
{
27+
Action result = () => Skill.Create(name, "url", "backend", ProficiencyLevel.Expert.Key);
28+
29+
result.Should().Throw<ArgumentNullException>();
30+
}
31+
32+
[Theory]
33+
[InlineData(null)]
34+
[InlineData("")]
35+
[InlineData(" ")]
36+
public void ShouldThrowWhenWhitespaceCapability(string capability)
37+
{
38+
Action result = () => Skill.Create("name", "url", capability, ProficiencyLevel.Expert.Key);
39+
40+
result.Should().Throw<ArgumentNullException>();
41+
}
42+
43+
[Fact]
44+
public void ShouldThrowWhenInvalidProficiencyLevel()
45+
{
46+
Action result = () => Skill.Create("name", "url", "cap", "null");
47+
result.Should().Throw<Exception>();
48+
}
49+
50+
[Theory]
51+
[InlineData(null)]
52+
[InlineData("")]
53+
[InlineData(" ")]
54+
public void ShouldSetUrlToNullWhenWhitespace(string url)
55+
{
56+
var skill = Skill.Create("name", url, "cap", ProficiencyLevel.Expert.Key);
57+
58+
skill.IconUrl.Should().BeNull();
59+
}
60+
}
61+
}

LinkDotNet.Blog.UnitTests/Domain/TestEnumeration.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ public sealed class TestEnumeration : Enumeration<TestEnumeration>
88

99
public static readonly TestEnumeration Two = new TestEnumeration(nameof(Two));
1010

11-
public TestEnumeration(string key) : base(key)
11+
public TestEnumeration(string key)
12+
: base(key)
1213
{
1314
}
1415
}

0 commit comments

Comments
 (0)