Skip to content

Commit

Permalink
Dependency update and enabling testing and code coverage through Gith…
Browse files Browse the repository at this point in the history
…ub Actions
  • Loading branch information
MarkCiliaVincenti committed Jan 1, 2024
1 parent b2e8f2e commit 3b92481
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 13 deletions.
24 changes: 20 additions & 4 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,28 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x

- name: Restore dependencies
run: dotnet restore

- name: App Settings Variable Substitution
uses: microsoft/variable-substitution@v1
with:
files: '${{env.DOTNET_ROOT}}/OpenWeatherMap.Cache.Tests/appsettings.json'
env:
apiKey: ${{ secrets.API_KEY }}

- name: Build
run: dotnet build --no-restore
run: dotnet build --no-restore --configuration Release

- name: Test
run: dotnet test --no-restore --configuration Release --verbosity normal --collect:"XPlat Code Coverage" --settings coverlet.runsettings

- name: Coverage
uses: codecov/codecov-action@v3
10 changes: 9 additions & 1 deletion OpenWeatherMap.Cache.Tests/OpenWeatherMap.Cache.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.4" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
Expand All @@ -23,4 +25,10 @@
<ProjectReference Include="..\OpenWeatherMap.Cache\OpenWeatherMap.Cache.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
15 changes: 11 additions & 4 deletions OpenWeatherMap.Cache.Tests/Tests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Microsoft.Extensions.Configuration;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -7,7 +8,13 @@ namespace OpenWeatherMap.Cache.Tests
{
public class Tests
{
private const string apiKey = "[API Key]";
private string _apiKey;

public Tests()
{
var config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
_apiKey = config["apiKey"];
}

[Fact]
public async Task TestConcurrency()
Expand All @@ -16,7 +23,7 @@ public async Task TestConcurrency()
int concurrency = 100;
int tries = 5;

var openWeatherMapCache = new OpenWeatherMapCache(apiKey, apiCachePeriod);
var openWeatherMapCache = new OpenWeatherMapCache(_apiKey, apiCachePeriod);
int totalFromCache = 0;
int totalFromAPI = 0;
int totalSuccessful = 0;
Expand Down Expand Up @@ -56,15 +63,15 @@ public async Task TestConcurrency()
}
}
}

[Fact]
public async Task TestConcurrencyAsync()
{
int apiCachePeriod = 1_000;
int concurrency = 100;
int tries = 5;

var openWeatherMapCache = new OpenWeatherMapCache(apiKey, apiCachePeriod);
var openWeatherMapCache = new OpenWeatherMapCache(_apiKey, apiCachePeriod);
int totalFromCache = 0;
int totalFromAPI = 0;
int totalSuccessful = 0;
Expand Down
3 changes: 3 additions & 0 deletions OpenWeatherMap.Cache.Tests/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"apiKey": "[API Key]"
}
8 changes: 4 additions & 4 deletions OpenWeatherMap.Cache/OpenWeatherMap.Cache.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
<PackageProjectUrl>https://github.com/MarkCiliaVincenti/OpenWeatherMap.Cache</PackageProjectUrl>
<Copyright>MIT</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Version>1.9.13</Version>
<Version>1.9.14</Version>
<PackageIcon>logo.png</PackageIcon>
<PackageReleaseNotes>Dependency update.</PackageReleaseNotes>
<Description>An asynchronous .NET Standard 2.0 library that allows you to fetch &amp; cache current weather readings from the OpenWeather API, with built-in resiliency that can extend the cache lifetime in case the API is unreachable.</Description>
<Copyright>© 2023 Mark Cilia Vincenti</Copyright>
<PackageTags>OpenWeather,OpenWeatherMap,cache,weather,API,.NET Standard,netstandard</PackageTags>
<RepositoryType>git</RepositoryType>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<AssemblyVersion>1.9.13.0</AssemblyVersion>
<FileVersion>1.9.13.0</FileVersion>
<AssemblyVersion>1.9.14.0</AssemblyVersion>
<FileVersion>1.9.14.0</FileVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
<IsPackable>true</IsPackable>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
Expand All @@ -34,7 +34,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AsyncKeyedLock" Version="6.2.5" />
<PackageReference Include="AsyncKeyedLock" Version="6.2.6" />
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="UnitsNet" Version="5.41.0" />
</ItemGroup>
Expand Down
22 changes: 22 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Documentation: https://docs.codecov.io/docs/codecov-yaml

codecov:
# Avoid "Missing base report"
# https://github.com/codecov/support/issues/363
# https://docs.codecov.io/docs/comparing-commits
allow_coverage_offsets: true

# Avoid Report Expired
# https://docs.codecov.io/docs/codecov-yaml#section-expired-reports
max_report_age: off

coverage:
# Use integer precision
# https://docs.codecov.com/docs/codecovyml-reference#coverageprecision
precision: 0

# Explicitly control coverage status checks
# https://docs.codecov.com/docs/commit-status#disabling-a-status
status:
project: on
patch: off
18 changes: 18 additions & 0 deletions coverlet.runsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
<MaxCpuCount>0</MaxCpuCount>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<Format>cobertura</Format>
<Include>[OpenWeatherMap.Cache*]*</Include>
<Exclude>[*.Tests]*</Exclude>
<ExcludeByAttribute>Obsolete,GeneratedCodeAttribute,CompilerGeneratedAttribute</ExcludeByAttribute>
<IncludeTestAssembly>false</IncludeTestAssembly>
<SkipAutoProps>true</SkipAutoProps>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>

0 comments on commit 3b92481

Please sign in to comment.