Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ jobs:
- name: Install .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x
- name: Install Codecov
run: choco install codecov -y
- name: Build and test ServicePool
run: dotnet test $env:Solution_Name --configuration=$env:Configuration --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
run: dotnet test $env:Solution_Name --configuration=$env:Configuration --collect:"XPlat Code Coverage" --results-directory .\Build\tests -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
- name: Upload code coverage report
run: codecov -f "$((ls .\src\ServicePool.Tests\TestResults -Directory)[0].Fullname)\coverage.opencover.xml"
run: foreach ($j in (ls .\Build\tests\ -Directory)) { codecov -f "$($j.FullName)\coverage.opencover.xml" }
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Create NuGet Packages
run: dotnet pack $env:Solution_Name --configuration=$env:Configuration --version-suffix=$env:GITHUB_SHA --include-source -p:RepositoryBranch=${{ github.ref }} -p:ContinuousIntegrationBuild=true
run: dotnet pack $env:Solution_Name --configuration=$env:Configuration --version-suffix=$env:GITHUB_SHA --include-source -p:RepositoryBranch=${{ github.ref }} -p:RepositoryCommit=${{ github.sha }} -p:ContinuousIntegrationBuild=true
- uses: actions/upload-artifact@v3
with:
name: ServicePool-nuget-packages
path: Build/Bin/**/*.nupkg
path: Build/Bin/**/*.nupkg
14 changes: 4 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,10 @@ jobs:
- name: Install .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Get tag name
uses: olegtarasov/get-tag@v2.1.2
dotnet-version: 8.0.x
- name: Create NuGet Packages
run: dotnet pack $env:Solution_Name --configuration=$env:Configuration -p:Version=$env:GIT_TAG_NAME -p:RepositoryBranch=${{ github.ref }} -p:ContinuousIntegrationBuild=true
run: dotnet pack $env:Solution_Name --configuration=${{ env.Configuration }} -p:Version=${{ github.ref_name }} -p:RepositoryBranch=${{ github.ref }} -p:RepositoryCommit=${{ github.sha }} -p:ContinuousIntegrationBuild=true
- name: Push packages to GitHub
run: dotnet nuget push "Build/**/*.nupkg" -k $env:GhToken --skip-duplicate --source "https://nuget.pkg.github.com/TheXDS/"
env:
GhToken: ${{ secrets.GITHUB_TOKEN }}
run: dotnet nuget push "Build/**/*.nupkg" -k ${{ secrets.GITHUB_TOKEN }} --skip-duplicate --source "https://nuget.pkg.github.com/TheXDS/"
- name: Push packages to NuGet
run: dotnet nuget push "Build/**/*.nupkg" -k $env:NgToken --skip-duplicate --source "https://api.nuget.org/v3/index.json"
env:
NgToken: ${{ secrets.NUGET_TOKEN }}
run: dotnet nuget push "Build/**/*.nupkg" -k ${{ secrets.NUGET_TOKEN }} --skip-duplicate --source "https://api.nuget.org/v3/index.json"
2 changes: 1 addition & 1 deletion BuildTargets/CompileOptions.targets
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
</ItemGroup>
</Project>
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,22 @@ The resulting binaries will be in the `./Build/bin` directory.
```sh
dotnet test ./src/ServicePool.sln
```
#### Coverage reports
It is possible to generate a coverage report locally.For that, it is necessary to install [`ReportGenerator`](https://github.com/danielpalme/ReportGenerator), which will read the test results after execution, and will generate a web page with the coverage results.

To install `ReportGenerator` execute:
```sh
dotnet tool install -g dotnet-reportgenerator-globaltool
```
After installing `ReportGenerator`, it will be possible to execute the following command:
```sh
dotnet test ./src/ServicePool.sln --collect:"XPlat Code Coverage" --results-directory:./Build/Tests ; reportgenerator -reports:./Build/Tests/*/coverage.cobertura.xml -targetdir:./Build/Coverage/
```
The coverage reports will be stored in `./Build/Coverage`

## Contribute
If you think that ServicePool is useful, consider making a donation via
[PayPal](https://paypal.me/thexds), or contact me directly.
[![Buy Me A Coffee](https://cdn.buymeacoffee.com/buttons/default-orange.png)](https://www.buymeacoffee.com/xdsxpsivx)

If `ServicePool` is useful to you, or if you're interested in donating to sponsor the project, feel free to to a donation via [PayPal](https://paypal.me/thexds), [BuyMeACoffee](https://www.buymeacoffee.com/xdsxpsivx) or just contact me directly.

Sadly, I cannot offer any other donation methods, as my country (Honduras) is not supported on any platform. Not even PayPal supports donations per-se to people in Honduras, but at least I have an account there.
Sadly, I cannot offer other means of sending donations as of right now due to my country (Honduras) not being supported by almost any platform.
8 changes: 4 additions & 4 deletions src/ServicePool.Tests/AssemblyListDiscoveryEngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void Engine_supports_add()
{
a
};
Assert.Contains(a, e);
Assert.That(e, Contains.Item(a));
}

[Test]
Expand All @@ -53,7 +53,7 @@ public void Engine_supports_insert()
var a = Assembly.GetExecutingAssembly();
var e = new AssemblyListDiscoveryEngine();
e.Insert(0, a);
Assert.Contains(a, e);
Assert.That(e, Contains.Item(a));
}

[Test]
Expand All @@ -63,8 +63,8 @@ public void Engine_supports_set()
var b = typeof(object).Assembly;
var e = new AssemblyListDiscoveryEngine { a };
e[0] = b;
Assert.False(e.Contains(a));
Assert.Contains(b, e);
Assert.That(e, Does.Not.Contain(a));
Assert.That(e, Contains.Item(b));
}

[Test]
Expand Down
22 changes: 11 additions & 11 deletions src/ServicePool.Tests/CommonExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,32 @@

namespace TheXDS.ServicePool.Tests;

public class CommonExtensionsTests
public abstract class CommonExtensionsTests<T> where T : PoolBase, new()
{
[Test]
public void RegisterInto_registers_singleton()
{
var pool = new ServicePool();
var pool = new T();
var x = new Random().RegisterInto(pool);
Assert.IsInstanceOf<Random>(x);
Assert.AreSame(x, pool.Resolve<Random>());
Assert.That(x, Is.InstanceOf<Random>());
Assert.That(pool.Resolve<Random>(), Is.SameAs(x));
}

[Test]
public void RegisterIntoIf_registers_if_true()
{
var pool = new ServicePool();
var pool = new Pool();
var x = new Random().RegisterIntoIf(pool, true);
Assert.IsInstanceOf<Random>(x);
Assert.AreSame(x, pool.Resolve<Random>());
Assert.That(x, Is.InstanceOf<Random>());
Assert.That(pool.Resolve<Random>(), Is.SameAs(x));
}

[Test]
public void RegisterIntoIf_returns_null_if_false()
public void RegisterIntoIf_returns_object_if_false()
{
var pool = new ServicePool();
var pool = new FlexPool();
var x = new Random().RegisterIntoIf(pool, false);
Assert.IsNull(x);
Assert.IsNull(pool.Resolve<Random>());
Assert.That(x, Is.InstanceOf<Random>());
Assert.That(pool.Resolve<Random>(), Is.Null);
}
}
47 changes: 47 additions & 0 deletions src/ServicePool.Tests/DefaultDiscoveryEngineTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// AssemblyListDiscoveryEngineTests.cs
//
// This file is part of ServicePool
//
// Author(s):
// César Andrés Morgan <xds_xps_ivx@hotmail.com>
//
// Released under the MIT License (MIT)
// Copyright © 2011 - 2023 César Andrés Morgan
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the “Software”), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#pragma warning disable CS1591

using NUnit.Framework;
using System;
using System.Collections;
using System.Linq;

namespace TheXDS.ServicePool.Tests;

public class DefaultDiscoveryEngineTests
{
[Test]
public void Engine_resolves_base_type()
{
var engine = new DefaultDiscoveryEngine();
var types = engine.Discover(typeof(Exception)).ToArray();
Assert.That(types.Length, Is.GreaterThan(50));
}
}
33 changes: 33 additions & 0 deletions src/ServicePool.Tests/FlexPoolExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// FlexPoolExtensionsTests.cs
//
// This file is part of ServicePool
//
// Author(s):
// César Andrés Morgan <xds_xps_ivx@hotmail.com>
//
// Released under the MIT License (MIT)
// Copyright © 2011 - 2022 César Andrés Morgan
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the “Software”), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#pragma warning disable CS1591

namespace TheXDS.ServicePool.Tests;

public class FlexPoolExtensionsTests : CommonExtensionsTests<FlexPool> { }
121 changes: 121 additions & 0 deletions src/ServicePool.Tests/FlexPoolTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// FlexPoolTests.cs
//
// This file is part of ServicePool
//
// Author(s):
// César Andrés Morgan <xds_xps_ivx@hotmail.com>
//
// Released under the MIT License (MIT)
// Copyright © 2011 - 2022 César Andrés Morgan
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the “Software”), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#pragma warning disable CS1591

using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using TheXDS.ServicePool.Extensions;
using TheXDS.ServicePool.TestTypes;

namespace TheXDS.ServicePool.Tests;

public class FlexPoolTests : PoolBaseTests<FlexPool>
{
[Test]
public void Resolve_resolves_for_interfaces()
{
FlexPool? pool = new();
pool.Register<Test1>();
Assert.That(pool.Resolve<ITest>(), Is.Not.Null);
}

[Test]
public void Resolve_resolves_for_base_class()
{
FlexPool? pool = new();
pool.Register<Test3>();
Assert.That(pool.Resolve<Test1>(), Is.Not.Null);
}

[Test]
public void Discover_searches_for_service()
{
FlexPool? pool = new();
Assert.That(pool.Discover<Random>(), Is.InstanceOf<Random>());
Assert.That(pool.Count, Is.EqualTo(1));
}

[Test]
public void Discover_returns_from_active_services()
{
FlexPool? pool = new();
pool.Register<Random>();
var r = pool.Resolve<Random>();
Assert.That(pool.Discover<Random>(), Is.SameAs(r));
}

[Test]
public void ResolveAll_returns_collection()
{
FlexPool pool = new();
pool.RegisterNow(new List<int>());
pool.RegisterNow(new Collection<int>());
pool.RegisterNow(Array.Empty<int>());
Assert.That(pool.ResolveAll<IEnumerable<int>>().Count(), Is.EqualTo(3));
}

[Test]
public void DiscoverAll_enumerates_all_types_that_implement_base_type()
{
FlexPool pool = new();
Assert.That(pool.DiscoverAll<ITest>().ToArray().Length, Is.EqualTo(3));
}

[Test]
public void DiscoverAll_skips_existing_services()
{
FlexPool pool = new();
pool.RegisterNow<Test1>();
var t1 = pool.Resolve<Test1>();
ITest[] c = pool.DiscoverAll<ITest>().ToArray();
Assert.That(c.Length, Is.EqualTo(3));
Assert.That(c[0], Is.SameAs(t1));
Assert.That(c[1], Is.InstanceOf<Test2>());
Assert.That(c[2], Is.InstanceOf<Test3>());
}

[Test]
public void DiscoverAll_allows_specifying_engine()
{
FlexPool pool = new();
ITest[] c = pool.DiscoverAll<ITest>(new DefaultDiscoveryEngine()).ToArray();
Assert.That(c.Length, Is.EqualTo(3));
}

[Test]
public void Discover_allows_specifying_engine()
{
FlexPool pool = new();
var c = pool.Discover<ITest>(new DefaultDiscoveryEngine());
Assert.That(c, Is.Not.Null);
}
}
Loading