diff --git a/GitVersion.yml b/GitVersion.yml new file mode 100644 index 0000000..e9c43fa --- /dev/null +++ b/GitVersion.yml @@ -0,0 +1,7 @@ +next-version: 1.0.0 +mode: ContinuousDeployment +continuous-delivery-fallback-tag: preview + +branches: + develop: + tag: vnext diff --git a/NybusLegacyAdapter.sln b/NybusLegacyAdapter.sln index 9d04890..eda77e6 100644 --- a/NybusLegacyAdapter.sln +++ b/NybusLegacyAdapter.sln @@ -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 @@ -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 diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..0564384 --- /dev/null +++ b/appveyor.yml @@ -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 \ No newline at end of file diff --git a/build.cake b/build.cake new file mode 100644 index 0000000..8b9ad3c --- /dev/null +++ b/build.cake @@ -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(_ => +{ + var state = new BuildState + { + Paths = new BuildPaths + { + SolutionFile = MakeAbsolute(File("./NybusLegacyAdapter.sln")) + } + }; + + CleanDirectory(state.Paths.OutputFolder); + + return state; +}); + +Task("Version") + .Does(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(state => +{ + var settings = new DotNetCoreRestoreSettings + { + + }; + + DotNetCoreRestore(state.Paths.SolutionFile.ToString(), settings); +}); + +Task("Build") + .IsDependentOn("Restore") + .Does(state => +{ + var settings = new DotNetCoreBuildSettings + { + Configuration = "Debug", + NoRestore = true + }; + + DotNetCoreBuild(state.Paths.SolutionFile.ToString(), settings); +}); + +Task("RunTests") + .IsDependentOn("Build") + .Does(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(state => +{ + Information("Merging coverage files"); + var coverageFiles = GetFiles($"{state.Paths.TestOutputFolder}/*.dcvr"); + DotCoverMerge(coverageFiles, state.Paths.DotCoverOutputFile); + DeleteFiles(coverageFiles); +}); + +Task("GenerateXmlReport") + .IsDependentOn("MergeCoverageResults") + .Does(state => +{ + Information("Generating dotCover XML report"); + DotCoverReport(state.Paths.DotCoverOutputFile, state.Paths.DotCoverOutputFileXml, new DotCoverReportSettings + { + ReportType = DotCoverReportType.DetailedXML + }); +}); + +Task("ExportReport") + .IsDependentOn("GenerateXmlReport") + .Does(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(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(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(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); \ No newline at end of file diff --git a/build/types.cake b/build/types.cake new file mode 100644 index 0000000..f40ae81 --- /dev/null +++ b/build/types.cake @@ -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 +} \ No newline at end of file diff --git a/src/Directory.Build.props b/src/Directory.Build.props new file mode 100644 index 0000000..0b7fda4 --- /dev/null +++ b/src/Directory.Build.props @@ -0,0 +1,28 @@ + + + Renato Golia + Nybus Project + Nybus + latest + + + + false + MIT + https://github.com/Nybus-project/Nybus + https://raw.githubusercontent.com/Nybus-project/Nybus/master/assets/nybus128x128.png + NU5105,NU5125 + + + + true + true + true + snupkg + + + + + + + \ No newline at end of file diff --git a/src/Nybus.Legacy.NetExtensions.Adapters/Nybus.Legacy.NetExtensions.Adapters.csproj b/src/Nybus.Legacy.NetExtensions.Adapters/Nybus.Legacy.NetExtensions.Adapters.csproj index 9b28b38..645809e 100644 --- a/src/Nybus.Legacy.NetExtensions.Adapters/Nybus.Legacy.NetExtensions.Adapters.csproj +++ b/src/Nybus.Legacy.NetExtensions.Adapters/Nybus.Legacy.NetExtensions.Adapters.csproj @@ -3,6 +3,8 @@ net47 Nybus + Implementation of IHostedService interface for Nybus Legacy + dotnet-framework;framework;queue;nybus;hosted service diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props new file mode 100644 index 0000000..898345a --- /dev/null +++ b/tests/Directory.Build.props @@ -0,0 +1,15 @@ + + + Tests + latest + + + + + + + + + + + \ No newline at end of file diff --git a/tests/Tests.Nybus.Legacy.NetExtensions.Adapters/AutoMoqDataAttribute.cs b/tests/Tests.Nybus.Legacy.NetExtensions.Adapters/AutoMoqDataAttribute.cs new file mode 100644 index 0000000..80fe453 --- /dev/null +++ b/tests/Tests.Nybus.Legacy.NetExtensions.Adapters/AutoMoqDataAttribute.cs @@ -0,0 +1,27 @@ +using AutoFixture; +using AutoFixture.AutoMoq; +using AutoFixture.NUnit3; + +namespace Tests +{ + public class AutoMoqDataAttribute : AutoDataAttribute + { + public AutoMoqDataAttribute() : base (CreateFixture) + { + + } + + private static IFixture CreateFixture() + { + var fixture = new Fixture(); + + fixture.Customize(new AutoMoqCustomization + { + ConfigureMembers = true, + GenerateDelegates = true + }); + + return fixture; + } + } +} \ No newline at end of file diff --git a/tests/Tests.Nybus.Legacy.NetExtensions.Adapters/NybusLegacyHostedServiceTests.cs b/tests/Tests.Nybus.Legacy.NetExtensions.Adapters/NybusLegacyHostedServiceTests.cs new file mode 100644 index 0000000..d2ed540 --- /dev/null +++ b/tests/Tests.Nybus.Legacy.NetExtensions.Adapters/NybusLegacyHostedServiceTests.cs @@ -0,0 +1,35 @@ +using System.Threading.Tasks; +using AutoFixture.Idioms; +using AutoFixture.NUnit3; +using Moq; +using NUnit.Framework; +using Nybus; + +namespace Tests +{ + [TestFixture] + public class NybusLegacyHostedServiceTests + { + [Test, AutoMoqData] + public void Constructor_is_guarded(GuardClauseAssertion assertion) + { + assertion.Verify(typeof(NybusLegacyHostedService).GetConstructors()); + } + + [Test, AutoMoqData] + public async Task StartAsync_starts_bus([Frozen] IBus bus, NybusLegacyHostedService sut) + { + await sut.StartAsync(default); + + Mock.Get(bus).Verify(p => p.Start()); + } + + [Test, AutoMoqData] + public async Task StopAsync_stops_bus([Frozen] IBus bus, NybusLegacyHostedService sut) + { + await sut.StopAsync(default); + + Mock.Get(bus).Verify(p => p.Stop()); + } + } +} \ No newline at end of file diff --git a/tests/Tests.Nybus.Legacy.NetExtensions.Adapters/Tests.Nybus.Legacy.NetExtensions.Adapters.csproj b/tests/Tests.Nybus.Legacy.NetExtensions.Adapters/Tests.Nybus.Legacy.NetExtensions.Adapters.csproj new file mode 100644 index 0000000..2797c25 --- /dev/null +++ b/tests/Tests.Nybus.Legacy.NetExtensions.Adapters/Tests.Nybus.Legacy.NetExtensions.Adapters.csproj @@ -0,0 +1,18 @@ + + + + net472 + false + + + + + + + + + + + + +