Skip to content

Commit

Permalink
Updating packages, adding in memory nuget tests
Browse files Browse the repository at this point in the history
  • Loading branch information
calebjenkins committed Dec 27, 2023
1 parent 068868c commit 3b68dad
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/KeyValueRepo.Benchmarks/KeyValueRepo.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.11" />
<PackageReference Include="Moq" Version="4.20.70" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/KeyValueRepo/KeyValueRepo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Calebs.Extensions" Version="1.2.0-ci-39" />
<PackageReference Include="Calebs.Extensions" Version="1.5.0-ci-62" />
<None Include="..\..\LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
Expand Down
8 changes: 4 additions & 4 deletions src/KeyValueRepoTests/KeyValueRepoTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.1" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="WestDiscGolf.MoqExtensions" Version="1.0.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="xunit" Version="2.6.4" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions src/KeyValueSqlLiteRepo/KeyValueSqlLiteRepo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@


<ItemGroup>
<PackageReference Include="Calebs.Extensions" Version="1.2.0-ci-39" />
<PackageReference Include="Calebs.KeyValueRepo" Version="0.2.0-ci-3" />
<PackageReference Include="Calebs.Extensions" Version="1.5.0-ci-62" />
<PackageReference Include="Calebs.KeyValueRepo" Version="0.2.0-ci-9" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.5" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<None Include="..\..\LICENSE">
Expand Down
89 changes: 89 additions & 0 deletions src/Tests.NugetSample/InMemeoryTests.cs
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

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 24 in src/Tests.NugetSample/InMemeoryTests.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
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);
17 changes: 10 additions & 7 deletions src/Tests.NugetSample/Tests.NugetSample.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -9,15 +9,18 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Calebs.KeyValueRepo" Version="0.1.0" />
<PackageReference Include="FluentAssertions" Version="6.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Calebs.Extensions" Version="1.5.0-ci-62" />
<PackageReference Include="Calebs.KeyValueRepo" Version="0.2.0-ci-9" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.1" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="xunit" Version="2.6.4" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
4 changes: 4 additions & 0 deletions src/Tests.NugetSample/Usings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
global using Xunit;
global using Xunit.Abstractions;
global using FluentAssertions;
global using Calebs.Data.KeyValueRepo;
global using Moq;
global using Microsoft.Extensions.Logging;
global using System.Diagnostics;

// nuget tests are on hold moving from 0.1.0 to 0.2.0
// These are breaking changes from exisisting nuget package moving to Task Async
Expand Down

0 comments on commit 3b68dad

Please sign in to comment.