{"id":20113414,"url":"https://github.com/cloudacademy/csharp-tdd-bitcoinconverter","last_synced_at":"2025-05-06T12:30:32.213Z","repository":{"id":77791455,"uuid":"301293020","full_name":"cloudacademy/csharp-tdd-bitcoinconverter","owner":"cloudacademy","description":"Dotnet Core 3.1 CSharp TDD Bitcoin Converter Project","archived":false,"fork":false,"pushed_at":"2023-04-17T03:04:00.000Z","size":116,"stargazers_count":5,"open_issues_count":0,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-09T12:11:46.090Z","etag":null,"topics":["bitcoin","cloudacademy","csharp","devops","dotnet","moq","tdd","xunit"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloudacademy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-05T04:29:43.000Z","updated_at":"2023-12-12T15:29:17.000Z","dependencies_parsed_at":"2023-04-30T04:17:11.136Z","dependency_job_id":null,"html_url":"https://github.com/cloudacademy/csharp-tdd-bitcoinconverter","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudacademy%2Fcsharp-tdd-bitcoinconverter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudacademy%2Fcsharp-tdd-bitcoinconverter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudacademy%2Fcsharp-tdd-bitcoinconverter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudacademy%2Fcsharp-tdd-bitcoinconverter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudacademy","download_url":"https://codeload.github.com/cloudacademy/csharp-tdd-bitcoinconverter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252683367,"owners_count":21788026,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitcoin","cloudacademy","csharp","devops","dotnet","moq","tdd","xunit"],"created_at":"2024-11-13T18:24:21.342Z","updated_at":"2025-05-06T12:30:32.201Z","avatar_url":"https://github.com/cloudacademy.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C# TDD Bitcoin Converter\n\n[![Build Status](https://github.com/cloudacademy/csharp-tdd-bitcoinconverter/workflows/bitcoinconverter.build/badge.svg)](https://github.com/cloudacademy/csharp-tdd-bitcoinconverter/actions) [![Coverage Status](https://coveralls.io/repos/github/cloudacademy/csharp-tdd-bitcoinconverter/badge.svg?branch=main)](https://coveralls.io/github/cloudacademy/csharp-tdd-bitcoinconverter?branch=main)\n\n## Background\nThe following repo contains source code developed using TDD (Test Driven Development) practices. The sample project implements a .Net Core 3.1 C# library which interacts with the [Bitcoin Price Index](https://www.coindesk.com/coindesk-api) api.\n\n![Bitcoin Converter Architecture](./docs/csharp-tdd-bitcoinconverter.png)\n\n**Note**: If you intend to follow along and complete the full demonstration then please fork or setup a new GitHub repo - as step 9 will require you to create a GitHub Secret to store the [Coveralls](https://coveralls.io/) project token. Coveralls is used to create code coverage reports and visuals.\n\n:metal:\n\n## Prerequisites\n**.Net Core 3.1** is required for this project. \n\nThe provided C# code and instructions have been tested with the following version:\n\n```\ndotnet --version\n3.1.403\n```\n\n## Tools and Frameworks\nThe following tools and frameworks have been used to perform the TDD developement:\n* [xUnit](https://xunit.net/) - a unit testing framework, used to implement unit tests\n* [Moq](https://github.com/Moq/moq4/wiki/Quickstart) - a mocking library, used to create mocks for external dependencies\n* [GitHub Actions](https://github.com/features/actions) - used to provide CICD features for automated building and testing\n* [Coveralls](https://coveralls.io/) - used to provide unit test code coverage reports\n\n## Repo Branches\nBranches are used within this repo to demonstrate the TDD workflow (red, green, refactor), as well as highlighting other project management configuration areas. These branches allow you to quickly jump ahead to the area of interest:\n\n### Branches\n* [step1](https://github.com/cloudacademy/csharp-tdd-bitcoinconverter/tree/step1) - demonstrates using the ```dotnet``` command to setup the project structure and create the first set of unit tests using xUnit and the ```[Fact]``` attribute\n\n* [step2](https://github.com/cloudacademy/csharp-tdd-bitcoinconverter/tree/step2) - refactors current unit tests and codebase using the ```[Theory]``` attribute - also demonstrates the use of the ```dotnet watch``` command to automatically execute all unit tests whenever the source code is changed\n\n* [step3](https://github.com/cloudacademy/csharp-tdd-bitcoinconverter/tree/step3) - refactors the unit tests and codebase to use the async/await keywords to manage asynchronous HTTP comms with the Bitcoin API online service\n\n* [step4](https://github.com/cloudacademy/csharp-tdd-bitcoinconverter/tree/step4) - introduces the Moq library to mock out the external Bitcoin API service dependency\n\n* [step5](https://github.com/cloudacademy/csharp-tdd-bitcoinconverter/tree/step5) - refactors the unit tests and codebase to add addtional unit tests to test error conditions\n\n* [step6](https://github.com/cloudacademy/csharp-tdd-bitcoinconverter/tree/step6) - adds in a GitHub Action workflow to perform automatic build and tests on push events - produces a DLL artifact\n\n* [step7](https://github.com/cloudacademy/csharp-tdd-bitcoinconverter/tree/step7) - updates the GitHub Action workflow to automatically produce a release for the built DLL artifact on tag events only\n\n* [step8](https://github.com/cloudacademy/csharp-tdd-bitcoinconverter/tree/step8) - creates a client console project to test the GitHub Action built DLL artifact - additonally adds badges to the README.md to render the current build status\n\n* [step9](https://github.com/cloudacademy/csharp-tdd-bitcoinconverter/tree/step9) - updates the existing GitHub Action to generate a unit test code coverage report and have it automatically uploaded into https://coveralls.io/ for viewing\n\n**Note**: The [main](https://github.com/cloudacademy/csharp-tdd-bitcoinconverter/tree/main) branch (this branch) contains the same code and configuration as contained in the [step9](https://github.com/cloudacademy/csharp-tdd-bitcoinconverter/tree/step9) branch\n\n## Bitcoin Converter Library\nThis project builds a .Net Core 3.1 library which contains the following 2 public methods:\n```csharp\npublic async Task\u003cdouble\u003e GetExchangeRate(Currency currency)\n```\nreturns in realtime the current Bitcoin exchange rate for the given currency (USD, GBP, or EUR)\n\n```csharp\npublic async Task\u003cdouble\u003e ConvertBitcoins(Currency currency, double coins)\n```\nreturns the dollar value for the given currency (USD, GBP, or EUR), and the number of Bitcoins\n\nTo build the Bitcoin Converter Library perform the following commands:\n\n```\ndotnet build\n```\n\n## Bitcoin Converter Client\nThis project also contains a sample [client](https://github.com/cloudacademy/csharp-tdd-bitcoinconverter/tree/main/BitcoinConverter.Client) console based application - which imports the Bitcoin Converter library. To build and run the client for Linux x64 distros, perform the following commands:\n\n```bash\n#build/package executable file\ncd BitcoinConverter.Client\ndotnet publish --runtime linux-x64 --configuration Release /p:TargetFramework=netcoreapp3.1 /p:PublishSingleFile=true /p:PublishTrimmed=true\n\n#run executable:\n./BitcoinConverter.Client\n```\n\n## GitHub Action - CICD\nThis project demonstrates how to use [GitHub Actions](https://github.com/cloudacademy/csharp-tdd-bitcoinconverter/blob/main/.github/workflows/dotnet-core.yml) to perform automated builds, testing, packaging, and releases.\n\n### dotnet-core.yml\n```\nname: bitcoinconverter.build\n\non: push\n\njobs:\n  build:\n\n    runs-on: ubuntu-latest\n\n    steps:\n    - uses: actions/checkout@v2\n\n    - name: Setup .NET Core\n      uses: actions/setup-dotnet@v1\n      with:\n        dotnet-version: 3.1.402\n\n    - name: Install Dependencies\n      run: dotnet restore\n\n    - name: Build\n      run: dotnet build --configuration Release --no-restore\n\n    - name: Test\n      run: dotnet test --no-restore --verbosity normal\n\n    - name: Generate Test Coverage Report\n      run: |\n        ls -la\n        mkdir -p BitcoinConverter.Tests/TestResults\n        cd BitcoinConverter.Tests\n        dotnet test /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:CoverletOutputFormat=lcov\n    - name: Publish Test Coverage Report\n      uses: coverallsapp/github-action@v1.1.2\n      with:\n        github-token: ${{ secrets.GITHUB_TOKEN }}\n        path-to-lcov: BitcoinConverter.Tests/TestResults/coverage.info\n\n    - name: Upload Artifact\n      uses: actions/upload-artifact@v1.0.0\n      with:\n        name: BitcoinConverter.Code.dll\n        path: BitcoinConverter.Code/bin/Release/netcoreapp3.1/BitcoinConverter.Code.dll\n\n    - name: Make Release\n      uses: softprops/action-gh-release@v0.1.5\n      if: startsWith(github.ref, 'refs/tags/')\n      with:\n        files:\n          BitcoinConverter.Code/bin/Release/netcoreapp3.1/BitcoinConverter.Code.dll\n      env:\n        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n```\n\n## Coveralls - Code Coverage Report\nThis project forwards its unit testing code coverage reports to [coveralls.io](https://coveralls.io/github/cloudacademy/csharp-tdd-bitcoinconverter) for report viewing and analysis\n\n## Vagrant\nThe provided [Vagrantfile](https://github.com/cloudacademy/csharp-tdd-bitcoinconverter/blob/main/Vagrantfile) can be used to spin up an Ubuntu 18.04 instance - which can then be used to install the .Net Core 3.1 SDK, allowing you to easily follow along:\n\n```\nVagrant.configure(\"2\") do |config|\n  config.vm.box = \"ubuntu/bionic64\"\n  config.vm.provision \"shell\", inline: \u003c\u003c-SHELL\n    apt-get update\n  SHELL\nend\n```\n\nUse the following Vagrant command to launch the instance:\n\n```\nvagrant up\n```\n\nThen SSH into the instance by running the following command:\n\n```\nvagrant ssh\n```\n\nThe .Net Core 3.1 SDK can then be installed using the following instructions:\n\n```\nwget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb\nsudo dpkg -i packages-microsoft-prod.deb\nsudo apt-get update\nsudo apt-get install -y apt-transport-https\nsudo apt-get update\nsudo apt-get install -y dotnet-sdk-3.1\n```\n\nTo confirm that the .Net Core 3.1 SDK has been successfully installed, run the following command:\n\n```\ndotnet --version\n```\n\nBack on your local workstation, you can use Visual Studio Code or any other editor to open and modify the contents of the current folder - with all changes being automatically synced back into the ```/vagrant``` directory within the Vagrant instance.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudacademy%2Fcsharp-tdd-bitcoinconverter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudacademy%2Fcsharp-tdd-bitcoinconverter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudacademy%2Fcsharp-tdd-bitcoinconverter/lists"}