Skip to content

Commit

Permalink
Initial commits (#2)
Browse files Browse the repository at this point in the history
Adapters for
- `IHostedService`
- `IServiceProvider` and `IScope`
- `ILoggerFactory` and `ILogger`

Extension methods to enrich `IServiceCollection`
  • Loading branch information
Kralizek authored May 9, 2019
1 parent ac2c6a0 commit 554e003
Show file tree
Hide file tree
Showing 11 changed files with 490 additions and 0 deletions.
7 changes: 7 additions & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
next-version: 1.0.0
mode: ContinuousDeployment
continuous-delivery-fallback-tag: preview

branches:
develop:
tag: vnext
17 changes: 17 additions & 0 deletions NybusLegacyAdapter.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F350BB51-6F5
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nybus.Legacy.NetExtensions.Adapters", "src\Nybus.Legacy.NetExtensions.Adapters\Nybus.Legacy.NetExtensions.Adapters.csproj", "{CF8576EB-F5EE-46BC-B5D5-09FB666B6B7A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{348C3DFA-1C3F-4F28-B77E-C88C14D1A0EF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.Nybus.Legacy.NetExtensions.Adapters", "tests\Tests.Nybus.Legacy.NetExtensions.Adapters\Tests.Nybus.Legacy.NetExtensions.Adapters.csproj", "{1D688821-B17F-434A-81E9-89DF81B14257}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -32,8 +36,21 @@ Global
{CF8576EB-F5EE-46BC-B5D5-09FB666B6B7A}.Release|x64.Build.0 = Release|Any CPU
{CF8576EB-F5EE-46BC-B5D5-09FB666B6B7A}.Release|x86.ActiveCfg = Release|Any CPU
{CF8576EB-F5EE-46BC-B5D5-09FB666B6B7A}.Release|x86.Build.0 = Release|Any CPU
{1D688821-B17F-434A-81E9-89DF81B14257}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D688821-B17F-434A-81E9-89DF81B14257}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D688821-B17F-434A-81E9-89DF81B14257}.Debug|x64.ActiveCfg = Debug|Any CPU
{1D688821-B17F-434A-81E9-89DF81B14257}.Debug|x64.Build.0 = Debug|Any CPU
{1D688821-B17F-434A-81E9-89DF81B14257}.Debug|x86.ActiveCfg = Debug|Any CPU
{1D688821-B17F-434A-81E9-89DF81B14257}.Debug|x86.Build.0 = Debug|Any CPU
{1D688821-B17F-434A-81E9-89DF81B14257}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D688821-B17F-434A-81E9-89DF81B14257}.Release|Any CPU.Build.0 = Release|Any CPU
{1D688821-B17F-434A-81E9-89DF81B14257}.Release|x64.ActiveCfg = Release|Any CPU
{1D688821-B17F-434A-81E9-89DF81B14257}.Release|x64.Build.0 = Release|Any CPU
{1D688821-B17F-434A-81E9-89DF81B14257}.Release|x86.ActiveCfg = Release|Any CPU
{1D688821-B17F-434A-81E9-89DF81B14257}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{CF8576EB-F5EE-46BC-B5D5-09FB666B6B7A} = {F350BB51-6F55-4AC1-BA1F-A4FFE41BC4ED}
{1D688821-B17F-434A-81E9-89DF81B14257} = {348C3DFA-1C3F-4F28-B77E-C88C14D1A0EF}
EndGlobalSection
EndGlobal
51 changes: 51 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
max_jobs: 1

image: Visual Studio 2017

environment:
COVERALLS_REPO_TOKEN:
secure: FLG2WTxc1Gvrikrvj/UXnb9IAklUhPKGYV5pxOzlwsOWGQBiiEigRnyWCvCc2Zga
MYGET_TOKEN:
secure: yP12k1vrHJyValU1UWnW3NySjKfXlRomR8p4qqmYs26FDztsGMlCQeT5jdCVHlz6

cache:
- '%LocalAppData%\NuGet\v3-cache'

nuget:
account_feed: false
project_feed: false
disable_publish_on_pr: true

install:
- cmd: dotnet tool install -g Cake.Tool --version 0.33.0
- cmd: dotnet tool install coveralls.net --tool-path tools

build_script:
- cmd: dotnet cake --target=Full


# after_build:
# - ps: if ($env:COVERALLS_REPO_TOKEN -ne $null) { .\tools\csmacnz.coveralls.exe --reportgenerator -i .\outputs\tests\report --repoToken $env:COVERALLS_REPO_TOKEN --commitId $env:APPVEYOR_REPO_COMMIT --commitBranch $env:APPVEYOR_REPO_BRANCH --commitAuthor $env:APPVEYOR_REPO_COMMIT_AUTHOR --commitEmail $env:APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL --commitMessage $env:APPVEYOR_REPO_COMMIT_MESSAGE --jobId $env:APPVEYOR_JOB_ID }

test: off

artifacts:
- path: outputs\*.nupkg
name: packages
- path: outputs\*.snupkg
name: symbols
- path: outputs\tests\report
name: report
type: zip

deploy:
- provider: NuGet
server: https://www.myget.org/F/nybus/api/v2/package
api_key:
secure: yP12k1vrHJyValU1UWnW3NySjKfXlRomR8p4qqmYs26FDztsGMlCQeT5jdCVHlz6
artifact: packages
- provider: Environment
name: NuGet
on:
branch: master
appveyor_repo_tag: true
244 changes: 244 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
#tool "nuget:?package=ReportGenerator&version=4.0.5"
#tool "nuget:?package=JetBrains.dotCover.CommandLineTools&version=2018.3.1"
#tool "nuget:?package=GitVersion.CommandLine&version=4.0.0"

#load "./build/types.cake"


var target = Argument("Target", "Full");

Setup<BuildState>(_ =>
{
var state = new BuildState
{
Paths = new BuildPaths
{
SolutionFile = MakeAbsolute(File("./NybusLegacyAdapter.sln"))
}
};

CleanDirectory(state.Paths.OutputFolder);

return state;
});

Task("Version")
.Does<BuildState>(state =>
{
var version = GitVersion();

var packageVersion = version.SemVer;
var buildVersion = $"{version.FullSemVer}+{DateTimeOffset.UtcNow:yyyyMMddHHmmss}";

state.Version = new VersionInfo
{
PackageVersion = packageVersion,
BuildVersion = buildVersion
};


Information($"Package version: {state.Version.PackageVersion}");
Information($"Build version: {state.Version.BuildVersion}");

if (BuildSystem.IsRunningOnAppVeyor)
{
AppVeyor.UpdateBuildVersion(state.Version.BuildVersion);
}
});

Task("Restore")
.Does<BuildState>(state =>
{
var settings = new DotNetCoreRestoreSettings
{
};
DotNetCoreRestore(state.Paths.SolutionFile.ToString(), settings);
});

Task("Build")
.IsDependentOn("Restore")
.Does<BuildState>(state =>
{
var settings = new DotNetCoreBuildSettings
{
Configuration = "Debug",
NoRestore = true
};
DotNetCoreBuild(state.Paths.SolutionFile.ToString(), settings);
});

Task("RunTests")
.IsDependentOn("Build")
.Does<BuildState>(state =>
{
var projectFiles = GetFiles($"{state.Paths.TestFolder}/**/Tests.*.csproj");
var frameworks = new[]{"netcoreapp2.2", "net472"};
bool success = true;
foreach (var file in projectFiles)
{
var targetFrameworks = GetTargetFrameworks(file);
foreach (var framework in targetFrameworks)
{
var frameworkFriendlyName = framework.Replace(".", "-");
try
{
Information($"Testing {file.GetFilenameWithoutExtension()} ({framework})");
var testResultFile = state.Paths.TestOutputFolder.CombineWithFilePath($"{file.GetFilenameWithoutExtension()}-{frameworkFriendlyName}.trx");
var coverageResultFile = state.Paths.TestOutputFolder.CombineWithFilePath($"{file.GetFilenameWithoutExtension()}-{frameworkFriendlyName}.dcvr");
var projectFile = MakeAbsolute(file).ToString();
var dotCoverSettings = new DotCoverCoverSettings()
.WithFilter("+:Nybus*")
.WithFilter("-:Tests*")
.WithFilter("-:TestUtils");
var settings = new DotNetCoreTestSettings
{
NoBuild = true,
NoRestore = true,
Logger = $"trx;LogFileName={testResultFile.FullPath}",
Filter = "TestCategory!=External",
Framework = framework
};
DotCoverCover(c => c.DotNetCoreTest(projectFile, settings), coverageResultFile, dotCoverSettings);
}
catch (Exception ex)
{
Error($"There was an error while executing the tests: {file.GetFilenameWithoutExtension()}", ex);
success = false;
}
Information("");
}
}
if (!success)
{
throw new CakeException("There was an error while executing the tests");
}
string[] GetTargetFrameworks(FilePath file)
{
XmlPeekSettings settings = new XmlPeekSettings
{
SuppressWarning = true
};
return (XmlPeek(file, "/Project/PropertyGroup/TargetFrameworks", settings) ?? XmlPeek(file, "/Project/PropertyGroup/TargetFramework", settings)).Split(";");
}
});

Task("MergeCoverageResults")
.IsDependentOn("RunTests")
.Does<BuildState>(state =>
{
Information("Merging coverage files");
var coverageFiles = GetFiles($"{state.Paths.TestOutputFolder}/*.dcvr");
DotCoverMerge(coverageFiles, state.Paths.DotCoverOutputFile);
DeleteFiles(coverageFiles);
});

Task("GenerateXmlReport")
.IsDependentOn("MergeCoverageResults")
.Does<BuildState>(state =>
{
Information("Generating dotCover XML report");
DotCoverReport(state.Paths.DotCoverOutputFile, state.Paths.DotCoverOutputFileXml, new DotCoverReportSettings
{
ReportType = DotCoverReportType.DetailedXML
});
});

Task("ExportReport")
.IsDependentOn("GenerateXmlReport")
.Does<BuildState>(state =>
{
Information("Executing ReportGenerator to generate HTML report");
ReportGenerator(state.Paths.DotCoverOutputFileXml, state.Paths.ReportFolder, new ReportGeneratorSettings {
ReportTypes = new[]{ReportGeneratorReportType.Html, ReportGeneratorReportType.Xml}
});
});

Task("UploadTestsToAppVeyor")
.IsDependentOn("RunTests")
.WithCriteria(BuildSystem.IsRunningOnAppVeyor)
.Does<BuildState>(state =>
{
Information("Uploading test result files to AppVeyor");
var testResultFiles = GetFiles($"{state.Paths.TestOutputFolder}/*.trx");
foreach (var file in testResultFiles)
{
Information($"\tUploading {file.GetFilename()}");
AppVeyor.UploadTestResults(file, AppVeyorTestResultsType.MSTest);
}
});

Task("Test")
.IsDependentOn("RunTests")
.IsDependentOn("MergeCoverageResults")
.IsDependentOn("GenerateXmlReport")
.IsDependentOn("ExportReport")
.IsDependentOn("UploadTestsToAppVeyor");

Task("PackLibraries")
.IsDependentOn("Version")
.IsDependentOn("Restore")
.Does<BuildState>(state =>
{
var settings = new DotNetCorePackSettings
{
Configuration = "Release",
NoRestore = true,
OutputDirectory = state.Paths.OutputFolder,
IncludeSymbols = true,
ArgumentCustomization = args => args.Append($"-p:SymbolPackageFormat=snupkg -p:Version={state.Version.PackageVersion}")
};
DotNetCorePack(state.Paths.SolutionFile.ToString(), settings);
});

Task("Pack")
.IsDependentOn("PackLibraries");

Task("UploadPackagesToAppVeyor")
.IsDependentOn("Pack")
.WithCriteria(BuildSystem.IsRunningOnAppVeyor)
.Does<BuildState>(state =>
{
Information("Uploading packages");
var files = GetFiles($"{state.Paths.OutputFolder}/*.nukpg");
foreach (var file in files)
{
Information($"\tUploading {file.GetFilename()}");
AppVeyor.UploadArtifact(file, new AppVeyorUploadArtifactsSettings {
ArtifactType = AppVeyorUploadArtifactType.NuGetPackage,
DeploymentName = "NuGet"
});
}
});

Task("Push")
.IsDependentOn("UploadPackagesToAppVeyor");

Task("Full")
.IsDependentOn("Version")
.IsDependentOn("Restore")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Pack")
.IsDependentOn("Push");

RunTarget(target);
46 changes: 46 additions & 0 deletions build/types.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
public class BuildState
{
public VersionInfo Version { get; set; }

public BuildPaths Paths { get; set; }
}

public class BuildParameters
{

}

public class BuildPaths
{
public FilePath SolutionFile { get; set; }

public DirectoryPath SolutionFolder => SolutionFile.GetDirectory();

public DirectoryPath TestFolder => SolutionFolder.Combine("tests");

public DirectoryPath OutputFolder => SolutionFolder.Combine("outputs");

public DirectoryPath TestOutputFolder => OutputFolder.Combine("tests");

public DirectoryPath ReportFolder => TestOutputFolder.Combine("report");

public FilePath DotCoverOutputFile => TestOutputFolder.CombineWithFilePath("coverage.dcvr");

public FilePath DotCoverOutputFileXml => TestOutputFolder.CombineWithFilePath("coverage.xml");

public FilePath OpenCoverResultFile => OutputFolder.CombineWithFilePath("OpenCover.xml");
}

public class VersionInfo
{
public string PackageVersion { get; set; }

public string BuildVersion {get; set; }
}

[Flags]
public enum CoverageTool
{
OpenCover = 1,
DotCover = 2
}
Loading

0 comments on commit 554e003

Please sign in to comment.