Skip to content

Commit ff5ad82

Browse files
committed
Add Tests for skilltree
1 parent 5a79d82 commit ff5ad82

File tree

4 files changed

+106
-1
lines changed

4 files changed

+106
-1
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System.Linq;
2+
using System.Threading.Tasks;
3+
using AngleSharp.Dom;
4+
using Blazored.Toast.Services;
5+
using Bunit;
6+
using FluentAssertions;
7+
using LinkDotNet.Blog.TestUtilities;
8+
using LinkDotNet.Blog.Web.Shared.Skills;
9+
using LinkDotNet.Domain;
10+
using LinkDotNet.Infrastructure.Persistence;
11+
using Microsoft.Extensions.DependencyInjection;
12+
using Moq;
13+
using Xunit;
14+
15+
namespace LinkDotNet.Blog.IntegrationTests.Web.Shared.Skills
16+
{
17+
public class SkillTreeTests : SqlDatabaseTestBase<Skill>
18+
{
19+
[Fact]
20+
public async Task ShouldDeleteItem()
21+
{
22+
var skill = new SkillBuilder().WithSkillName("C#").Build();
23+
using var ctx = new TestContext();
24+
await Repository.StoreAsync(skill);
25+
ctx.Services.AddScoped<IRepository<Skill>>(_ => Repository);
26+
ctx.Services.AddScoped(_ => new Mock<IToastService>().Object);
27+
var cut = ctx.RenderComponent<SkillTable>(p =>
28+
p.Add(s => s.IsAuthenticated, true));
29+
cut.WaitForState(() => cut.HasComponent<SkillTag>());
30+
31+
cut.FindComponent<SkillTag>().Find("button").Click();
32+
33+
var items = (await Repository.GetAllAsync()).ToList();
34+
items.Should().HaveCount(0);
35+
cut.FindAll("td").Any(s => s.TextContent == "C#").Should().BeFalse();
36+
}
37+
38+
[Fact]
39+
public async Task ShouldAddSkill()
40+
{
41+
using var ctx = new TestContext();
42+
ctx.Services.AddScoped<IRepository<Skill>>(_ => Repository);
43+
ctx.Services.AddScoped(_ => new Mock<IToastService>().Object);
44+
var cut = ctx.RenderComponent<SkillTable>(p =>
45+
p.Add(s => s.IsAuthenticated, true));
46+
cut.Find("button").Click();
47+
var dialog = cut.FindComponent<AddSkillDialog>();
48+
dialog.Find("#title").Change("C#");
49+
dialog.Find("#image").Change("Url");
50+
dialog.Find("#capability").Change("capability");
51+
dialog.Find("#proficiency").Change(ProficiencyLevel.Expert.Key);
52+
53+
dialog.Find("form").Submit();
54+
55+
cut.WaitForState(() => cut.HasComponent<SkillTag>());
56+
var skillTag = cut.FindComponent<SkillTag>();
57+
skillTag.Find("span").Text().Should().Contain("C#");
58+
var fromRepo = (await Repository.GetAllAsync())[0];
59+
fromRepo.Name.Should().Be("C#");
60+
fromRepo.IconUrl.Should().Be("Url");
61+
fromRepo.Capability.Should().Be("capability");
62+
fromRepo.ProficiencyLevel.Should().Be(ProficiencyLevel.Expert);
63+
}
64+
}
65+
}

LinkDotNet.Blog.UnitTests/Domain/EnumerationTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,29 @@ public void GivenTwoEqualEnumerationThenHashcodeEqual()
8989

9090
hashCode1.Should().Be(hashCode2);
9191
}
92+
93+
[Fact]
94+
public void ShouldNotBeEqualWhenNull()
95+
{
96+
var isEqual = TestEnumeration.One.Equals(null);
97+
98+
isEqual.Should().BeFalse();
99+
}
100+
101+
[Fact]
102+
public void ShouldNotBeEqualWhenDifferentNull()
103+
{
104+
var isEqual = TestEnumeration.One.Equals("string");
105+
106+
isEqual.Should().BeFalse();
107+
}
108+
109+
[Fact]
110+
public void ShouldBeEqualWhenKeyTheSame()
111+
{
112+
var isEqual = TestEnumeration.One.Equals(TestEnumeration.One);
113+
114+
isEqual.Should().BeTrue();
115+
}
92116
}
93117
}

LinkDotNet.Domain/Enumeration.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace LinkDotNet.Domain
88
public abstract class Enumeration<TEnumeration>
99
where TEnumeration : Enumeration<TEnumeration>
1010
{
11-
private string key;
11+
private readonly string key;
1212

1313
protected Enumeration()
1414
{
@@ -57,6 +57,21 @@ public static TEnumeration Create(string key)
5757

5858
public override int GetHashCode() => Key.GetHashCode();
5959

60+
public override bool Equals(object obj)
61+
{
62+
if (obj is null)
63+
{
64+
return false;
65+
}
66+
67+
if (obj.GetType() != typeof(TEnumeration))
68+
{
69+
return false;
70+
}
71+
72+
return (obj as TEnumeration).key == key;
73+
}
74+
6075
public override string ToString() => Key;
6176

6277
private static TEnumeration[] GetEnumerations()

stylecop.analyzers.ruleset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
<Rule Id="SA1601" Action="None"/>
8989
<Rule Id="SA1633" Action="None"/>
9090
<Rule Id="SA1609" Action="Warning"/>
91+
<Rule Id="SA1649" Action="None"/>
9192
</Rules>
9293
<Rules AnalyzerId="DocumentationAnalyzers" RuleNamespace="DocumentationAnalyzers">
9394
<Rule Id="DOC100" Action="Warning"/>

0 commit comments

Comments
 (0)