-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding missing integration test and new features to tests * Fix mocking * Add memory repository tests * Add new tests to sln file * More tests * Export code coverage from what's visible in E2E tests (not perfect but still a gain) * PlatformService tests * Add 403s to translation integration tests * Add 403sto webhooks tests * Remove unused code
- Loading branch information
Showing
12 changed files
with
370 additions
and
191 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,76 @@ | ||
namespace SIL.DataAccess; | ||
|
||
[TestFixture] | ||
public class MemoryRepositoryTests | ||
{ | ||
[Test] | ||
public async Task AddAndRemove() | ||
{ | ||
var mr = new MemoryRepository<IntegerEntity>(); | ||
mr.Init(); | ||
mr.Add(new IntegerEntity(1) { Id = "1" }); | ||
var entityToRemove = new IntegerEntity(2) { Id = "2" }; | ||
mr.Add(entityToRemove); | ||
mr.Remove(entityToRemove); | ||
Assert.That((await mr.GetAllAsync(_ => true)).Count, Is.EqualTo(1)); | ||
IntegerEntity entity = mr.Get("1"); | ||
Assert.That(entity.Value, Is.EqualTo(1)); | ||
mr.Add( | ||
new IntegerEntity[] | ||
{ | ||
new IntegerEntity(1) { Id = "3" }, | ||
new IntegerEntity(2) { Id = "4" } | ||
} | ||
); | ||
Assert.That((await mr.GetAllAsync(_ => true)).Count, Is.EqualTo(3)); | ||
Assert.That(await mr.ExistsAsync(entity => entity.Value == 2)); | ||
} | ||
|
||
[Test] | ||
public async Task InsertAndUpdate() | ||
{ | ||
var mr = new MemoryRepository<IntegerEntity>(); | ||
mr.Init(); | ||
await mr.InsertAllAsync( | ||
new IntegerEntity[] | ||
{ | ||
new IntegerEntity(1) { Id = "1" }, | ||
new IntegerEntity(2) { Id = "2" } | ||
} | ||
); | ||
Assert.ThrowsAsync<DuplicateKeyException>(async () => | ||
{ | ||
await mr.InsertAllAsync( | ||
new IntegerEntity[] | ||
{ | ||
new IntegerEntity(1) { Id = "1" }, | ||
new IntegerEntity(2) { Id = "2" } | ||
} | ||
); | ||
}); | ||
Assert.That((await mr.GetAllAsync(_ => true)).Count, Is.EqualTo(2)); | ||
await mr.UpdateAsync(e => e.Id == "0", e => e.Set(r => r.Value, 0), upsert: true); | ||
Assert.That((await mr.GetAllAsync(_ => true)).Count, Is.EqualTo(3)); | ||
await mr.UpdateAsync(e => e.Id == "0", e => e.Set(r => r.Value, 100)); | ||
Assert.That((await mr.GetAllAsync(_ => true)).Count, Is.EqualTo(3)); | ||
Assert.That(mr.Get("0").Value, Is.EqualTo(100)); | ||
await mr.UpdateAsync(e => e.Id == "1", e => e.Set(r => r.Value, 100)); | ||
await mr.UpdateAllAsync(e => e.Value == 100, e => e.Set(r => r.Value, -100)); | ||
Assert.That(mr.Get("0").Value, Is.EqualTo(-100)); | ||
Assert.That(mr.Get("1").Value, Is.EqualTo(-100)); | ||
} | ||
|
||
private class IntegerEntity : IEntity | ||
{ | ||
public string Id { get; set; } = default!; | ||
public int Revision { get; set; } = 1; | ||
public int Value { get; set; } | ||
|
||
public IntegerEntity(int value) | ||
{ | ||
Value = value; | ||
} | ||
|
||
public IntegerEntity() { } | ||
} | ||
} |
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,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
<RootNamespace>SIL.DataAccess</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" /> | ||
<PackageReference Include="NSubstitute" Version="5.0.0" /> | ||
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.16"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="NUnit" Version="3.13.3" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" /> | ||
<PackageReference Include="NUnit.Analyzers" Version="3.6.1"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\SIL.DataAccess\SIL.DataAccess.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.