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
63 changes: 63 additions & 0 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Build and Deploy
on:
pull_request:
branches:
- master
push:
branches:
- master
env:
APP_NAME: DanishCvr
VERSION: 1.0.0-preview
NUGET_HOST: https://api.nuget.org/v3/index.json
NUGET_APIKEY: ${{ secrets.NUGET_APIKEY }}
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: write
concurrency:
group: ${{ github.repository }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v6

- name: Build and Pack
shell: pwsh
run: |
dotnet build -c Release .\$env:APP_NAME.sln;
if ($LastExitCode -ne 0)
{
throw "Build failed";
};

dotnet pack .\$env:APP_NAME\$env:APP_NAME.csproj -c Release --output nupkgs /p:PackageVersion=$env:VERSION;
if ($LastExitCode -ne 0)
{
throw "Pack failed";
};

# - name: Push NuGet
# if: github.ref == 'refs/heads/master'
# shell: pwsh
# run: |
# dotnet nuget push "nupkgs/*.nupkg" -s $env:NUGET_HOST -k $env:NUGET_APIKEY --skip-duplicate

# if ($LastExitCode -ne 0)
# {
# throw "Publish failed";
# };

# - name: GitHub Release
# if: github.ref == 'refs/heads/master'
# uses: ncipollo/release-action@v1
# with:
# tag: v${{ env.VERSION }}
# name: "Release ${{ env.VERSION }}"
# body: |
# Version: ${{ env.VERSION }}
# Commit: ${{ github.sha }}
# artifacts: "nupkgs/*"
# token: ${{ secrets.GITHUB_TOKEN }}
# draft: false
# prerelease: false
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
**/*.user
**/*.userprefs
*.user
*.userprefs
*.suo
*.tss
*.vs
_ReSharper*
**/bin
**/obj
*.DotSettings.User
**/wwwroot/lib
.vs
packages
.env
71 changes: 71 additions & 0 deletions .tests/Tests.DanishCvr/BaseTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using DanishCvr.Extensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using DanishCvr.Responses.Models;

namespace Tests.DanishCvr;

public class BaseTests
{
private const string DIRECTORY = ".test-output";

protected IServiceProvider serviceProvider;

[TestInitialize]
public void TestSetup()
{
var configurationRoot = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.AddUserSecrets(Assembly.GetExecutingAssembly())
.Build();

var services = new ServiceCollection();

services
.AddSingleton<IConfiguration>(configurationRoot)
.AddLogging(x => x
.AddConfiguration(configurationRoot.GetSection("Logging"))
.AddConsole());

var logger = services
.BuildServiceProvider()
.GetRequiredService<ILoggerFactory>()
.CreateLogger("Test");

services
.AddSingleton(logger);

services
.AddDanishCvr();

this.serviceProvider = services
.BuildServiceProvider();
}

protected Task SaveJsonOrDefault(BaseDebugResult result, [CallerMemberName]string callerMethodName = "")
{
if (result == null)
{
return Task.CompletedTask;
}

if (!Directory.Exists(DIRECTORY))
{
Directory.CreateDirectory(DIRECTORY);
}

var contents = JsonConvert.SerializeObject(result, Formatting.Indented);

return File.WriteAllTextAsync($"./{DIRECTORY}/{callerMethodName}.json", contents);
}
}
51 changes: 51 additions & 0 deletions .tests/Tests.DanishCvr/DanishCvrBatchServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using DanishCvr.Interfaces;
using DanishCvr.Models.Debug;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Tests.DanishCvr;

[TestClass]
public class DanishCvrBatchServiceTests : BaseTests
{
private IDanishCvrBatchService DanishCvrBatchService => this.serviceProvider.GetService<IDanishCvrBatchService>();

[TestMethod]
public async Task SearchAllTest()
{
await Task.CompletedTask;

const int MAX_ITERATIONS = 1;
const int SKIP_ITERATIONS = 0;

var debugInformation = await this.DanishCvrBatchService
.SearchAllAsync(x =>
{
Debug.WriteLine($"callback: {x.Count()}");
}, MAX_ITERATIONS, SKIP_ITERATIONS, 2);

this.PrintDebugInformation(debugInformation);
}

private void PrintDebugInformation(DebugInformation debugInformation)
{
if (debugInformation == null)
throw new ArgumentNullException(nameof(debugInformation));

foreach (var debugHovedType in debugInformation.HovedTyper)
{
Debug.WriteLine($"{debugHovedType.Type}: {debugHovedType.Count}");

foreach (var debugAttribute in debugHovedType.Attributes)
{
var registrationNumbers = string.Join(',', debugAttribute.SampleRegistrationNumbers);

Debug.WriteLine($" {debugAttribute.Value}: {debugAttribute.Count} ({registrationNumbers})");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System.Linq;
using System.Threading.Tasks;
using DanishCvr.Requests;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Tests.DanishCvr;

public partial class DanishCvrServiceTests
{
[TestMethod]
public async Task AutoCompleteCompanyTest()
{
const string NAME = "Vivet";

var response = await this.DanishCvrService
.AutoCompleteCompaniesAsync(new AutoCompleteCompaniesRequest
{
Names =
{
Name = NAME
}
});

Assert.IsNotNull(response);
Assert.AreEqual(10, response.Results.Count());
}

[TestMethod]
public async Task AutoCompleteCompanyWhenAlternativeNameTest()
{
await Task.CompletedTask;

Assert.Inconclusive();
}

[TestMethod]
public async Task AutoCompleteCompanyWhenAlternativeNameAndNotIncludedTest()
{
await Task.CompletedTask;

Assert.Inconclusive();
}

[TestMethod]
public async Task AutoCompleteCompanyWhenHistoricNameTest()
{
await Task.CompletedTask;

Assert.Inconclusive();
}

[TestMethod]
public async Task AutoCompleteCompanyWhenHistoricNameAndNotIncludedTest()
{
await Task.CompletedTask;

Assert.Inconclusive();
}

[TestMethod]
public async Task AutoCompleteCompanyWhenIsActiveTest()
{
await Task.CompletedTask;

Assert.Inconclusive();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Linq;
using System.Threading.Tasks;
using DanishCvr.Requests;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Tests.DanishCvr;

public partial class DanishCvrServiceTests
{
[TestMethod]
public async Task AutoCompletePersonTest()
{
const string NAME = "Michael Viv";

var response = await this.DanishCvrService
.AutoCompletePersonsAsync(new AutoCompletePersonsRequest
{
Name = NAME
});

Assert.IsNotNull(response);
Assert.AreEqual(4, response.Results.Count());
}
}
25 changes: 25 additions & 0 deletions .tests/Tests.DanishCvr/DanishCvrServiceTests.GetCompanies.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Tests.DanishCvr;

public partial class DanishCvrServiceTests
{
[TestMethod]
public async Task GetCompanyWithRegistrationNumbersTest()
{
const string CVR_NUMMER_1 = "10198054";
const string CVR_NUMMER_2 = "21705500";
const string CVR_NUMMER_3 = "10191246";

var response = await this.DanishCvrService
.GetCompaniesAsync([CVR_NUMMER_1, CVR_NUMMER_2, CVR_NUMMER_3]);

Assert.IsNotNull(response);

Assert.IsTrue(response.Results.Any(x => x.Company.RegistrationNumber == CVR_NUMMER_1));
Assert.IsTrue(response.Results.Any(x => x.Company.RegistrationNumber == CVR_NUMMER_2));
Assert.IsTrue(response.Results.Any(x => x.Company.RegistrationNumber == CVR_NUMMER_3));
}
}
Loading
Loading