Skip to content
Closed
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
100 changes: 100 additions & 0 deletions .github/workflows/nuget-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: NuGet Pipeline

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
permissions:
checks: write # required by dorny/test-reporter
pull-requests: write # required for PR comments
strategy:
matrix:
dotnet-version: ['9.0.x']

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Required for GitVersion

- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v3.1.11
with:
versionSpec: '6.0.x'

- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v3.1.11
with:
useConfigFile: true

- name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet-version }}
source-url: https://pkgs.dev.azure.com/elemdisc/Elem/_packaging/elemd/nuget/v3/index.json
env:
NUGET_AUTH_TOKEN: ${{ secrets.AZURE_ARTIFACTS_PAT }}

- name: Install dependencies
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore /p:Version=${{ steps.gitversion.outputs.semVer }}

- name: Test
run: |
dotnet test --no-restore --verbosity normal \
--logger "trx;LogFileName=test-results.trx" \
--collect:"XPlat Code Coverage" \
--results-directory TestResults \
QueryKit.UnitTests/QueryKit.UnitTests.csproj

dotnet test --no-restore --verbosity normal \
--logger "trx;LogFileName=integration-results.trx" \
--collect:"XPlat Code Coverage" \
--results-directory TestResults \
QueryKit.IntegrationTests/QueryKit.IntegrationTests.csproj

dotnet test --no-restore --verbosity normal \
--logger "trx;LogFileName=marten-results.trx" \
--collect:"XPlat Code Coverage" \
--results-directory TestResults \
QueryKit.MartenTests/QueryKit.MartenTests.csproj

- name: Test Report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: .NET Test Results
path: "TestResults/*.trx" # will find all .trx files
reporter: dotnet-trx

- name: Code Coverage Report
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: "TestResults/**/coverage.cobertura.xml" # will find all coverage files
badge: true
format: markdown
output: both
# Optional: fail if coverage is below a threshold
# fail_below_min: true
# minimum_coverage: 80

- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
path: code-coverage-results.md

- name: Pack
run: dotnet pack --configuration Release --no-build --output nupkgs /p:Version=${{ steps.gitversion.outputs.semVer }}

- name: Push Package
run: dotnet nuget push "./nupkgs/*.nupkg" --api-key AzureDevOps --skip-duplicate

3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.formatOnSave": false
}
58 changes: 58 additions & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
workflow: GitHubFlow/v1
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
tag-prefix: '[vV]?'
version-in-branch-pattern: (?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*
major-version-bump-message: (\+)?semver:\s?(breaking|major)
minor-version-bump-message: (\+)?semver:\s?(feature|minor)
patch-version-bump-message: (\+)?semver:\s?(fix|patch)
no-bump-message: (\+)?semver:\s?(none|skip)
commit-date-format: yyyy-MM-dd
merge-message-formats: {}
update-build-number: true
semantic-version-format: Strict
strategies:
- ConfiguredNextVersion
- Mainline
branches:
main:
mode: ContinuousDeployment
label: ''
increment: Patch
prevent-increment:
of-merged-branch: true
track-merge-target: false
track-merge-message: true
regex: ^master$|^main$
source-branches: []
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-main-branch: true
feature:
mode: ContinuousDelivery
label: '{BranchName}'
increment: Patch
prevent-increment:
when-current-commit-tagged: false
track-merge-message: true
regex: ^(?<BranchName>.+)
source-branches:
- main
- release
is-source-branch-for: []
is-main-branch: false
pull-request:
mode: ContinuousDelivery
label: PullRequest
increment: Inherit
prevent-increment:
of-merged-branch: true
when-current-commit-tagged: false
label-number-pattern: '[/-](?<number>\d+)'
track-merge-message: true
regex: ^((refs\/)?pull|pull\-requests|pr)[/-]
source-branches:
- main
- feature
is-source-branch-for: []
32 changes: 32 additions & 0 deletions QueryKit.MartenTests/Documents/TestDocument.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace QueryKit.MartenTests.Documents;

public class TestDocument
{
public Guid Id { get; set; }
public string Title { get; set; }
public Guid? RelatedId { get; set; }
public Guid[] AdditionalIds { get; set; } = [];
public Guid[]? NullableAdditionalIds { get; set; }
public decimal Rating { get; set; }
public int Age { get; set; }
public BirthMonthEnum BirthMonth { get; set; }
public DateTimeOffset? SpecificDate { get; set; }
public DateOnly? Date { get; set; }
public TimeOnly? Time { get; set; }
}

public enum BirthMonthEnum
{
January = 1,
February = 2,
March = 3,
April = 4,
May = 5,
June = 6,
July = 7,
August = 8,
September = 9,
October = 10,
November = 11,
December = 12
}
30 changes: 30 additions & 0 deletions QueryKit.MartenTests/QueryKit.MartenTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AwesomeAssertions" Version="8.0.1" />
<PackageReference Include="Bogus" Version="35.6.2" />
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="Marten" Version="7.37.3" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Testcontainers.PostgreSql" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\QueryKit\QueryKit.csproj" />
</ItemGroup>

</Project>
62 changes: 62 additions & 0 deletions QueryKit.MartenTests/TestBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Marten;
using Microsoft.Extensions.DependencyInjection;
using Weasel.Core;
using Testcontainers.PostgreSql;
using Xunit;

namespace QueryKit.MartenTests;

public abstract class TestBase : IAsyncLifetime
{
private readonly IDocumentStore _store;
private readonly IServiceScope _scope;
protected IDocumentSession Session;
private readonly PostgreSqlContainer _dbContainer;

protected TestBase()
{
_dbContainer = new PostgreSqlBuilder().Build();

var services = new ServiceCollection();

services.AddMarten(opts =>
{
opts.Connection("Host=localhost;Port=5432;Database=querykit_tests;Username=postgres;Password=postgres");
opts.AutoCreateSchemaObjects = AutoCreate.All;
});

var provider = services.BuildServiceProvider();
_scope = provider.CreateScope();
_store = provider.GetRequiredService<IDocumentStore>();
Session = _store.LightweightSession();
}

public async Task InitializeAsync()
{
await _dbContainer.StartAsync();

var services = new ServiceCollection();
services.AddMarten(opts =>
{
opts.Connection(_dbContainer.GetConnectionString());
opts.AutoCreateSchemaObjects = AutoCreate.All;
});

var provider = services.BuildServiceProvider();
_scope?.Dispose();
_store?.Dispose();

var scope = provider.CreateScope();
var store = provider.GetRequiredService<IDocumentStore>();
Session?.Dispose();
Session = store.LightweightSession();
}

public async Task DisposeAsync()
{
Session?.Dispose();
_scope?.Dispose();
_store?.Dispose();
await _dbContainer.DisposeAsync();
}
}
Loading
Loading