Skip to content

Commit 4c4678e

Browse files
committed
Added Test for AddProfileShortItem
1 parent 96c5ad1 commit 4c4678e

File tree

2 files changed

+68
-9
lines changed

2 files changed

+68
-9
lines changed

LinkDotNet.Blog.UnitTests/Infrastructure/Persistence/InMemory/ProfileRepositoryTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ namespace LinkDotNet.Blog.UnitTests.Infrastructure.Persistence.InMemory
88
{
99
public class ProfileRepositoryTests
1010
{
11-
private readonly ProfileRepository ProfileRepository;
11+
private readonly ProfileRepository profileRepository;
1212

1313
public ProfileRepositoryTests()
1414
{
15-
ProfileRepository = new ProfileRepository();
15+
profileRepository = new ProfileRepository();
1616
}
1717

1818
[Fact]
1919
public async Task ShouldSaveAndRetrieveAllEntries()
2020
{
2121
var item1 = new ProfileInformationEntryBuilder().WithKey("key1").WithValue("value1").Build();
2222
var item2 = new ProfileInformationEntryBuilder().WithKey("key2").WithValue("value2").Build();
23-
await ProfileRepository.AddAsync(item1);
24-
await ProfileRepository.AddAsync(item2);
23+
await profileRepository.AddAsync(item1);
24+
await profileRepository.AddAsync(item2);
2525

26-
var items = await ProfileRepository.GetAllAsync();
26+
var items = await profileRepository.GetAllAsync();
2727

2828
items[0].Key.Should().Be("key1");
2929
items[0].Value.Should().Be("value1");
@@ -36,12 +36,12 @@ public async Task ShouldDelete()
3636
{
3737
var item1 = new ProfileInformationEntryBuilder().WithKey("key1").WithValue("value1").Build();
3838
var item2 = new ProfileInformationEntryBuilder().WithKey("key2").WithValue("value2").Build();
39-
await ProfileRepository.AddAsync(item1);
40-
await ProfileRepository.AddAsync(item2);
39+
await profileRepository.AddAsync(item1);
40+
await profileRepository.AddAsync(item2);
4141

42-
await ProfileRepository.DeleteAsync(item1.Id);
42+
await profileRepository.DeleteAsync(item1.Id);
4343

44-
var items = await ProfileRepository.GetAllAsync();
44+
var items = await profileRepository.GetAllAsync();
4545
items.Should().HaveCount(1);
4646
items[0].Id.Should().Be(item2.Id);
4747
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System.Collections.Generic;
2+
using Bunit;
3+
using FluentAssertions;
4+
using LinkDotNet.Blog.Web.Shared;
5+
using Xunit;
6+
7+
namespace LinkDotNet.Blog.UnitTests.Web.Shared
8+
{
9+
public class AddProfileShortItemTests : TestContext
10+
{
11+
[Fact]
12+
public void ShouldAddShortItem()
13+
{
14+
KeyValuePair<string, string> addedItem = default;
15+
var cut = RenderComponent<AddProfileShortItem>(
16+
p => p.Add(s => s.ValueAdded, pair => addedItem = pair));
17+
cut.FindAll("input")[0].Change("Key");
18+
cut.FindAll("input")[1].Change("Value");
19+
20+
cut.Find("button").Click();
21+
22+
addedItem.Key.Should().Be("Key");
23+
addedItem.Value.Should().Be("Value");
24+
}
25+
26+
[Theory]
27+
[InlineData("", "v")]
28+
[InlineData(" ", "v")]
29+
[InlineData(null, "v")]
30+
[InlineData("k", "")]
31+
[InlineData("k", " ")]
32+
[InlineData("k", null)]
33+
public void ShouldNotAddItemWhenKeyOrValueIsEmpty(string key, string value)
34+
{
35+
var wasInvoked = false;
36+
var cut = RenderComponent<AddProfileShortItem>(
37+
p => p.Add(s => s.ValueAdded, _ => wasInvoked = true));
38+
cut.FindAll("input")[0].Change(key);
39+
cut.FindAll("input")[1].Change(value);
40+
41+
cut.Find("button").Click();
42+
43+
wasInvoked.Should().BeFalse();
44+
}
45+
46+
[Fact]
47+
public void ShouldEmptyModelAfterTextEntered()
48+
{
49+
var cut = RenderComponent<AddProfileShortItem>();
50+
cut.FindAll("input")[0].Change("Key");
51+
cut.FindAll("input")[1].Change("Value");
52+
53+
cut.Find("button").Click();
54+
55+
cut.FindAll("input")[0].TextContent.Should().BeEmpty();
56+
cut.FindAll("input")[1].TextContent.Should().BeEmpty();
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)