Skip to content

Commit 5a79d82

Browse files
committed
Added Tests for AddSkillDialog and SkillRepository
1 parent 5d5afe0 commit 5a79d82

File tree

3 files changed

+100
-5
lines changed

3 files changed

+100
-5
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System.Threading.Tasks;
2+
using FluentAssertions;
3+
using LinkDotNet.Blog.TestUtilities;
4+
using LinkDotNet.Domain;
5+
using Xunit;
6+
7+
namespace LinkDotNet.Blog.IntegrationTests.Infrastructure.Persistence.Sql
8+
{
9+
public class SkillRepositoryTests : SqlDatabaseTestBase<Skill>
10+
{
11+
[Fact]
12+
public async Task ShouldSaveAndRetrieveAllEntries()
13+
{
14+
var skill = new SkillBuilder()
15+
.WithSkillName("C#")
16+
.WithIconUrl("url")
17+
.WithCapability("Backend")
18+
.WithProficiencyLevel(ProficiencyLevel.Expert).Build();
19+
await Repository.StoreAsync(skill);
20+
21+
var items = await Repository.GetAllAsync();
22+
23+
items.Should().HaveCount(1);
24+
items[0].Name.Should().Be("C#");
25+
items[0].IconUrl.Should().Be("url");
26+
items[0].Capability.Should().Be("Backend");
27+
items[0].ProficiencyLevel.Should().Be(ProficiencyLevel.Expert);
28+
}
29+
30+
[Fact]
31+
public async Task ShouldDelete()
32+
{
33+
var skill1 = new SkillBuilder().Build();
34+
var skill2 = new SkillBuilder().Build();
35+
await Repository.StoreAsync(skill1);
36+
await Repository.StoreAsync(skill2);
37+
38+
await Repository.DeleteAsync(skill1.Id);
39+
40+
var items = await Repository.GetAllAsync();
41+
items.Should().HaveCount(1);
42+
items[0].Id.Should().Be(skill2.Id);
43+
}
44+
45+
[Fact]
46+
public async Task NoopOnDeleteWhenEntryNotFound()
47+
{
48+
var item = new SkillBuilder().Build();
49+
await Repository.StoreAsync(item);
50+
51+
await Repository.DeleteAsync("SomeIdWhichHopefullyDoesNotExist");
52+
53+
(await Repository.GetAllAsync()).Should().HaveCount(1);
54+
}
55+
}
56+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Blazored.Toast.Services;
2+
using Bunit;
3+
using FluentAssertions;
4+
using LinkDotNet.Blog.Web.Shared.Skills;
5+
using LinkDotNet.Domain;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using Moq;
8+
using Xunit;
9+
10+
namespace LinkDotNet.Blog.UnitTests.Web.Shared.Skills
11+
{
12+
public class AddSkillDialogTests : TestContext
13+
{
14+
[Fact]
15+
public void ShouldCreateSkill()
16+
{
17+
Skill addedSkill = null;
18+
var toastServiceMock = new Mock<IToastService>();
19+
Services.AddScoped(_ => toastServiceMock.Object);
20+
var cut = RenderComponent<AddSkillDialog>(p =>
21+
p.Add(s => s.SkillAdded, t => addedSkill = t));
22+
cut.Find("#title").Change("C#");
23+
cut.Find("#image").Change("Url");
24+
cut.Find("#capability").Change("capability");
25+
cut.Find("#proficiency").Change(ProficiencyLevel.Expert.Key);
26+
27+
cut.Find("form").Submit();
28+
29+
addedSkill.Should().NotBeNull();
30+
addedSkill.Name.Should().Be("C#");
31+
addedSkill.IconUrl.Should().Be("Url");
32+
addedSkill.Capability.Should().Be("capability");
33+
addedSkill.ProficiencyLevel.Should().Be(ProficiencyLevel.Expert);
34+
toastServiceMock.Verify(t => t.ShowSuccess(
35+
"Created Skill C# in capability capability with level Expert",
36+
string.Empty));
37+
}
38+
}
39+
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
optimal size</small>
1616
</div>
1717
<div class="mb-3">
18-
<label for="capability">Capability</label>
19-
<InputText class="form-control" id="capability" @bind-Value="model.Capability" />
20-
</div>
18+
<label for="capability">Capability</label>
19+
<InputText class="form-control" id="capability" @bind-Value="model.Capability" />
20+
</div>
2121
<div class="mb-3">
22-
<label for="tags">Proficiency</label>
23-
<select class="form-select" id="tags" @bind="model.Proficiency">
22+
<label for="proficiency">Proficiency</label>
23+
<select class="form-select" id="proficiency" @bind="model.Proficiency">
2424
@foreach (var level in ProficiencyLevel.All)
2525
{
2626
<option value="@level.Key">@level.Key</option>

0 commit comments

Comments
 (0)