{"id":21534539,"url":"https://github.com/winseros/dependenciesmockingdemoproject","last_synced_at":"2025-03-17T20:14:49.002Z","repository":{"id":81337516,"uuid":"366522407","full_name":"winseros/DependenciesMockingDemoProject","owner":"winseros","description":"Tests are useful. This repo will demonstrate how to add integration tests to an ASP.NET Core web application.","archived":false,"fork":false,"pushed_at":"2021-05-12T13:13:00.000Z","size":129,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-24T07:11:28.725Z","etag":null,"topics":["asp-net-core","aspnetcore","integration-testing","test-automation","test-driven-development","testing"],"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/winseros.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":"2021-05-11T21:56:47.000Z","updated_at":"2023-09-08T18:22:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"239b8d65-64eb-41e7-8bdb-6da63ce6d17b","html_url":"https://github.com/winseros/DependenciesMockingDemoProject","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winseros%2FDependenciesMockingDemoProject","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winseros%2FDependenciesMockingDemoProject/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winseros%2FDependenciesMockingDemoProject/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winseros%2FDependenciesMockingDemoProject/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/winseros","download_url":"https://codeload.github.com/winseros/DependenciesMockingDemoProject/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244102855,"owners_count":20398386,"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":["asp-net-core","aspnetcore","integration-testing","test-automation","test-driven-development","testing"],"created_at":"2024-11-24T03:11:09.400Z","updated_at":"2025-03-17T20:14:48.984Z","avatar_url":"https://github.com/winseros.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mock dependencies demo project\r\n\r\nThis demonstrates how you can mock the external dependencies of the application when doing unit and integration tests.\r\n\r\nNote the code here to show you the idea, not to be accepted as the final truth.\r\n\r\n## Core features\r\n\r\n### Single button startup\r\n\r\nWhen a developer gets the codebase, the only thing he has to do - is run `docker-compose up`. That will run all the external dependencies the project needs.\r\n\r\n### Real database in tests\r\n\r\nYou can cover the code that invokes the real database with [tests](DependenciesMockingDemoProject.Test/Services/WeatherForecastServiceTest.cs). No \"in-memory\" stuff or other kinds of data-layer mocking. \r\n\r\nSuch tests are bigger than \"unit\" but still less than \"integration\", so I call them **\"component\"**.\r\n\r\n### Entity framework SQL output\r\n\r\nWhen running **component** tests, the test output shows the SQL generated by Entity Framework. That helps to build queries the right way. \r\n\r\n![SQL output in test window](doc/01-sql-in-tests.png \"SQL output in test window\")\r\n\r\n### Integration tests\r\n\r\nThe test engine runs the real application, allowing you to make real HTTP calls to it [in a test](DependenciesMockingDemoProject.Int/Controllers/WeatherForecastControllerTest.cs).\r\n\r\n### Application log output\r\n\r\nIntegration tests output the application logs. That helps to ensure you've logged the right things the right way.\r\n\r\n![Application log output in test window](doc/02-logs-in-tests.png \"Application log output in test window\")\r\n\r\n### External HTTP mock\r\n\r\nThe project uses the [Open Weather Map Api](https://openweathermap.org/api). The tests don't call the real service but use its [mock](DependenciesMockingDemoProject.Int/Controllers/WeatherForecastControllerTest.cs#L56-L62) instead.\r\n\r\n## Running the project\r\n\r\n1. Run `docker-compose up`\r\n   \r\n   There is a caveat here. Git has a setting to convert line-endings to `CRLF` on its own disposal, and **on windows this setting is often ON**. The command will fail if [*.sh](./.mssql/) files here get their line endings changed to `CRLF`. The setting can be disabled locally via `git config --local core.autocrlf false`.\r\n2. Run `dotnet test`\r\n3. Open the project in your favorite IDE\r\n3. Do the development\r\n\r\n## Managing Entity Framework migrations\r\n\r\nTo manage the Entity Framework migrations, you need to set the `ENVIRONMENT` system variable to `Development` before. Otherwise, the migration management will fail.\r\n\r\n```pwsh\r\n$env:ENVIRONMENT=\"Development\" \r\ndotnet ef migrations add -o DataLayer\\Migrations -p DependenciesMockingDemoProject.Web\\DependenciesMockingDemoProject.Web.csproj \u003cMigrationName\u003e\r\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinseros%2Fdependenciesmockingdemoproject","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwinseros%2Fdependenciesmockingdemoproject","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinseros%2Fdependenciesmockingdemoproject/lists"}