Skip to content

Commit 83f8cfb

Browse files
authored
Merge pull request #3 from bitfaster/users/alexpeck/builder
builder
2 parents 6865c7a + 1b0cc48 commit 83f8cfb

File tree

13 files changed

+454
-42
lines changed

13 files changed

+454
-42
lines changed

.github/workflows/gate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ jobs:
2727
uses: coverallsapp/github-action@master
2828
with:
2929
github-token: ${{ secrets.GITHUB_TOKEN }}
30-
path-to-lcov: BitFaster.Caching.DependencyInjection.UnitTests/TestResults/coverage.info
30+
path-to-lcov: src/BitFaster.Caching.DependencyInjection.UnitTests/TestResults/coverage.info
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="coverlet.msbuild" Version="3.1.2">
13+
<PrivateAssets>all</PrivateAssets>
14+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
15+
</PackageReference>
16+
<PackageReference Include="FluentAssertions" Version="6.7.0" />
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
18+
<PackageReference Include="xunit" Version="2.4.1" />
19+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
20+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
21+
<PrivateAssets>all</PrivateAssets>
22+
</PackageReference>
23+
<PackageReference Include="coverlet.collector" Version="3.1.2">
24+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
25+
<PrivateAssets>all</PrivateAssets>
26+
</PackageReference>
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<ProjectReference Include="..\BitFaster.Caching.DependencyInjection\BitFaster.Caching.DependencyInjection.csproj" />
31+
</ItemGroup>
32+
33+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+

2+
namespace BitFaster.Caching.DependencyInjection.UnitTests
3+
{
4+
public class Disposable : IDisposable
5+
{
6+
public void Dispose()
7+
{
8+
throw new NotImplementedException();
9+
}
10+
}
11+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using BitFaster.Caching.Lfu;
2+
using FluentAssertions;
3+
using Microsoft.Extensions.DependencyInjection;
4+
5+
namespace BitFaster.Caching.DependencyInjection.UnitTests
6+
{
7+
public class LfuExtensionsTests
8+
{
9+
private IServiceCollection services = new TestServiceCollection();
10+
11+
[Fact]
12+
public void AddLfu()
13+
{
14+
services.AddLfu<int, int>(builder =>
15+
builder
16+
.WithCapacity(666)
17+
.Build());
18+
19+
services.Count.Should().Be(1);
20+
services[0].IsSingleton<ConcurrentLfu<int, int>, ICache<int, int>>();
21+
}
22+
23+
[Fact]
24+
public void AddAsyncLfu()
25+
{
26+
services.AddAsyncLfu<int, int>(builder =>
27+
builder
28+
.WithCapacity(666)
29+
.Build());
30+
31+
services.Count.Should().Be(1);
32+
services[0].IsSingleton<ConcurrentLfu<int, int>, IAsyncCache<int, int>>();
33+
}
34+
35+
[Fact]
36+
public void AddScopedLfu()
37+
{
38+
services.AddScopedLfu<int, Disposable>(builder =>
39+
builder
40+
.WithCapacity(666)
41+
.Build());
42+
43+
services.Count.Should().Be(1);
44+
services[0].IsSingleton<ScopedCache<int, Disposable>, IScopedCache<int, Disposable>>();
45+
}
46+
47+
[Fact]
48+
public void AddScopedAsyncLfu()
49+
{
50+
services.AddScopedAsyncLfu<int, Disposable>(builder =>
51+
builder
52+
.WithCapacity(666)
53+
.Build());
54+
55+
services.Count.Should().Be(1);
56+
services[0].IsSingleton<ScopedAsyncCache<int, Disposable>, IScopedAsyncCache<int, Disposable>>();
57+
}
58+
}
59+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using BitFaster.Caching.Lru;
2+
using FluentAssertions;
3+
using Microsoft.Extensions.DependencyInjection;
4+
5+
namespace BitFaster.Caching.DependencyInjection.UnitTests
6+
{
7+
public class LruExtensionsTests
8+
{
9+
private IServiceCollection services = new TestServiceCollection();
10+
11+
[Fact]
12+
public void AddLru()
13+
{
14+
services.AddLru<int, int>(builder =>
15+
builder
16+
.WithCapacity(666)
17+
.Build());
18+
19+
services.Count.Should().Be(1);
20+
services[0].IsSingleton<FastConcurrentLru<int, int>, ICache<int, int>>();
21+
}
22+
23+
[Fact]
24+
public void AddAsyncLru()
25+
{
26+
services.AddAsyncLru<int, int>(builder =>
27+
builder
28+
.WithCapacity(666)
29+
.Build());
30+
31+
services.Count.Should().Be(1);
32+
services[0].IsSingleton<FastConcurrentLru<int, int>, IAsyncCache<int, int>>();
33+
}
34+
35+
[Fact]
36+
public void AddScopedLru()
37+
{
38+
services.AddScopedLru<int, Disposable>(builder =>
39+
builder
40+
.WithCapacity(666)
41+
.Build());
42+
43+
services.Count.Should().Be(1);
44+
services[0].IsSingleton<ScopedCache<int, Disposable>, IScopedCache<int, Disposable>>();
45+
}
46+
47+
[Fact]
48+
public void AddScopedAsyncLru()
49+
{
50+
services.AddScopedAsyncLru<int, Disposable>(builder =>
51+
builder
52+
.WithCapacity(666)
53+
.Build());
54+
55+
services.Count.Should().Be(1);
56+
services[0].IsSingleton<ScopedAsyncCache<int, Disposable>, IScopedAsyncCache<int, Disposable>>();
57+
}
58+
}
59+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using BitFaster.Caching.Lru;
2+
using FluentAssertions;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace BitFaster.Caching.DependencyInjection.UnitTests
11+
{
12+
public static class ServiceDescriptorValidatorExtensions
13+
{
14+
public static void IsSingleton<TImpl, TSvc>(this ServiceDescriptor sd)
15+
{
16+
sd.ImplementationFactory.Should().BeNull();
17+
sd.ImplementationInstance.Should().BeOfType<TImpl>();
18+
sd.Lifetime.Should().Be(ServiceLifetime.Singleton);
19+
sd.ServiceType.Should().Be(typeof(TSvc));
20+
}
21+
}
22+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using System.Collections;
3+
4+
namespace BitFaster.Caching.DependencyInjection.UnitTests
5+
{
6+
internal class TestServiceCollection : IServiceCollection
7+
{
8+
private List<ServiceDescriptor> list = new List<ServiceDescriptor>();
9+
10+
public ServiceDescriptor this[int index] { get => this.list[index]; set => this.list[index] = value; }
11+
12+
public int Count => this.list.Count;
13+
14+
public bool IsReadOnly => false;
15+
16+
public void Add(ServiceDescriptor item)
17+
{
18+
this.list.Add(item);
19+
}
20+
21+
public void Clear()
22+
{
23+
this.list.Clear();
24+
}
25+
26+
public bool Contains(ServiceDescriptor item)
27+
{
28+
return this.list.Contains(item);
29+
}
30+
31+
public void CopyTo(ServiceDescriptor[] array, int arrayIndex)
32+
{
33+
throw new NotImplementedException();
34+
}
35+
36+
public IEnumerator<ServiceDescriptor> GetEnumerator()
37+
{
38+
return this.list.GetEnumerator();
39+
}
40+
41+
public int IndexOf(ServiceDescriptor item)
42+
{
43+
return this.list.IndexOf(item);
44+
}
45+
46+
public void Insert(int index, ServiceDescriptor item)
47+
{
48+
this.list.Insert(index, item);
49+
}
50+
51+
public bool Remove(ServiceDescriptor item)
52+
{
53+
return this.list.Remove(item);
54+
}
55+
56+
public void RemoveAt(int index)
57+
{
58+
this.list.RemoveAt(index);
59+
}
60+
61+
IEnumerator IEnumerable.GetEnumerator()
62+
{
63+
return this.list.GetEnumerator();
64+
}
65+
}
66+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global using Xunit;

src/BitFaster.Caching.DependencyInjection.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.3.32819.101
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitFaster.Caching.DependencyInjection", "BitFaster.Caching.DependencyInjection\BitFaster.Caching.DependencyInjection.csproj", "{337F4327-E35A-40F6-8A6C-7FA47A962D49}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BitFaster.Caching.DependencyInjection", "BitFaster.Caching.DependencyInjection\BitFaster.Caching.DependencyInjection.csproj", "{337F4327-E35A-40F6-8A6C-7FA47A962D49}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitFaster.Caching.DependencyInjection.UnitTests", "BitFaster.Caching.DependencyInjection.UnitTests\BitFaster.Caching.DependencyInjection.UnitTests.csproj", "{66A915E7-59AE-4D1E-B43F-33D344C3AC3F}"
79
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,6 +17,10 @@ Global
1517
{337F4327-E35A-40F6-8A6C-7FA47A962D49}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{337F4327-E35A-40F6-8A6C-7FA47A962D49}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{337F4327-E35A-40F6-8A6C-7FA47A962D49}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{66A915E7-59AE-4D1E-B43F-33D344C3AC3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{66A915E7-59AE-4D1E-B43F-33D344C3AC3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{66A915E7-59AE-4D1E-B43F-33D344C3AC3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{66A915E7-59AE-4D1E-B43F-33D344C3AC3F}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE

src/BitFaster.Caching.DependencyInjection/CacheExtensions.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)