Skip to content

Commit c69a8e5

Browse files
committed
Hardened Skill domain object
1 parent c945788 commit c69a8e5

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

LinkDotNet.Blog.Domain/Skill.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ private Skill(string name, string iconUrl, string capability, ProficiencyLevel p
1616
ProficiencyLevel = proficiencyLevel;
1717
}
1818

19-
public string IconUrl { get; set; }
19+
public string IconUrl { get; private set; }
2020

21-
public string Name { get; set; }
21+
public string Name { get; private set; }
2222

23-
public string Capability { get; set; }
23+
public string Capability { get; private set; }
2424

25-
public ProficiencyLevel ProficiencyLevel { get; set; }
25+
public ProficiencyLevel ProficiencyLevel { get; private set; }
26+
27+
public void SetProficiencyLevel(ProficiencyLevel level)
28+
{
29+
ArgumentNullException.ThrowIfNull(level);
30+
ProficiencyLevel = level;
31+
}
2632

2733
public static Skill Create(string name, string iconUrl, string capability, string proficiencyLevel)
2834
{

LinkDotNet.Blog.UnitTests/Domain/SkillTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,24 @@ public void ShouldSetUrlToNullWhenWhitespace(string url)
5757

5858
skill.IconUrl.Should().BeNull();
5959
}
60+
61+
[Fact]
62+
public void ShouldSetProficiencyLevel()
63+
{
64+
var skill = Skill.Create("name", null, "cap", ProficiencyLevel.Familiar.Key);
65+
66+
skill.SetProficiencyLevel(ProficiencyLevel.Proficient);
67+
68+
skill.ProficiencyLevel.Should().Be(ProficiencyLevel.Proficient);
69+
}
70+
71+
[Fact]
72+
public void ShouldThrowWhenProficiencyIsNull()
73+
{
74+
var skill = Skill.Create("name", null, "cap", ProficiencyLevel.Familiar.Key);
75+
76+
Action result = () => skill.SetProficiencyLevel(null);
77+
78+
result.Should().Throw<ArgumentNullException>();
79+
}
6080
}

LinkDotNet.Blog.Web/Shared/Skills/SkillTable.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
return;
8484
}
8585

86-
currentDragItem.ProficiencyLevel = proficiencyLevel;
86+
currentDragItem.SetProficiencyLevel(proficiencyLevel);
8787
await repository.StoreAsync(currentDragItem);
8888
currentDragItem = null;
8989
}

0 commit comments

Comments
 (0)