Skip to content

Commit f5e57b3

Browse files
committed
Added tests
1 parent cc77c26 commit f5e57b3

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

LinkDotNet.Blog.Domain/Enumeration.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ namespace LinkDotNet.Blog.Domain
88
public abstract class Enumeration<TEnumeration>
99
where TEnumeration : Enumeration<TEnumeration>
1010
{
11-
private readonly string key;
12-
1311
protected Enumeration()
1412
{
1513
}
@@ -21,12 +19,12 @@ protected Enumeration(string key)
2119
throw new ArgumentException("The enum key cannot be null or empty");
2220
}
2321

24-
this.key = key;
22+
Key = key;
2523
}
2624

2725
public static IReadOnlyCollection<TEnumeration> All => GetEnumerations();
2826

29-
public string Key => key;
27+
public string Key { get; }
3028

3129
public static bool operator ==(Enumeration<TEnumeration> a, Enumeration<TEnumeration> b)
3230
{
@@ -35,7 +33,7 @@ protected Enumeration(string key)
3533
return false;
3634
}
3735

38-
return a.key.Equals(b.key);
36+
return a.Key.Equals(b.Key);
3937
}
4038

4139
public static bool operator !=(Enumeration<TEnumeration> a, Enumeration<TEnumeration> b)
@@ -45,7 +43,7 @@ protected Enumeration(string key)
4543

4644
public static TEnumeration Create(string key)
4745
{
48-
var enumeration = All.SingleOrDefault(p => p.key == key);
46+
var enumeration = All.SingleOrDefault(p => p.Key == key);
4947

5048
if (enumeration is null)
5149
{
@@ -69,7 +67,7 @@ public override bool Equals(object obj)
6967
return false;
7068
}
7169

72-
return (obj as TEnumeration).key == key;
70+
return ((TEnumeration)obj).Key == Key;
7371
}
7472

7573
public override string ToString() => Key;

LinkDotNet.Blog.IntegrationTests/Infrastructure/Persistence/RavenDb/BlogPostRepositoryTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ public async Task ShouldFilterAndOrder()
6565
retrievedPosts[1].Id.Should().Be(newerPost.Id);
6666
}
6767

68+
[Fact]
69+
public async Task ShouldSort()
70+
{
71+
var olderPost = new BlogPostBuilder().Build();
72+
var newerPost = new BlogPostBuilder().Build();
73+
await SaveBlogPostAsync(olderPost, newerPost);
74+
await sut.StoreAsync(olderPost);
75+
await sut.StoreAsync(newerPost);
76+
77+
var blogPosts = await sut.GetAllAsync(
78+
orderBy: bp => bp.UpdatedDate,
79+
descending: true);
80+
81+
var retrievedPosts = blogPosts.ToList();
82+
retrievedPosts[0].Id.Should().Be(newerPost.Id);
83+
retrievedPosts[1].Id.Should().Be(olderPost.Id);
84+
}
85+
6886
[Fact]
6987
public async Task ShouldSaveBlogPost()
7088
{

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ public async Task ShouldFilterAndOrder()
6464
retrievedPosts[1].Id.Should().Be(newerPost.Id);
6565
}
6666

67+
[Fact]
68+
public async Task ShouldGetAll()
69+
{
70+
var olderPost = new BlogPostBuilder().Build();
71+
var newerPost = new BlogPostBuilder().Build();
72+
var filteredOutPost = new BlogPostBuilder().WithTitle("FilterOut").Build();
73+
await sut.StoreAsync(olderPost);
74+
await sut.StoreAsync(newerPost);
75+
await sut.StoreAsync(filteredOutPost);
76+
77+
var blogPosts = await sut.GetAllAsync();
78+
79+
blogPosts.Count.Should().Be(3);
80+
}
81+
6782
[Fact]
6883
public async Task ShouldOrderDescending()
6984
{

0 commit comments

Comments
 (0)