{"id":21000941,"url":"https://github.com/managedcode/environmentdetector","last_synced_at":"2025-06-10T21:35:20.026Z","repository":{"id":64882919,"uuid":"578141400","full_name":"managedcode/EnvironmentDetector","owner":"managedcode","description":"Library that provides a simple way to detect whether your code is running in a test environment or not. It currently supports detecting MSTest, NUnit, and xUnit test frameworks.","archived":false,"fork":false,"pushed_at":"2024-05-27T14:29:54.000Z","size":45,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-17T14:13:41.808Z","etag":null,"topics":["dapr","detector","docker","environment","k8s","kubernetes","mstest","nunit","test","xunit"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/managedcode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2022-12-14T11:01:26.000Z","updated_at":"2024-05-27T14:29:57.000Z","dependencies_parsed_at":"2024-11-17T02:11:36.380Z","dependency_job_id":"1712fbc4-3f2e-4afe-9b5a-bb6d7b8e81fc","html_url":"https://github.com/managedcode/EnvironmentDetector","commit_stats":{"total_commits":13,"total_committers":2,"mean_commits":6.5,"dds":0.3846153846153846,"last_synced_commit":"a0b90922460bfd0fd8a4b06a010c945139664ae8"},"previous_names":["managedcode/testsdetector"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/managedcode%2FEnvironmentDetector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/managedcode%2FEnvironmentDetector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/managedcode%2FEnvironmentDetector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/managedcode%2FEnvironmentDetector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/managedcode","download_url":"https://codeload.github.com/managedcode/EnvironmentDetector/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254248329,"owners_count":22039006,"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":["dapr","detector","docker","environment","k8s","kubernetes","mstest","nunit","test","xunit"],"created_at":"2024-11-19T08:13:03.040Z","updated_at":"2025-05-14T23:31:58.611Z","avatar_url":"https://github.com/managedcode.png","language":"C#","readme":"# EnvironmentDetector\n\n[![.NET](https://github.com/managedcode/EnvironmentDetector/actions/workflows/dotnet.yml/badge.svg)](https://github.com/managedcode/EnvironmentDetector/actions/workflows/dotnet.yml)\n[![Coverage Status](https://coveralls.io/repos/github/managedcode/EnvironmentDetector/badge.svg?branch=main\u0026service=github)](https://coveralls.io/github/managedcode/EnvironmentDetector?branch=main)\n[![nuget](https://github.com/managedcode/EnvironmentDetector/actions/workflows/nuget.yml/badge.svg?branch=main)](https://github.com/managedcode/EnvironmentDetector/actions/workflows/nuget.yml)\n[![CodeQL](https://github.com/managedcode/EnvironmentDetector/actions/workflows/codeql-analysis.yml/badge.svg?branch=main)](https://github.com/managedcode/EnvironmentDetector/actions/workflows/codeql-analysis.yml)\n[![NuGet Package](https://img.shields.io/nuget/v/ManagedCode.EnvironmentDetector.svg)](https://www.nuget.org/packages/ManagedCode.EnvironmentDetector)\n\n\n\nEnvironmentDetector is a library that provides a simple way to detect whether your code is running in a test environment or not.\nIt currently supports detecting Dapr, Kubernetes, Docker, MSTest, NUnit, and xUnit.\n\n## Installation\n\nTo use EnvironmentDetector in your project, you'll need to install the NuGet package. \nYou can do this by running the following command in the Package Manager Console:\n\n```Install-Package ManagedCode.EnvironmentDetector```\n\nAlternatively, you can search for \"ManagedCode.EnvironmentDetector\" in the NuGet Package Manager in Visual Studio.\n\n## Usage\n\nEnvironmentDetector provides two ways to detect whether your code is running in a test environment or not.\n\nThe first way is to use the provided extension method IsTests on an instance of IHostEnvironment. Here's an example of how you might use this method in a Razor page:\n\n```csharp\nif (HostEnvironment.IsTests())\n{\n    app.AddFake();\n}\nelse if (HostEnvironment.IsKubernetes())\n{\n    app.AddKubernetes();\n}\nelse if (HostEnvironment.IsDapr())\n{\n    app.AddDapr();\n}\nelse if (HostEnvironment.IsDocker())\n{\n    app.AddDocker();\n}\n```\n\nThe second way to use EnvironmentDetector is to use the MSTestDetector.IsInTest static property. This can be useful if you don't have access to an instance of IHostEnvironment, or if you want to check whether you're running in a test environment in a static context. Here's an example of how you might use this property:\n\n```csharp\nusing ManagedCode.TestsDetector;\n\nif (MSTestDetector.IsInTest)\n{\n    Console.WriteLine(\"Running in a test environment\");\n}\nelse\n{\n    Console.WriteLine(\"Running in a production environment\");\n}\n```\n\n\n## Motivation\n\nWhen working on a software project, it's common to have both production code and test code in the same repository. \nHowever, it can sometimes be useful to be able to distinguish between the two, especially when working with dependency injection.\n\nThe TestsDetector project aims to provide a simple and convenient way to detect whether your code is running in a test environment or not. \nBy using TestsDetector, you'll be able to easily check whether you're running in a test environment or not, \nand configure your dependency injection container accordingly. TestsDetector currently supports MSTest, NUnit, and xUnit test frameworks.\n\n\n## Limitations\n\nTestsDetector uses reflection to detect the presence of test frameworks. \nThis means that it may not work in all cases, especially if the test framework is being used in an unusual way. \nHowever, it should work in most cases.\n\n## Contributions\n\nWe welcome contributions to TestsDetector! \nIf you have an idea for a new feature or have found a bug, please open an issue on GitHub. \nIf you'd like to contribute code, please fork the repository and submit a pull request.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanagedcode%2Fenvironmentdetector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanagedcode%2Fenvironmentdetector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanagedcode%2Fenvironmentdetector/lists"}