-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updating packages, adding in memory nuget tests
- Loading branch information
1 parent
068868c
commit 3b68dad
Showing
7 changed files
with
112 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
|
||
namespace KeyValueRepoTests; | ||
|
||
[Collection("RepoTests")] | ||
public class InMemeoryTests{ | ||
|
||
public virtual IKeyValueRepo GetNewRepo() | ||
{ | ||
return new KeyValueInMemory(); | ||
} | ||
|
||
[Fact] | ||
public async Task RepoShouldHoldValues() | ||
{ | ||
IKeyValueRepo repo = GetNewRepo(); | ||
var p = new Person("Test", "Last", 1); | ||
|
||
await repo.Update(p.Id.ToString(), p); | ||
|
||
var p2 = await repo.Get<Person>("1"); | ||
p2.Should().NotBeNull(); | ||
p2?.First.Should().Be("Test"); | ||
|
||
var p3 = p2 with { First = "Test2" }; | ||
Check warning on line 24 in src/Tests.NugetSample/InMemeoryTests.cs GitHub Actions / build
|
||
await repo.Update(p3.Id.ToString(), p3); | ||
|
||
var p4 = await repo.Get<Person>(1); | ||
p4?.First.Should().Be("Test2"); | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldReturnVoidForUnknownTypes() | ||
{ | ||
IKeyValueRepo repo = GetNewRepo(); | ||
var p = await repo.Get<Person>("1"); | ||
|
||
p.Should().BeNull(); | ||
} | ||
|
||
[Fact] | ||
public async Task MissingIdShouldReturnNull() | ||
{ | ||
IKeyValueRepo repo = GetNewRepo(); | ||
var p1 = new Person("Kelly", "Burkhardt", 1); | ||
await repo.Update(p1.Id, p1); | ||
|
||
var p2 = await repo.Get<Person>(1); | ||
p2.Should().NotBeNull(); | ||
|
||
var randomId = Guid.NewGuid().ToString().Substring(0, 8); | ||
var p3 = await repo.Get<Person>(randomId); | ||
p3.Should().BeNull(); | ||
} | ||
|
||
[Fact] | ||
public async Task GetAllShouldReturnAllInstances() | ||
{ | ||
IKeyValueRepo repo = GetNewRepo(); | ||
var p1 = new Person("Kelly", "Burkhardt", 1); | ||
var p2 = new Person("Drew", "Wu", 2); | ||
var p3 = new Person("Monroe", "", 3); | ||
|
||
await repo.Update(p1.Id, p1); | ||
await repo.Update(p2.Id, p2); | ||
await repo.Update(p3.Id.ToString(), p3); | ||
|
||
var people = await repo.GetAll<Person>(); | ||
people.Count.Should().BeGreaterThanOrEqualTo(3); // Repo holds 4th record from previous test runs | ||
// Either need to fully reset DB each time or maybe add a Remove / RemoveAll methods | ||
|
||
var l1 = new Location("1", "123 Main", "Dallas"); | ||
var l2 = new Location("2", "456 Front St.", "Tulsa"); | ||
|
||
await repo.Update(l1.Id, l1); | ||
await repo.Update(l2.Id, l2); | ||
|
||
var p4 = new Person("Nick", "Burkhardt", 4); | ||
await repo.Update(p4.Id.ToString(), p4); | ||
|
||
people = await repo.GetAll<Person>(); | ||
var locals = await repo.GetAll<Location>(); | ||
|
||
people.Count().Should().BeGreaterThanOrEqualTo(4); | ||
locals.Count().Should().BeGreaterThanOrEqualTo(2); | ||
} | ||
} | ||
|
||
public record Person (string First, string Last, int Id); | ||
public record Location (string Id, string Street, string City); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters