Skip to content

Commit 96c5ad1

Browse files
committed
Added Tests for repositories
1 parent 3d01b42 commit 96c5ad1

File tree

6 files changed

+105
-3
lines changed

6 files changed

+105
-3
lines changed

LinkDotNet.Blog.IntegrationTests/Infrastructure/Persistence/Sql/SqlRepositoryTests.cs renamed to LinkDotNet.Blog.IntegrationTests/Infrastructure/Persistence/Sql/BlogPostRepositoryTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace LinkDotNet.Blog.IntegrationTests.Infrastructure.Persistence.Sql
1010
{
11-
public sealed class SqlRepositoryTests : SqlDatabaseTestBase
11+
public sealed class BlogPostRepositoryTests : SqlDatabaseTestBase
1212
{
1313
[Fact]
1414
public async Task ShouldLoadBlogPost()
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.Threading.Tasks;
2+
using FluentAssertions;
3+
using LinkDotNet.Blog.TestUtilities;
4+
using Xunit;
5+
6+
namespace LinkDotNet.Blog.IntegrationTests.Infrastructure.Persistence.Sql
7+
{
8+
public class ProfileRepositoryTests : SqlDatabaseTestBase
9+
{
10+
[Fact]
11+
public async Task ShouldSaveAndRetrieveAllEntries()
12+
{
13+
var item1 = new ProfileInformationEntryBuilder().WithKey("key1").WithValue("value1").Build();
14+
var item2 = new ProfileInformationEntryBuilder().WithKey("key2").WithValue("value2").Build();
15+
await ProfileRepository.AddAsync(item1);
16+
await ProfileRepository.AddAsync(item2);
17+
18+
var items = await ProfileRepository.GetAllAsync();
19+
20+
items[0].Key.Should().Be("key1");
21+
items[0].Value.Should().Be("value1");
22+
items[1].Key.Should().Be("key2");
23+
items[1].Value.Should().Be("value2");
24+
}
25+
26+
[Fact]
27+
public async Task ShouldDelete()
28+
{
29+
var item1 = new ProfileInformationEntryBuilder().WithKey("key1").WithValue("value1").Build();
30+
var item2 = new ProfileInformationEntryBuilder().WithKey("key2").WithValue("value2").Build();
31+
await ProfileRepository.AddAsync(item1);
32+
await ProfileRepository.AddAsync(item2);
33+
34+
await ProfileRepository.DeleteAsync(item1.Id);
35+
36+
var items = await ProfileRepository.GetAllAsync();
37+
items.Should().HaveCount(1);
38+
items[0].Id.Should().Be(item2.Id);
39+
}
40+
}
41+
}

LinkDotNet.Blog.IntegrationTests/SqlDatabaseTestBase.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ protected SqlDatabaseTestBase()
1717
.Options;
1818
DbContext = new BlogDbContext(options);
1919
BlogPostRepository = new BlogPostRepository(new BlogDbContext(options));
20+
ProfileRepository = new ProfileRepository(new BlogDbContext(options));
2021
}
2122

2223
protected BlogPostRepository BlogPostRepository { get; }
2324

25+
protected ProfileRepository ProfileRepository { get; }
26+
2427
protected BlogDbContext DbContext { get; }
2528

2629
public Task InitializeAsync()

LinkDotNet.Blog.UnitTests/Domain/ProfileInformationEntryTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,14 @@ public void ShouldThrowExceptionWhenEmptyKeyOrValue(string key, string value)
2929

3030
act.Should().Throw<ArgumentOutOfRangeException>();
3131
}
32+
33+
[Fact]
34+
public void ShouldTrim()
35+
{
36+
var result = ProfileInformationEntry.Create(" key ", " value ");
37+
38+
result.Key.Should().Be("key");
39+
result.Value.Should().Be("value");
40+
}
3241
}
3342
}

LinkDotNet.Blog.UnitTests/Infrastructure/Persistence/InMemory/InMemoryRepositoryTests.cs renamed to LinkDotNet.Blog.UnitTests/Infrastructure/Persistence/InMemory/BlogPostRepositoryTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
namespace LinkDotNet.Blog.UnitTests.Infrastructure.Persistence.InMemory
99
{
10-
public class InMemoryRepositoryTests
10+
public class BlogPostRepositoryTests
1111
{
1212
private readonly BlogPostRepository sut;
1313

14-
public InMemoryRepositoryTests()
14+
public BlogPostRepositoryTests()
1515
{
1616
sut = new BlogPostRepository();
1717
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System.Threading.Tasks;
2+
using FluentAssertions;
3+
using LinkDotNet.Blog.TestUtilities;
4+
using LinkDotNet.Infrastructure.Persistence.InMemory;
5+
using Xunit;
6+
7+
namespace LinkDotNet.Blog.UnitTests.Infrastructure.Persistence.InMemory
8+
{
9+
public class ProfileRepositoryTests
10+
{
11+
private readonly ProfileRepository ProfileRepository;
12+
13+
public ProfileRepositoryTests()
14+
{
15+
ProfileRepository = new ProfileRepository();
16+
}
17+
18+
[Fact]
19+
public async Task ShouldSaveAndRetrieveAllEntries()
20+
{
21+
var item1 = new ProfileInformationEntryBuilder().WithKey("key1").WithValue("value1").Build();
22+
var item2 = new ProfileInformationEntryBuilder().WithKey("key2").WithValue("value2").Build();
23+
await ProfileRepository.AddAsync(item1);
24+
await ProfileRepository.AddAsync(item2);
25+
26+
var items = await ProfileRepository.GetAllAsync();
27+
28+
items[0].Key.Should().Be("key1");
29+
items[0].Value.Should().Be("value1");
30+
items[1].Key.Should().Be("key2");
31+
items[1].Value.Should().Be("value2");
32+
}
33+
34+
[Fact]
35+
public async Task ShouldDelete()
36+
{
37+
var item1 = new ProfileInformationEntryBuilder().WithKey("key1").WithValue("value1").Build();
38+
var item2 = new ProfileInformationEntryBuilder().WithKey("key2").WithValue("value2").Build();
39+
await ProfileRepository.AddAsync(item1);
40+
await ProfileRepository.AddAsync(item2);
41+
42+
await ProfileRepository.DeleteAsync(item1.Id);
43+
44+
var items = await ProfileRepository.GetAllAsync();
45+
items.Should().HaveCount(1);
46+
items[0].Id.Should().Be(item2.Id);
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)