From 4d0ddd0d70921f71b0c84f7f497c783c299c1789 Mon Sep 17 00:00:00 2001 From: David Pine Date: Tue, 16 Jun 2020 10:44:56 -0500 Subject: [PATCH 1/3] Added unit testing code coverage samples --- csharp/unit-testing-code-coverage/.gitignore | 3 ++ .../Numbers/Numbers.csproj | 7 +++ .../Numbers/PrimeService.cs | 22 ++++++++++ csharp/unit-testing-code-coverage/README.md | 33 ++++++++++++++ .../XUnit.Coverage.sln | 43 +++++++++++++++++++ .../PrimeServiceTests.cs | 33 ++++++++++++++ .../XUnit.Coverlet.Collector.csproj | 31 +++++++++++++ .../PrimeServiceTests.cs | 33 ++++++++++++++ .../XUnit.Coverlet.MSBuild.csproj | 30 +++++++++++++ csharp/unit-testing/.gitignore | 3 ++ .../MSTest.Project/MSTest.Project.csproj | 11 +++-- .../NUnit.TestProject/NUnit.Project.csproj | 2 +- csharp/unit-testing/Numbers/Numbers.csproj | 7 +++ csharp/unit-testing/Numbers/PrimeService.cs | 25 +++++++++++ csharp/unit-testing/UnitTesting.sln | 25 +++++++++-- .../PrimeServiceTests.cs | 33 ++++++++++++++ .../XUnit.Coverlet.Collector.csproj | 31 +++++++++++++ .../PrimeServiceTests.cs | 33 ++++++++++++++ .../XUnit.Coverlet.MSBuild.csproj | 30 +++++++++++++ .../XUnit.TestProject/XUnit.Project.csproj | 14 ++++-- 20 files changed, 437 insertions(+), 12 deletions(-) create mode 100644 csharp/unit-testing-code-coverage/.gitignore create mode 100644 csharp/unit-testing-code-coverage/Numbers/Numbers.csproj create mode 100644 csharp/unit-testing-code-coverage/Numbers/PrimeService.cs create mode 100644 csharp/unit-testing-code-coverage/README.md create mode 100644 csharp/unit-testing-code-coverage/XUnit.Coverage.sln create mode 100644 csharp/unit-testing-code-coverage/XUnit.Coverlet.Collector/PrimeServiceTests.cs create mode 100644 csharp/unit-testing-code-coverage/XUnit.Coverlet.Collector/XUnit.Coverlet.Collector.csproj create mode 100644 csharp/unit-testing-code-coverage/XUnit.Coverlet.MSBuild/PrimeServiceTests.cs create mode 100644 csharp/unit-testing-code-coverage/XUnit.Coverlet.MSBuild/XUnit.Coverlet.MSBuild.csproj create mode 100644 csharp/unit-testing/.gitignore create mode 100644 csharp/unit-testing/Numbers/Numbers.csproj create mode 100644 csharp/unit-testing/Numbers/PrimeService.cs create mode 100644 csharp/unit-testing/XUnit.Coverlet.Collector/PrimeServiceTests.cs create mode 100644 csharp/unit-testing/XUnit.Coverlet.Collector/XUnit.Coverlet.Collector.csproj create mode 100644 csharp/unit-testing/XUnit.Coverlet.MSBuild/PrimeServiceTests.cs create mode 100644 csharp/unit-testing/XUnit.Coverlet.MSBuild/XUnit.Coverlet.MSBuild.csproj diff --git a/csharp/unit-testing-code-coverage/.gitignore b/csharp/unit-testing-code-coverage/.gitignore new file mode 100644 index 00000000000..d6bc47910f7 --- /dev/null +++ b/csharp/unit-testing-code-coverage/.gitignore @@ -0,0 +1,3 @@ +/TestResults/* +/Reports/* +coverage.json diff --git a/csharp/unit-testing-code-coverage/Numbers/Numbers.csproj b/csharp/unit-testing-code-coverage/Numbers/Numbers.csproj new file mode 100644 index 00000000000..9f5c4f4abb6 --- /dev/null +++ b/csharp/unit-testing-code-coverage/Numbers/Numbers.csproj @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + diff --git a/csharp/unit-testing-code-coverage/Numbers/PrimeService.cs b/csharp/unit-testing-code-coverage/Numbers/PrimeService.cs new file mode 100644 index 00000000000..672b713fc02 --- /dev/null +++ b/csharp/unit-testing-code-coverage/Numbers/PrimeService.cs @@ -0,0 +1,22 @@ +namespace System.Numbers +{ + public class PrimeService + { + public bool IsPrime(int candidate) + { + if (candidate < 2) + { + return false; + } + + for (int divisor = 2; divisor <= Math.Sqrt(candidate); ++divisor) + { + if (candidate % divisor == 0) + { + return false; + } + } + return true; + } + } +} diff --git a/csharp/unit-testing-code-coverage/README.md b/csharp/unit-testing-code-coverage/README.md new file mode 100644 index 00000000000..5c2f6bb02a2 --- /dev/null +++ b/csharp/unit-testing-code-coverage/README.md @@ -0,0 +1,33 @@ +--- +languages: +- csharp +products: +- dotnet +- dotnet-core +page_type: sample +name: ".NET Core unit testing code coverage" +urlFragment: "unit-testing-code-coverage-cs" +description: ".NET Core unit testing code coverage and reporting with coverlet, and ReportGenerator." +--- + +# .NET Core unit testing code coverage + +This sample solution includes a class library that is unit tested by two xUnit test projects. The corresponding article, [use code coverage for unit testing](https://docs.microsoft.com/dotnet/core/testing/unit-testing-code-coverage) details the usage of C#, xUnit, coverlet, and ReportGenerator. + +## Sample prerequisites + +This sample is written in C# and targets .NET Core 3.1. It requires the [.NET Core 3.1 SDK](https://dotnet.microsoft.com/download/dotnet-core/3.1). + +## Building the sample + +The source code includes an MSBuild project file for C# (a *.csproj* file) that targets .NET Core 3.1. After you download the *.zip* file containing the example code, create a directory and select **Download ZIP** to download the sample code files to your computer. To build the example: + +1. Download the *.zip* file containing. +1. Create the directory to which you want to copy the files. +1. Copy the files from the *.zip* file to the directory you just created. +1. If you are using Visual Studio 2019: + 1. In Visual Studio, select **Open a project or solution** (or **File** > **Open** > **Project/Solution** from the Visual Studio menu. + 1. Select **Debug** > **Start Debugging** from the Visual Studio menu to build and launch the application. +1. If you are working from the command line: + 1. Navigate to the directory that contains the sample. + 1. Type in the command `dotnet run` to build and launch the application. diff --git a/csharp/unit-testing-code-coverage/XUnit.Coverage.sln b/csharp/unit-testing-code-coverage/XUnit.Coverage.sln new file mode 100644 index 00000000000..4ecf03e3a2f --- /dev/null +++ b/csharp/unit-testing-code-coverage/XUnit.Coverage.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30204.135 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XUnit.Coverlet.MSBuild", "XUnit.Coverlet.MSBuild\XUnit.Coverlet.MSBuild.csproj", "{D175215F-6236-4099-AF52-1A590D469C77}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XUnit.Coverlet.Collector", "XUnit.Coverlet.Collector\XUnit.Coverlet.Collector.csproj", "{2658198A-3AF7-41BC-9A4B-FC527B966ADE}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Numbers", "Numbers\Numbers.csproj", "{EE84B727-F32F-4AC0-AF3E-35ED1C2ABF54}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4B1428C5-6394-41F0-BD14-E5D600734E9D}" + ProjectSection(SolutionItems) = preProject + .gitignore = .gitignore + README.md = README.md + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D175215F-6236-4099-AF52-1A590D469C77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D175215F-6236-4099-AF52-1A590D469C77}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D175215F-6236-4099-AF52-1A590D469C77}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D175215F-6236-4099-AF52-1A590D469C77}.Release|Any CPU.Build.0 = Release|Any CPU + {2658198A-3AF7-41BC-9A4B-FC527B966ADE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2658198A-3AF7-41BC-9A4B-FC527B966ADE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2658198A-3AF7-41BC-9A4B-FC527B966ADE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2658198A-3AF7-41BC-9A4B-FC527B966ADE}.Release|Any CPU.Build.0 = Release|Any CPU + {EE84B727-F32F-4AC0-AF3E-35ED1C2ABF54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EE84B727-F32F-4AC0-AF3E-35ED1C2ABF54}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EE84B727-F32F-4AC0-AF3E-35ED1C2ABF54}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EE84B727-F32F-4AC0-AF3E-35ED1C2ABF54}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6FC1D618-6596-4B95-AE0F-AE47427A6748} + EndGlobalSection +EndGlobal diff --git a/csharp/unit-testing-code-coverage/XUnit.Coverlet.Collector/PrimeServiceTests.cs b/csharp/unit-testing-code-coverage/XUnit.Coverlet.Collector/PrimeServiceTests.cs new file mode 100644 index 00000000000..fa0bffd5f9e --- /dev/null +++ b/csharp/unit-testing-code-coverage/XUnit.Coverlet.Collector/PrimeServiceTests.cs @@ -0,0 +1,33 @@ +using System.Numbers; +using Xunit; + +namespace XUnit.Coverlet +{ + public class PrimeServiceTests + { + readonly PrimeService _primeService; + + public PrimeServiceTests() => _primeService = new PrimeService(); + + [ + Theory, + InlineData(-1), InlineData(0), InlineData(1) + ] + public void IsPrime_ValuesLessThan2_ReturnFalse(int value) => + Assert.False(_primeService.IsPrime(value), $"{value} should not be prime"); + + [ + Theory, + InlineData(2), InlineData(3), InlineData(5), InlineData(7) + ] + public void IsPrime_PrimesLessThan10_ReturnTrue(int value) => + Assert.True(_primeService.IsPrime(value), $"{value} should be prime"); + + [ + Theory, + InlineData(4), InlineData(6), InlineData(8), InlineData(9) + ] + public void IsPrime_NonPrimesLessThan10_ReturnFalse(int value) => + Assert.False(_primeService.IsPrime(value), $"{value} should not be prime"); + } +} diff --git a/csharp/unit-testing-code-coverage/XUnit.Coverlet.Collector/XUnit.Coverlet.Collector.csproj b/csharp/unit-testing-code-coverage/XUnit.Coverlet.Collector/XUnit.Coverlet.Collector.csproj new file mode 100644 index 00000000000..450328e5cd0 --- /dev/null +++ b/csharp/unit-testing-code-coverage/XUnit.Coverlet.Collector/XUnit.Coverlet.Collector.csproj @@ -0,0 +1,31 @@ + + + + netcoreapp3.1 + + false + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + diff --git a/csharp/unit-testing-code-coverage/XUnit.Coverlet.MSBuild/PrimeServiceTests.cs b/csharp/unit-testing-code-coverage/XUnit.Coverlet.MSBuild/PrimeServiceTests.cs new file mode 100644 index 00000000000..fa0bffd5f9e --- /dev/null +++ b/csharp/unit-testing-code-coverage/XUnit.Coverlet.MSBuild/PrimeServiceTests.cs @@ -0,0 +1,33 @@ +using System.Numbers; +using Xunit; + +namespace XUnit.Coverlet +{ + public class PrimeServiceTests + { + readonly PrimeService _primeService; + + public PrimeServiceTests() => _primeService = new PrimeService(); + + [ + Theory, + InlineData(-1), InlineData(0), InlineData(1) + ] + public void IsPrime_ValuesLessThan2_ReturnFalse(int value) => + Assert.False(_primeService.IsPrime(value), $"{value} should not be prime"); + + [ + Theory, + InlineData(2), InlineData(3), InlineData(5), InlineData(7) + ] + public void IsPrime_PrimesLessThan10_ReturnTrue(int value) => + Assert.True(_primeService.IsPrime(value), $"{value} should be prime"); + + [ + Theory, + InlineData(4), InlineData(6), InlineData(8), InlineData(9) + ] + public void IsPrime_NonPrimesLessThan10_ReturnFalse(int value) => + Assert.False(_primeService.IsPrime(value), $"{value} should not be prime"); + } +} diff --git a/csharp/unit-testing-code-coverage/XUnit.Coverlet.MSBuild/XUnit.Coverlet.MSBuild.csproj b/csharp/unit-testing-code-coverage/XUnit.Coverlet.MSBuild/XUnit.Coverlet.MSBuild.csproj new file mode 100644 index 00000000000..7359b90af35 --- /dev/null +++ b/csharp/unit-testing-code-coverage/XUnit.Coverlet.MSBuild/XUnit.Coverlet.MSBuild.csproj @@ -0,0 +1,30 @@ + + + + netcoreapp3.1 + + false + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/csharp/unit-testing/.gitignore b/csharp/unit-testing/.gitignore new file mode 100644 index 00000000000..d6bc47910f7 --- /dev/null +++ b/csharp/unit-testing/.gitignore @@ -0,0 +1,3 @@ +/TestResults/* +/Reports/* +coverage.json diff --git a/csharp/unit-testing/MSTest.Project/MSTest.Project.csproj b/csharp/unit-testing/MSTest.Project/MSTest.Project.csproj index a45be4b8a75..8cc1f6a3fce 100644 --- a/csharp/unit-testing/MSTest.Project/MSTest.Project.csproj +++ b/csharp/unit-testing/MSTest.Project/MSTest.Project.csproj @@ -7,10 +7,13 @@ - - - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/csharp/unit-testing/NUnit.TestProject/NUnit.Project.csproj b/csharp/unit-testing/NUnit.TestProject/NUnit.Project.csproj index 3737e9ea44f..c17585ba1c2 100644 --- a/csharp/unit-testing/NUnit.TestProject/NUnit.Project.csproj +++ b/csharp/unit-testing/NUnit.TestProject/NUnit.Project.csproj @@ -9,7 +9,7 @@ - + diff --git a/csharp/unit-testing/Numbers/Numbers.csproj b/csharp/unit-testing/Numbers/Numbers.csproj new file mode 100644 index 00000000000..9f5c4f4abb6 --- /dev/null +++ b/csharp/unit-testing/Numbers/Numbers.csproj @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + diff --git a/csharp/unit-testing/Numbers/PrimeService.cs b/csharp/unit-testing/Numbers/PrimeService.cs new file mode 100644 index 00000000000..7882b6b4307 --- /dev/null +++ b/csharp/unit-testing/Numbers/PrimeService.cs @@ -0,0 +1,25 @@ +using System; + +namespace Numbers +{ + public class PrimeService + { + public bool IsPrime(int candidate) + { + if (candidate < 2) + { + return false; + } + + for (int divisor = 2; divisor <= Math.Sqrt(candidate); ++ divisor) + { + if (candidate % divisor == 0) + { + return false; + } + } + return true; + + } + } +} diff --git a/csharp/unit-testing/UnitTesting.sln b/csharp/unit-testing/UnitTesting.sln index 2a346661ec9..eaa212dc613 100644 --- a/csharp/unit-testing/UnitTesting.sln +++ b/csharp/unit-testing/UnitTesting.sln @@ -3,17 +3,24 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30104.148 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XUnit.Project", "XUnit.TestProject\XUnit.Project.csproj", "{04082197-A92E-49DC-8349-F11CB93D9E8E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XUnit.Project", "XUnit.TestProject\XUnit.Project.csproj", "{04082197-A92E-49DC-8349-F11CB93D9E8E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NUnit.Project", "NUnit.TestProject\NUnit.Project.csproj", "{20D0BC71-F331-4D52-B281-7E743386C536}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NUnit.Project", "NUnit.TestProject\NUnit.Project.csproj", "{20D0BC71-F331-4D52-B281-7E743386C536}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSTest.Project", "MSTest.Project\MSTest.Project.csproj", "{2BFAD3EE-A562-4825-995D-462484112A59}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSTest.Project", "MSTest.Project\MSTest.Project.csproj", "{2BFAD3EE-A562-4825-995D-462484112A59}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{11197C29-FF8A-40DA-8E27-9BD52125EAF8}" ProjectSection(SolutionItems) = preProject + .gitignore = .gitignore README.md = README.md EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XUnit.Coverlet.Collector", "XUnit.Coverlet.Collector\XUnit.Coverlet.Collector.csproj", "{21BCE9AE-A737-4D42-B215-D542324C2333}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Numbers", "Numbers\Numbers.csproj", "{AAA46FA3-94B5-4D04-8A1A-C91207116A10}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XUnit.Coverlet.MSBuild", "XUnit.Coverlet.MSBuild\XUnit.Coverlet.MSBuild.csproj", "{2A589CDE-DEDE-46D3-A9AC-EB80447D9572}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -32,6 +39,18 @@ Global {2BFAD3EE-A562-4825-995D-462484112A59}.Debug|Any CPU.Build.0 = Debug|Any CPU {2BFAD3EE-A562-4825-995D-462484112A59}.Release|Any CPU.ActiveCfg = Release|Any CPU {2BFAD3EE-A562-4825-995D-462484112A59}.Release|Any CPU.Build.0 = Release|Any CPU + {21BCE9AE-A737-4D42-B215-D542324C2333}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {21BCE9AE-A737-4D42-B215-D542324C2333}.Debug|Any CPU.Build.0 = Debug|Any CPU + {21BCE9AE-A737-4D42-B215-D542324C2333}.Release|Any CPU.ActiveCfg = Release|Any CPU + {21BCE9AE-A737-4D42-B215-D542324C2333}.Release|Any CPU.Build.0 = Release|Any CPU + {AAA46FA3-94B5-4D04-8A1A-C91207116A10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AAA46FA3-94B5-4D04-8A1A-C91207116A10}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AAA46FA3-94B5-4D04-8A1A-C91207116A10}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AAA46FA3-94B5-4D04-8A1A-C91207116A10}.Release|Any CPU.Build.0 = Release|Any CPU + {2A589CDE-DEDE-46D3-A9AC-EB80447D9572}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2A589CDE-DEDE-46D3-A9AC-EB80447D9572}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2A589CDE-DEDE-46D3-A9AC-EB80447D9572}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2A589CDE-DEDE-46D3-A9AC-EB80447D9572}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/csharp/unit-testing/XUnit.Coverlet.Collector/PrimeServiceTests.cs b/csharp/unit-testing/XUnit.Coverlet.Collector/PrimeServiceTests.cs new file mode 100644 index 00000000000..15f58cc93dc --- /dev/null +++ b/csharp/unit-testing/XUnit.Coverlet.Collector/PrimeServiceTests.cs @@ -0,0 +1,33 @@ +using Numbers; +using Xunit; + +namespace XUnit.CodeCoverage +{ + public class PrimeServiceTests + { + readonly PrimeService _primeService; + + public PrimeServiceTests() => _primeService = new PrimeService(); + + [ + Theory, + InlineData(-1), InlineData(0), InlineData(1) + ] + public void IsPrime_ValuesLessThan2_ReturnFalse(int value) => + Assert.False(_primeService.IsPrime(value), $"{value} should not be prime"); + + [ + Theory, + InlineData(2), InlineData(3), InlineData(5), InlineData(7) + ] + public void IsPrime_PrimesLessThan10_ReturnTrue(int value) => + Assert.True(_primeService.IsPrime(value), $"{value} should be prime"); + + [ + Theory, + InlineData(4), InlineData(6), InlineData(8), InlineData(9) + ] + public void IsPrime_NonPrimesLessThan10_ReturnFalse(int value) => + Assert.False(_primeService.IsPrime(value), $"{value} should not be prime"); + } +} diff --git a/csharp/unit-testing/XUnit.Coverlet.Collector/XUnit.Coverlet.Collector.csproj b/csharp/unit-testing/XUnit.Coverlet.Collector/XUnit.Coverlet.Collector.csproj new file mode 100644 index 00000000000..450328e5cd0 --- /dev/null +++ b/csharp/unit-testing/XUnit.Coverlet.Collector/XUnit.Coverlet.Collector.csproj @@ -0,0 +1,31 @@ + + + + netcoreapp3.1 + + false + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + diff --git a/csharp/unit-testing/XUnit.Coverlet.MSBuild/PrimeServiceTests.cs b/csharp/unit-testing/XUnit.Coverlet.MSBuild/PrimeServiceTests.cs new file mode 100644 index 00000000000..2bbe4e1d4f2 --- /dev/null +++ b/csharp/unit-testing/XUnit.Coverlet.MSBuild/PrimeServiceTests.cs @@ -0,0 +1,33 @@ +using Numbers; +using Xunit; + +namespace XUnit.Coverlet.MSBuild +{ + public class PrimeServiceTests + { + readonly PrimeService _primeService; + + public PrimeServiceTests() => _primeService = new PrimeService(); + + [ + Theory, + InlineData(-1), InlineData(0), InlineData(1) + ] + public void IsPrime_ValuesLessThan2_ReturnFalse(int value) => + Assert.False(_primeService.IsPrime(value), $"{value} should not be prime"); + + [ + Theory, + InlineData(2), InlineData(3), InlineData(5), InlineData(7) + ] + public void IsPrime_PrimesLessThan10_ReturnTrue(int value) => + Assert.True(_primeService.IsPrime(value), $"{value} should be prime"); + + [ + Theory, + InlineData(4), InlineData(6), InlineData(8), InlineData(9) + ] + public void IsPrime_NonPrimesLessThan10_ReturnFalse(int value) => + Assert.False(_primeService.IsPrime(value), $"{value} should not be prime"); + } +} diff --git a/csharp/unit-testing/XUnit.Coverlet.MSBuild/XUnit.Coverlet.MSBuild.csproj b/csharp/unit-testing/XUnit.Coverlet.MSBuild/XUnit.Coverlet.MSBuild.csproj new file mode 100644 index 00000000000..7359b90af35 --- /dev/null +++ b/csharp/unit-testing/XUnit.Coverlet.MSBuild/XUnit.Coverlet.MSBuild.csproj @@ -0,0 +1,30 @@ + + + + netcoreapp3.1 + + false + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/csharp/unit-testing/XUnit.TestProject/XUnit.Project.csproj b/csharp/unit-testing/XUnit.TestProject/XUnit.Project.csproj index b84acb879c1..c4da77dfc15 100644 --- a/csharp/unit-testing/XUnit.TestProject/XUnit.Project.csproj +++ b/csharp/unit-testing/XUnit.TestProject/XUnit.Project.csproj @@ -7,10 +7,16 @@ - - - - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + From f8ee93f84935c47ebfbf5baa852cb78134680bbb Mon Sep 17 00:00:00 2001 From: David Pine Date: Tue, 16 Jun 2020 10:47:34 -0500 Subject: [PATCH 2/3] Remove projects that were moved --- csharp/unit-testing/Numbers/Numbers.csproj | 7 ---- csharp/unit-testing/Numbers/PrimeService.cs | 25 -------------- .../PrimeServiceTests.cs | 33 ------------------- .../XUnit.Coverlet.Collector.csproj | 31 ----------------- .../PrimeServiceTests.cs | 33 ------------------- .../XUnit.Coverlet.MSBuild.csproj | 30 ----------------- 6 files changed, 159 deletions(-) delete mode 100644 csharp/unit-testing/Numbers/Numbers.csproj delete mode 100644 csharp/unit-testing/Numbers/PrimeService.cs delete mode 100644 csharp/unit-testing/XUnit.Coverlet.Collector/PrimeServiceTests.cs delete mode 100644 csharp/unit-testing/XUnit.Coverlet.Collector/XUnit.Coverlet.Collector.csproj delete mode 100644 csharp/unit-testing/XUnit.Coverlet.MSBuild/PrimeServiceTests.cs delete mode 100644 csharp/unit-testing/XUnit.Coverlet.MSBuild/XUnit.Coverlet.MSBuild.csproj diff --git a/csharp/unit-testing/Numbers/Numbers.csproj b/csharp/unit-testing/Numbers/Numbers.csproj deleted file mode 100644 index 9f5c4f4abb6..00000000000 --- a/csharp/unit-testing/Numbers/Numbers.csproj +++ /dev/null @@ -1,7 +0,0 @@ - - - - netstandard2.0 - - - diff --git a/csharp/unit-testing/Numbers/PrimeService.cs b/csharp/unit-testing/Numbers/PrimeService.cs deleted file mode 100644 index 7882b6b4307..00000000000 --- a/csharp/unit-testing/Numbers/PrimeService.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; - -namespace Numbers -{ - public class PrimeService - { - public bool IsPrime(int candidate) - { - if (candidate < 2) - { - return false; - } - - for (int divisor = 2; divisor <= Math.Sqrt(candidate); ++ divisor) - { - if (candidate % divisor == 0) - { - return false; - } - } - return true; - - } - } -} diff --git a/csharp/unit-testing/XUnit.Coverlet.Collector/PrimeServiceTests.cs b/csharp/unit-testing/XUnit.Coverlet.Collector/PrimeServiceTests.cs deleted file mode 100644 index 15f58cc93dc..00000000000 --- a/csharp/unit-testing/XUnit.Coverlet.Collector/PrimeServiceTests.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Numbers; -using Xunit; - -namespace XUnit.CodeCoverage -{ - public class PrimeServiceTests - { - readonly PrimeService _primeService; - - public PrimeServiceTests() => _primeService = new PrimeService(); - - [ - Theory, - InlineData(-1), InlineData(0), InlineData(1) - ] - public void IsPrime_ValuesLessThan2_ReturnFalse(int value) => - Assert.False(_primeService.IsPrime(value), $"{value} should not be prime"); - - [ - Theory, - InlineData(2), InlineData(3), InlineData(5), InlineData(7) - ] - public void IsPrime_PrimesLessThan10_ReturnTrue(int value) => - Assert.True(_primeService.IsPrime(value), $"{value} should be prime"); - - [ - Theory, - InlineData(4), InlineData(6), InlineData(8), InlineData(9) - ] - public void IsPrime_NonPrimesLessThan10_ReturnFalse(int value) => - Assert.False(_primeService.IsPrime(value), $"{value} should not be prime"); - } -} diff --git a/csharp/unit-testing/XUnit.Coverlet.Collector/XUnit.Coverlet.Collector.csproj b/csharp/unit-testing/XUnit.Coverlet.Collector/XUnit.Coverlet.Collector.csproj deleted file mode 100644 index 450328e5cd0..00000000000 --- a/csharp/unit-testing/XUnit.Coverlet.Collector/XUnit.Coverlet.Collector.csproj +++ /dev/null @@ -1,31 +0,0 @@ - - - - netcoreapp3.1 - - false - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - diff --git a/csharp/unit-testing/XUnit.Coverlet.MSBuild/PrimeServiceTests.cs b/csharp/unit-testing/XUnit.Coverlet.MSBuild/PrimeServiceTests.cs deleted file mode 100644 index 2bbe4e1d4f2..00000000000 --- a/csharp/unit-testing/XUnit.Coverlet.MSBuild/PrimeServiceTests.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Numbers; -using Xunit; - -namespace XUnit.Coverlet.MSBuild -{ - public class PrimeServiceTests - { - readonly PrimeService _primeService; - - public PrimeServiceTests() => _primeService = new PrimeService(); - - [ - Theory, - InlineData(-1), InlineData(0), InlineData(1) - ] - public void IsPrime_ValuesLessThan2_ReturnFalse(int value) => - Assert.False(_primeService.IsPrime(value), $"{value} should not be prime"); - - [ - Theory, - InlineData(2), InlineData(3), InlineData(5), InlineData(7) - ] - public void IsPrime_PrimesLessThan10_ReturnTrue(int value) => - Assert.True(_primeService.IsPrime(value), $"{value} should be prime"); - - [ - Theory, - InlineData(4), InlineData(6), InlineData(8), InlineData(9) - ] - public void IsPrime_NonPrimesLessThan10_ReturnFalse(int value) => - Assert.False(_primeService.IsPrime(value), $"{value} should not be prime"); - } -} diff --git a/csharp/unit-testing/XUnit.Coverlet.MSBuild/XUnit.Coverlet.MSBuild.csproj b/csharp/unit-testing/XUnit.Coverlet.MSBuild/XUnit.Coverlet.MSBuild.csproj deleted file mode 100644 index 7359b90af35..00000000000 --- a/csharp/unit-testing/XUnit.Coverlet.MSBuild/XUnit.Coverlet.MSBuild.csproj +++ /dev/null @@ -1,30 +0,0 @@ - - - - netcoreapp3.1 - - false - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - From 7a87131dcb77869a93cf53ec6715a14f11568f3b Mon Sep 17 00:00:00 2001 From: David Pine Date: Tue, 16 Jun 2020 10:49:11 -0500 Subject: [PATCH 3/3] Remove from sln too --- csharp/unit-testing/UnitTesting.sln | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/csharp/unit-testing/UnitTesting.sln b/csharp/unit-testing/UnitTesting.sln index eaa212dc613..bc97bf3b600 100644 --- a/csharp/unit-testing/UnitTesting.sln +++ b/csharp/unit-testing/UnitTesting.sln @@ -15,12 +15,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution README.md = README.md EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XUnit.Coverlet.Collector", "XUnit.Coverlet.Collector\XUnit.Coverlet.Collector.csproj", "{21BCE9AE-A737-4D42-B215-D542324C2333}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Numbers", "Numbers\Numbers.csproj", "{AAA46FA3-94B5-4D04-8A1A-C91207116A10}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XUnit.Coverlet.MSBuild", "XUnit.Coverlet.MSBuild\XUnit.Coverlet.MSBuild.csproj", "{2A589CDE-DEDE-46D3-A9AC-EB80447D9572}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -39,18 +33,6 @@ Global {2BFAD3EE-A562-4825-995D-462484112A59}.Debug|Any CPU.Build.0 = Debug|Any CPU {2BFAD3EE-A562-4825-995D-462484112A59}.Release|Any CPU.ActiveCfg = Release|Any CPU {2BFAD3EE-A562-4825-995D-462484112A59}.Release|Any CPU.Build.0 = Release|Any CPU - {21BCE9AE-A737-4D42-B215-D542324C2333}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {21BCE9AE-A737-4D42-B215-D542324C2333}.Debug|Any CPU.Build.0 = Debug|Any CPU - {21BCE9AE-A737-4D42-B215-D542324C2333}.Release|Any CPU.ActiveCfg = Release|Any CPU - {21BCE9AE-A737-4D42-B215-D542324C2333}.Release|Any CPU.Build.0 = Release|Any CPU - {AAA46FA3-94B5-4D04-8A1A-C91207116A10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AAA46FA3-94B5-4D04-8A1A-C91207116A10}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AAA46FA3-94B5-4D04-8A1A-C91207116A10}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AAA46FA3-94B5-4D04-8A1A-C91207116A10}.Release|Any CPU.Build.0 = Release|Any CPU - {2A589CDE-DEDE-46D3-A9AC-EB80447D9572}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2A589CDE-DEDE-46D3-A9AC-EB80447D9572}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2A589CDE-DEDE-46D3-A9AC-EB80447D9572}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2A589CDE-DEDE-46D3-A9AC-EB80447D9572}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE