diff --git a/.github/workflows/enforce-license-compliance.yml b/.github/workflows/enforce-license-compliance.yml new file mode 100644 index 0000000..86be741 --- /dev/null +++ b/.github/workflows/enforce-license-compliance.yml @@ -0,0 +1,14 @@ +name: Enforce License Compliance + +on: + pull_request: + branches: [main, master] + +jobs: + enforce-license-compliance: + runs-on: ubuntu-latest + steps: + - name: 'Enforce License Compliance' + uses: getsentry/action-enforce-license-compliance@57ba820387a1a9315a46115ee276b2968da51f3d # main + with: + fossa_api_key: ${{ secrets.FOSSA_API_KEY }} diff --git a/MyUnitTests/MyTargetClassTests.cs b/MyUnitTests/MyTargetClassTests.cs index cfe9454..b9f0601 100644 --- a/MyUnitTests/MyTargetClassTests.cs +++ b/MyUnitTests/MyTargetClassTests.cs @@ -24,5 +24,19 @@ public void VerifySubtraction() var intResult = objTargetClass.SubractNumbers(intFirstNumber, intsecondNumber); Assert.Equal(15 - 10, intResult); } + + [Fact] + public void VerifyDivision() + { + const int intFirstNumber = 15; + const int intsecondNumber = 10; + var objTargetClass = new MyTargetClass(); + + // in this though there seems to be some data loss. + var intResult = objTargetClass.DivideNumbers(intFirstNumber, intsecondNumber); + + // ensure this is always a int. + Assert.Equal((int)(15 / 10), intResult); + } } -} \ No newline at end of file +} diff --git a/README.md b/README.md index 3594e34..29f8b4e 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,29 @@ -# Codecov C# Example +# [Codecov](https://codecov.io) C# Example -| [https://codecov.io](https://codecov.io/) | [@codecov](https://twitter.com/codecov) | [hello@codecov.io](mailto:hello@codecov.io) | -| ----------------------- | ------------- | --------------------- | - -[![AppVeyor](https://img.shields.io/appveyor/ci/stevepeak/example-csharp.svg)](https://ci.appveyor.com/project/stevepeak/example-csharp/branch/master) [![codecov](https://codecov.io/gh/codecov/example-csharp/branch/master/graph/badge.svg)](https://codecov.io/gh/codecov/example-csharp) +[![AppVeyor](https://img.shields.io/appveyor/ci/stevepeak/example-csharp.svg)](https://ci.appveyor.com/project/stevepeak/example-csharp/branch/master) +[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-csharp.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-csharp?ref=badge_shield) -## Solution +## Guide +### AppVeyor Setup +Add to your `appveyor.yml` file. +```yml +image: Visual Studio 2015 -Start by restoring the nuget packages and building the solution. +before_build: +- nuget restore +- choco install opencover.portable +- choco install codecov -## Generate the Coverage File +build: + project: CodecovProject.sln + verbosity: minimal +test_script: +- OpenCover.Console.exe -register:user -target:"%xunit20%\xunit.console.x86.exe" -targetargs:".\MyUnitTests\bin\Debug\MyUnitTests.dll -noshadow" -filter:"+[UnitTestTargetProject*]* -[MyUnitTests*]*" -output:".\MyProject_coverage.xml" +- codecov -f "MyProject_coverage.xml +``` +### Producing Coverage Reports Coverage is generated using [OpenCover](https://github.com/OpenCover/opencover). You can obtain it from [NuGet](https://www.nuget.org/packages/opencover) or [Chocolatey](https://chocolatey.org/packages/opencover.portable). If we run the following command in PowerShell to install OpenCover via Chocolatey, ```powershell @@ -20,7 +32,11 @@ choco install opencover.portable the OpenCover commandline will become available. -### xUnit +Generation of coverage report is slighly different depending on the .NET platform of your test projects. + +#### .NET Framework project + +##### xUnit First install the xUnit console runner via [Nuget](https://www.nuget.org/packages/xunit.runner.console/2.3.0-beta1-build3642) or [Chocolatey](https://chocolatey.org/packages/XUnit). If we run the following in PowerShell to install xUnit via Chocolatey @@ -36,7 +52,7 @@ OpenCover.Console.exe -register:user -target:"xunit.console.x86.exe" -targetargs Then a coverage report will be generated. -### MSTest +##### MSTest Execute the following in your solution's root, @@ -46,34 +62,30 @@ OpenCover.Console.exe -register:user -target:"C:\Program Files (x86)\Microsoft V where you may need to change the `-target` flag to point to the correct version of MSTest. -## Uploading Report -Many options exit for uploading reports to Codecov. Three commonly used uploaders for .NET are +#### .NET Core project -1. [Codecov-exe](https://github.com/codecov/codecov-exe) (C# source code) -2. [Bash](https://github.com/codecov/codecov-bash) -3. [Python](https://github.com/codecov/codecov-python) +If you don't yet have .NET Core SDK installed, install it -For OS X and Linux builds, the recommended uploader is bash. For windows builds, all three uploaders work, but Codecov-exe does not require any dependencies. For example, the bash uploader and python uploader would require bash or python to be installed. This may or may not be an option. +```powershell +choco install dotnetcore-sdk +``` -### Codecov-exe +In case of .NET Core projects, there is no difference between `MSTest` and `xUnit` for coverage report generation. -First install Codecov-exe via [Nuget](https://www.nuget.org/packages/Codecov/) or [Chocolatey](https://chocolatey.org/packages/codecov). If we run the following in PowerShell to install it via Chocolatey +Make sure all covered projects generate full pdb file (not only test projects), either through `full` in the `.csproj` file or by using a Visual Studio: Project Properties > Build > Advanced > Debugging information. By default, projects created by `dotnet` or by Visual Studio use a portable format for pdb files. Support for portable pdb format [hasn't been released in OpenCover yet](https://github.com/OpenCover/opencover/issues/610). If you fail to set full pdb, the `OpenCover` will print out a message notifying you that it has no results along with common causes. -```powershell -choco install codecov -``` +The .NET Core test assembly can't be run by a `xunit.console.x86.exe`, because that tool works only with .NET Framework assemblies. The tests are run by `dotnet test` (possibly `dotnet xunit` if you [add dotnet-xunit](https://xunit.github.io/docs/getting-started-dotnet-core.html#create-project) CLI tool to your project). -and then run the following in PowerShell +Execute the following command in your solution's root: -``` -.\codecov -f "MyProject_coverage.xml" -t +```powershell +OpenCover.Console.exe -register:user -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:test -filter:"+[UnitTestTargetProject*]* -[MyUnitTests*]*" -output:".\MyProject_coverage.xml" -oldstyle ``` -the report will be uploaded. +where `-oldstyle` switch is necessary, because .NET Core uses `System.Private.CoreLib` instead of `mscorlib` and thus `OpenCover` can't use `mscorlib` for code instrumentation. You may also need to change the location of `dotnet.exe` to depending on the installed location. ### Bash - In bash run the following to upload the report ```bash @@ -82,21 +94,6 @@ chmod +x codecov ./codecov -f "MyProject_coverage.xml" -t ``` -### Python - -First installed python (if you don't have it already). A simple way to install python is [Chocolatey](https://chocolatey.org/packages/python) - -```powershell -choco install python -``` - -Next run the following in PowerShell - -``` -pip install codecov -.\codecov -f "MyProject_coverage.xml" -t -``` - ### Continous Integration The previous examples assumed local development. More commonly, you'll use a CI service like [AppVeyor](https://www.appveyor.com/) or [TeamCity](https://www.jetbrains.com/teamcity/). For TeamCity builds please see the [documentation](https://github.com/codecov/codecov-exe#teamcity). For AppVeyor builds using xUnit, your yaml file would look something like @@ -139,30 +136,15 @@ test_script: - .\packages\\codecov.exe -f "MyProject_coverage.xml" ``` -#### Python - -```yaml -image: Visual Studio 2015 - -before_build: -- nuget restore -- choco install opencover.portable - -build: - project: CodecovProject.sln - verbosity: minimal - -test_script: -- OpenCover.Console.exe -register:user -target:"%xunit20%\xunit.console.x86.exe" -targetargs:".\MyUnitTests\bin\Debug\MyUnitTests.dll -noshadow" -filter:"+[UnitTestTargetProject*]* -[MyUnitTests*]*" -output:".\MyProject_coverage.xml" -- "SET PATH=C:\\Python34;C:\\Python34\\Scripts;%PATH%" -- pip install codecov -- codecov -f "MyProject_coverage.xml" -``` - -## Cake.Codecov +## Caveats +### Private Repo +Repository tokens are required for (a) all private repos, (b) public repos not using Travis-CI, CircleCI, GitHub Actions, or AppVeyor. Find your repository token at Codecov and provide via appending `-t ` to you where you upload reports e.g. `.\codecov -f "MyProject_coverage.xml" -t ` -If you use [Cake](http://cakebuild.net/) (C# Make) for your build automation, there is a [Cake.Codecov](http://cakebuild.net/dsl/codecov/) addin available. Cake also has built in support for [OpenCover](http://cakebuild.net/dsl/opencover/). It makes using OpenCover and Codecov-exe really easy! +## Links +- [Community Boards](https://community.codecov.io) +- [Support](https://codecov.io/support) +- [Documentation](https://docs.codecov.io) -## Sample Project -An example C# project using AppVeyor, xUnit, OpenCover, and Codecov-exe is [DotNetAnalyzers/StyleCopAnalyzers](https://github.com/DotNetAnalyzers/StyleCopAnalyzers). +## License +[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-csharp.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-csharp?ref=badge_large) \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index f60a588..ed65b9a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -11,4 +11,4 @@ build: test_script: - OpenCover.Console.exe -register:user -target:"%xunit20%\xunit.console.x86.exe" -targetargs:".\MyUnitTests\bin\Debug\MyUnitTests.dll -noshadow" -filter:"+[UnitTestTargetProject*]* -[MyUnitTests*]*" -output:".\MyProject_coverage.xml" -- codecov -f "MyProject_coverage.xml \ No newline at end of file +- codecov -f "MyProject_coverage.xml"