From 98a107abb917c9ff64869229a318ebf977def997 Mon Sep 17 00:00:00 2001 From: Dennis Beuchler Date: Tue, 6 Oct 2020 08:45:53 +0200 Subject: [PATCH] Fixed test execution for new project style --- .build/BuildToolkit.ps1 | 21 +- .build/Common.props | 1 - .github/workflows/build-and-test.yml | 3 +- .vscode/launch.json | 2 +- GlobalAssemblyInfo.cs | 14 - ...munication.Sockets.IntegrationTests.csproj | 4 +- .../Moryx.Container.Tests.csproj | 7 +- .../Moryx.Model.Tests.csproj | 4 +- .../Moryx.Runtime.Kernel.Tests.csproj | 5 +- .../Moryx.Runtime.SystemTests.csproj | 3 +- .../Moryx.Runtime.Tests.csproj | 4 +- src/Tests/Moryx.Tests/Moryx.Tests.csproj | 2 +- .../Threading/NotSoParallelOpsTests.cs | 239 ------------------ .../Threading/ParallelOperationTests.cs | 4 +- .../Moryx.Tools.Wcf.SystemTests.csproj | 3 +- .../LogMaintenanceClientMock.cs | 2 +- .../Moryx.Tools.Wcf.Tests.csproj | 3 +- 17 files changed, 36 insertions(+), 285 deletions(-) delete mode 100644 GlobalAssemblyInfo.cs delete mode 100644 src/Tests/Moryx.Tests/Threading/NotSoParallelOpsTests.cs diff --git a/.build/BuildToolkit.ps1 b/.build/BuildToolkit.ps1 index 025e35c16..d326fc7f4 100644 --- a/.build/BuildToolkit.ps1 +++ b/.build/BuildToolkit.ps1 @@ -244,7 +244,7 @@ function Invoke-CoverTests($SearchPath = $RootPath, $SearchFilter = "*.csproj", Write-Step "Starting cover tests from $SearchPath with filter $FilterFile." if (-not (Test-Path $SearchPath)) { - Write-Host "$SearchPath does not exists, ignoring!"; + Write-Host-Warning "$SearchPath does not exists, ignoring!"; return; } @@ -336,7 +336,7 @@ function Invoke-CoverTests($SearchPath = $RootPath, $SearchFilter = "*.csproj", $errorText = "FAILED_TESTS ($exitCode)"; } - Write-Host "Nunit exited with $errorText for $projectName"; + Write-Host-Error "Nunit exited with $errorText for $projectName"; Invoke-ExitCodeCheck $exitCode; } } @@ -409,13 +409,16 @@ function Invoke-DocFx($Metadata = [System.IO.Path]::Combine($DocumentationDir, " CopyAndReplaceFolder $docFxDest "$DocumentationArtifcacts\DocFx"; } -function Invoke-PackSdkProject($ProjectPath, [bool]$IsTool = $False, [bool]$IncludeSymbols = $False) { +function Invoke-PackSdkProject($CsprojFile, [bool]$IncludeSymbols = $False) { + Write-Host "Try to pack .NET SDK project: $($CsprojFile.Name) ..."; + # Check if the project should be packed - $csprojFullName = $csprojFile.FullName; + $csprojFullName = $CsprojFile.FullName; [xml]$csprojContent = Get-Content $csprojFullName $createPackage = $csprojContent.Project.PropertyGroup.CreatePackage; ; if ($null -eq $createPackage -or "false" -eq $createPackage) { + Write-Host-Warning "... csproj not flagged with true: $($CsprojFile.Name)"; return; } @@ -433,11 +436,13 @@ function Invoke-PackSdkProject($ProjectPath, [bool]$IsTool = $False, [bool]$Incl Invoke-ExitCodeCheck $LastExitCode; } -function Invoke-PackFrameworkProject($ProjectPath, [bool]$IsTool = $False, [bool]$IncludeSymbols = $False) { +function Invoke-PackFrameworkProject($CsprojFile, [bool]$IsTool = $False, [bool]$IncludeSymbols = $False) { + Write-Host "Try to pack .NET Framework project: $CsprojFile.Name ..."; # Check if there is a matching nuspec for the proj - $nuspecPath = [IO.Path]::ChangeExtension($ProjectPath, "nuspec") + $nuspecPath = [IO.Path]::ChangeExtension($CsprojFile.FullName, "nuspec") if(-not (Test-Path $nuspecPath)) { + Write-Host-Warning "Nuspec for project not found: $CsprojFile.Name"; return; } @@ -464,7 +469,7 @@ function Invoke-Pack($ProjectPath, [bool]$IsTool = $False, [bool]$IncludeSymbols CreateFolderIfNotExists $NugetPackageArtifacts; if (Get-CsprojIsSdkProject($ProjectPath)) { - Invoke-PackSdkProject $ProjectPath $IsTool $IncludeSymbols; + Invoke-PackSdkProject $ProjectPath $IncludeSymbols; } else { Invoke-PackFrameworkProject $ProjectPath $IsTool $IncludeSymbols; @@ -483,7 +488,7 @@ function Invoke-Publish { Write-Host "Pushing packages from $NugetPackageArtifacts to $env:MORYX_PACKAGE_TARGET" if ([string]::IsNullOrEmpty($env:MORYX_PACKAGE_TARGET)) { - Write-Host "There is no package target given. Set the environment varialble MORYX_PACKAGE_TARGET to publish packages."; + Write-Host-Error "There is no package target given. Set the environment varialble MORYX_PACKAGE_TARGET to publish packages."; Invoke-ExitCodeCheck 1; } diff --git a/.build/Common.props b/.build/Common.props index d4beefb00..15b86e9da 100644 --- a/.build/Common.props +++ b/.build/Common.props @@ -24,7 +24,6 @@ https://github.com/PHOENIXCONTACT/MORYX-Platform moryx-logo.png - https://www.phoenixcontact.com/favicon.ico https://moryx-industry.net/ Apache-2.0 false diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 89547e7f9..2ac240d55 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -62,7 +62,8 @@ jobs: - name: Codecov uses: codecov/codecov-action@v1 with: - files: './artifacts/Tests/*.OpenCover.xml' + files: ./artifacts/Tests/Moryx.Container.Tests.OpenCover.xml,./artifacts/Tests/Moryx.Model.Tests.OpenCover.xml,./artifacts/Tests/Moryx.Runtime.Kernel.Tests.OpenCover.xml,./artifacts/Tests/Moryx.Runtime.Tests.OpenCover.xml,./artifacts/Tests/Moryx.Tests.OpenCover.xml,./artifacts/Tests/Moryx.Tools.Wcf.Tests.OpenCover.xml,./artifacts/Tests/Moryx.Communication.Sockets.IntegrationTests.OpenCover + Publish: needs: [Test] if: ${{ github.event_name == 'push' }} diff --git a/.vscode/launch.json b/.vscode/launch.json index b867ff107..8c4af20dc 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -59,7 +59,7 @@ "script": "${workspaceRoot}\\Build.ps1", "args": ["-Pack"], "cwd": "${workspaceRoot}" - } + }, { "type": "PowerShell", "request": "launch", diff --git a/GlobalAssemblyInfo.cs b/GlobalAssemblyInfo.cs deleted file mode 100644 index 43359dd02..000000000 --- a/GlobalAssemblyInfo.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Reflection; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyProduct("MORYX Platform")] -[assembly: AssemblyCompany("PHOENIX CONTACT")] -[assembly: AssemblyCopyright("Copyright © PHOENIX CONTACT 2020")] -[assembly: AssemblyTrademark("")] - -[assembly: AssemblyConfiguration("Debug")] -[assembly: AssemblyVersion("3.0.0.0")] -[assembly: AssemblyFileVersion("3.0.0.0")] -[assembly: AssemblyInformationalVersion("3.0.0.0")] \ No newline at end of file diff --git a/src/Tests/Moryx.Communication.Sockets.IntegrationTests/Moryx.Communication.Sockets.IntegrationTests.csproj b/src/Tests/Moryx.Communication.Sockets.IntegrationTests/Moryx.Communication.Sockets.IntegrationTests.csproj index 67bd7573a..cd7b8e163 100644 --- a/src/Tests/Moryx.Communication.Sockets.IntegrationTests/Moryx.Communication.Sockets.IntegrationTests.csproj +++ b/src/Tests/Moryx.Communication.Sockets.IntegrationTests/Moryx.Communication.Sockets.IntegrationTests.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/src/Tests/Moryx.Container.Tests/Moryx.Container.Tests.csproj b/src/Tests/Moryx.Container.Tests/Moryx.Container.Tests.csproj index 7f0296b24..5e2b00e24 100644 --- a/src/Tests/Moryx.Container.Tests/Moryx.Container.Tests.csproj +++ b/src/Tests/Moryx.Container.Tests/Moryx.Container.Tests.csproj @@ -7,12 +7,9 @@ - + - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/Tests/Moryx.Model.Tests/Moryx.Model.Tests.csproj b/src/Tests/Moryx.Model.Tests/Moryx.Model.Tests.csproj index 090570adc..5913db464 100644 --- a/src/Tests/Moryx.Model.Tests/Moryx.Model.Tests.csproj +++ b/src/Tests/Moryx.Model.Tests/Moryx.Model.Tests.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/src/Tests/Moryx.Runtime.Kernel.Tests/Moryx.Runtime.Kernel.Tests.csproj b/src/Tests/Moryx.Runtime.Kernel.Tests/Moryx.Runtime.Kernel.Tests.csproj index cc330420f..1ffcdcedf 100644 --- a/src/Tests/Moryx.Runtime.Kernel.Tests/Moryx.Runtime.Kernel.Tests.csproj +++ b/src/Tests/Moryx.Runtime.Kernel.Tests/Moryx.Runtime.Kernel.Tests.csproj @@ -3,13 +3,12 @@ Library netcoreapp3.1 - full - - + + diff --git a/src/Tests/Moryx.Runtime.SystemTests/Moryx.Runtime.SystemTests.csproj b/src/Tests/Moryx.Runtime.SystemTests/Moryx.Runtime.SystemTests.csproj index 8e56ffae0..b55696c82 100644 --- a/src/Tests/Moryx.Runtime.SystemTests/Moryx.Runtime.SystemTests.csproj +++ b/src/Tests/Moryx.Runtime.SystemTests/Moryx.Runtime.SystemTests.csproj @@ -2,11 +2,12 @@ net45 + false full - + diff --git a/src/Tests/Moryx.Runtime.Tests/Moryx.Runtime.Tests.csproj b/src/Tests/Moryx.Runtime.Tests/Moryx.Runtime.Tests.csproj index 896e5199f..1ffcdcedf 100644 --- a/src/Tests/Moryx.Runtime.Tests/Moryx.Runtime.Tests.csproj +++ b/src/Tests/Moryx.Runtime.Tests/Moryx.Runtime.Tests.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/src/Tests/Moryx.Tests/Moryx.Tests.csproj b/src/Tests/Moryx.Tests/Moryx.Tests.csproj index c9b670313..09c70178f 100644 --- a/src/Tests/Moryx.Tests/Moryx.Tests.csproj +++ b/src/Tests/Moryx.Tests/Moryx.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/Tests/Moryx.Tests/Threading/NotSoParallelOpsTests.cs b/src/Tests/Moryx.Tests/Threading/NotSoParallelOpsTests.cs deleted file mode 100644 index 00b703735..000000000 --- a/src/Tests/Moryx.Tests/Threading/NotSoParallelOpsTests.cs +++ /dev/null @@ -1,239 +0,0 @@ -// Copyright (c) 2020, Phoenix Contact GmbH & Co. KG -// Licensed under the Apache License, Version 2.0 - -using System; -using System.Linq; -using System.Threading; -using Moryx.TestTools.UnitTest; -using NUnit.Framework; - -namespace Moryx.Tests.Threading -{ - [TestFixture] - public class NotSoParallelOpsTests - { - private const string ExceptionMsg = "Hello World!"; - private const int MaxTrows = 3; - private const int SleepTime = 5000; - - private NotSoParallelOps _threadFactory; - private readonly ManualResetEventSlim _callbackReceivedEvent = new ManualResetEventSlim(false); - private DummyLogger _logger; - - [OneTimeSetUp] - public void OneTimeSetUp() - { - _logger = new DummyLogger(); - } - - [OneTimeTearDown] - public void OneTimeTearDown() - { - } - - [SetUp] - public void Setup() - { - _logger.ClearBuffer(); - _threadFactory = new NotSoParallelOps(); - - _callbackReceivedEvent.Reset(); - } - - [TearDown] - public void TearDown() - { - _threadFactory.Dispose(); - } - - [Test] - public void ExecuteParallel() - { - // Arrange - var state = new StateObject(); - - // Act - _threadFactory.ExecuteParallel(SimpleCallback, state); - - // Assert - Assert.IsTrue(_callbackReceivedEvent.IsSet, "Callback not called."); - } - - [TestCase(true)] - [TestCase(false)] - public void ScheduledExecuteParallelWithException(bool critical) - { - // Arrange - var state = new StateObject(); - - // Act - _threadFactory.ScheduleExecution(ExceptionCallback, state, 10, Timeout.Infinite, critical); - - // Assert - Assert.AreEqual(true, _threadFactory.WaitForScheduledExecution(5000)); - Assert.AreEqual(1, _threadFactory.ScheduledExecutionExceptions().Count()); - } - - - [Test] - public void ScheduleExecutionWithStop() - { - // Arrange - var state = new StateObject(); - - // Act - var id = _threadFactory.ScheduleExecution(SimpleCallback, state, 100, 50); - - Thread.Sleep(75); - - Assert.AreEqual(0, state.Counter, "First check"); - - Thread.Sleep(50); - - Assert.AreEqual(1, state.Counter, "Second check"); - - Thread.Sleep(50); - - Assert.AreEqual(2, state.Counter, "Third check"); - - _threadFactory.StopExecution(id); - - // Assert - Assert.AreEqual(true, _threadFactory.WaitForScheduledExecution(5000)); - Assert.AreEqual(2, state.Counter, "Last check"); - } - - [Test] - public void ScheduleExecutionWithWrongStop() - { - // Arrange - var state = new StateObject(); - - // Act - _threadFactory.ScheduleExecution(SimpleCallback, state, 200, 100); - - Thread.Sleep(150); - - Assert.AreEqual(0, state.Counter, "First check"); - - Thread.Sleep(100); - - Assert.AreEqual(1, state.Counter, "Second check"); - - Thread.Sleep(100); - - Assert.AreEqual(2, state.Counter, "Third check"); - - _threadFactory.StopExecution(42); - - Thread.Sleep(100); - - // Assert - Assert.AreEqual(3, state.Counter, "Last check"); - Assert.AreEqual(false, _threadFactory.WaitForScheduledExecution(500)); - } - - [Test] - public void ScheduleExecutionWithDispose() - { - // Arrange - var state = new StateObject(); - - // Act - _threadFactory.ScheduleExecution(SimpleCallback, state, 100, 50); - - Thread.Sleep(75); - - Assert.AreEqual(0, state.Counter, "First check"); - - Thread.Sleep(50); - - Assert.AreEqual(1, state.Counter, "Second check"); - - Thread.Sleep(50); - - Assert.AreEqual(2, state.Counter, "Third check"); - - _threadFactory.Dispose(); - - // Assert - Assert.AreEqual(true, _threadFactory.WaitForScheduledExecution(5000)); - Assert.AreEqual(2, state.Counter, "Last check"); - } - - [Test] - public void DelayedExecution() - { - // Arrange - var state = new StateObject(); - - // Act - _threadFactory.ScheduleExecution(SimpleCallback, state, 100, Timeout.Infinite); - - Thread.Sleep(75); - - Assert.AreEqual(0, state.Counter, "First check"); - - Thread.Sleep(50); - - // Assert - Assert.AreEqual(1, state.Counter, "Second check"); - Assert.AreEqual(true, _threadFactory.WaitForScheduledExecution(5000)); - Assert.AreEqual(1, state.Counter, "Last check"); - } - - [Test] - public void DelayedExecutionRunsInTimeout() - { - // Arrange - var state = new StateObject(); - - // Act - _threadFactory.ScheduleExecution(SleepingCallback, state, 100, Timeout.Infinite); - - // Assert - Assert.AreEqual(false, _threadFactory.WaitForScheduledExecution(500)); - } - - [TestCase(true)] - [TestCase(false)] - public void DelayedExecutionWithException(bool critical) - { - // Arrange - var state = new StateObject(); - - // Act - _threadFactory.ScheduleExecution(ExceptionCallback, state, 10, Timeout.Infinite, critical); - - // Assert - Assert.AreEqual(true, _threadFactory.WaitForScheduledExecution(5000)); - Assert.AreEqual(1, _threadFactory.ScheduledExecutionExceptions().Count()); - } - - private void SimpleCallback(StateObject state) - { - state.Counter++; - _callbackReceivedEvent.Set(); - } - - private void SleepingCallback(StateObject state) - { - Thread.Sleep(SleepTime); - - state.Counter++; - } - - private void ExceptionCallback(StateObject state) - { - if (state.Counter++ < MaxTrows) - { - throw new Exception(ExceptionMsg); - } - } - - private class StateObject - { - public int Counter { get; set; } - } - } -} diff --git a/src/Tests/Moryx.Tests/Threading/ParallelOperationTests.cs b/src/Tests/Moryx.Tests/Threading/ParallelOperationTests.cs index 84acb8a5c..63a2985f8 100644 --- a/src/Tests/Moryx.Tests/Threading/ParallelOperationTests.cs +++ b/src/Tests/Moryx.Tests/Threading/ParallelOperationTests.cs @@ -79,7 +79,7 @@ public void ExecuteParallelWithException(bool critical) Assert.AreEqual(!critical, _logger.Messages.Any(m => m.Level == LogLevel.Error), "Warning received"); } - + [Test] public void ScheduleExecutionWithStop() { @@ -185,7 +185,7 @@ public void DelayedExecutionWithException(bool critical) StateObject state = new StateObject(); _threadFactory.ScheduleExecution(ExceptionCallback, state, 10, Timeout.Infinite, critical); - + AwaitLogMessage(); Assert.AreEqual(critical, _logger.Messages.Any(m => m.Level == LogLevel.Fatal), "Failure received"); diff --git a/src/Tests/Moryx.Tools.Wcf.SystemTests/Moryx.Tools.Wcf.SystemTests.csproj b/src/Tests/Moryx.Tools.Wcf.SystemTests/Moryx.Tools.Wcf.SystemTests.csproj index 7fdb20c98..1186cd141 100644 --- a/src/Tests/Moryx.Tools.Wcf.SystemTests/Moryx.Tools.Wcf.SystemTests.csproj +++ b/src/Tests/Moryx.Tools.Wcf.SystemTests/Moryx.Tools.Wcf.SystemTests.csproj @@ -2,11 +2,12 @@ net45 + false full - + diff --git a/src/Tests/Moryx.Tools.Wcf.Tests/LogMaintenanceClientMock.cs b/src/Tests/Moryx.Tools.Wcf.Tests/LogMaintenanceClientMock.cs index 95e83baab..ff436cf54 100644 --- a/src/Tests/Moryx.Tools.Wcf.Tests/LogMaintenanceClientMock.cs +++ b/src/Tests/Moryx.Tools.Wcf.Tests/LogMaintenanceClientMock.cs @@ -10,7 +10,7 @@ namespace Moryx.Tools.Wcf.Tests public class LogMaintenanceClientMock : LogMaintenanceClient { - public LogMaintenanceClientMock(Binding binding, EndpointAddress remoteAddress) : + public LogMaintenanceClientMock(Binding binding, EndpointAddress remoteAddress): base(binding, remoteAddress) { } diff --git a/src/Tests/Moryx.Tools.Wcf.Tests/Moryx.Tools.Wcf.Tests.csproj b/src/Tests/Moryx.Tools.Wcf.Tests/Moryx.Tools.Wcf.Tests.csproj index 0a6b5c0b3..d2f9fbd4f 100644 --- a/src/Tests/Moryx.Tools.Wcf.Tests/Moryx.Tools.Wcf.Tests.csproj +++ b/src/Tests/Moryx.Tools.Wcf.Tests/Moryx.Tools.Wcf.Tests.csproj @@ -2,11 +2,12 @@ net45 + false full - +