{"id":24524198,"url":"https://github.com/bytedev/bytedev.testing","last_synced_at":"2025-09-01T00:43:49.825Z","repository":{"id":40646165,"uuid":"298224176","full_name":"ByteDev/ByteDev.Testing","owner":"ByteDev","description":".NET Standard library that provides some testing related functionality.","archived":false,"fork":false,"pushed_at":"2022-09-20T07:35:15.000Z","size":134,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-23T11:36:15.996Z","etag":null,"topics":["csharp","dotnet-standard","testing","tests"],"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/ByteDev.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}},"created_at":"2020-09-24T08:59:51.000Z","updated_at":"2022-03-21T09:42:07.000Z","dependencies_parsed_at":"2023-01-17T16:51:42.151Z","dependency_job_id":null,"html_url":"https://github.com/ByteDev/ByteDev.Testing","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ByteDev%2FByteDev.Testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ByteDev%2FByteDev.Testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ByteDev%2FByteDev.Testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ByteDev%2FByteDev.Testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ByteDev","download_url":"https://codeload.github.com/ByteDev/ByteDev.Testing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243738972,"owners_count":20340003,"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":["csharp","dotnet-standard","testing","tests"],"created_at":"2025-01-22T04:18:48.536Z","updated_at":"2025-03-15T14:13:52.179Z","avatar_url":"https://github.com/ByteDev.png","language":"C#","readme":"[![Build status](https://ci.appveyor.com/api/projects/status/github/bytedev/ByteDev.Testing?branch=master\u0026svg=true)](https://ci.appveyor.com/project/bytedev/ByteDev-Testing/branch/master)\n[![NuGet Package](https://img.shields.io/nuget/v/ByteDev.Testing.svg)](https://www.nuget.org/packages/ByteDev.Testing)\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/ByteDev/ByteDev.Testing/blob/master/LICENSE)\n\n# ByteDev.Testing\n\n.NET Standard library that provides some testing related functionality.\n\n## Installation\n\nByteDev.Testing has been written as a .NET Standard 2.1 library.\n\nByteDev.Testing is hosted as a package on nuget.org.  To install from the Package Manager Console in Visual Studio run:\n\n`Install-Package ByteDev.Testing`\n\nFurther details can be found on the [nuget page](https://www.nuget.org/packages/ByteDev.Testing/).\n\n## Release Notes\n\nReleases follow semantic versioning.\n\nFull details of the release notes can be viewed on [GitHub](https://github.com/ByteDev/ByteDev.Testing/blob/master/docs/RELEASE-NOTES.md).\n\n## Usage\n\nThe library is split into the following main parts:\n- Builders\n- HTTP\n- Setting\n- Settings\n\n---\n\n### Builders - DirectoryBuilder\n\n`DirectoryBuilder` helps to create directories quickly for testing purposes.\n\n```csharp\nusing ByteDev.Testing.Builders;\n\n// ...\n\n// Create a directory quickly on disk\nDirectoryInfo dir = DirectoryBuilder.InFileSystem\n                        .WithPath(@\"C:\\Temp\\Testing\")\n                        .EmptyIfExists()\n                        .Build();\n```\n\n---\n\n### Builders - FileBuilder\n\n`FileBuilder` helps to create files quickly for testing purposes.\n\n```csharp\nusing ByteDev.Testing.Builders;\n\n// ...\n\n// Create a file quickly on disk\nFileInfo file = FileBuilder.InFileSystem\n                    .WithPath(@\"C:\\Temp\\Testing\\TestFile1.txt\")\n                    .WithSize(10)\n                    .OverwriteIfExists(true)\n                    .Build();\n```\n\n---\n\n### HTTP - FakeHttpMessageHandler\n\n`FakeHttpMessageHandler` allows you to provide a sequence of *outcomes* (HTTP responses or exceptions thrown) that correspond to each HTTP request made.\n\n```csharp\nusing ByteDev.Testing.Http;\n\n// ...\n\nvar uri = new Uri(\"http://www.google.com/\");\n\n// Create a sequence of outcomes...\n// 1st request will return a response OK with content.\n// 2nd request will throw request timeout exception.\nvar outcomes = new List\u003cFakeRequestOutcome\u003e\n{\n    new FakeRequestOutcome(new HttpResponseMessage(HttpStatusCode.OK)\n    {\n        Content = new StringContent(\"Testing\")\n    }),\n    new FakeRequestOutcome(FakeRequestOutcome.CreateRequestTimeout())\n}\n\n// Create a fake HTTP handler\nvar handler = new FakeHttpMessageHandler(outcomes);\n\nvar httpClient = new HttpClient(handler);\n\nvar response1 = await httpClient.GetAsync(uri);\nvar content = await response1.Content.ReadAsStringAsync();\n\n// response1.StatusCode == HttpStatusCode.OK\n// content == \"Testing\"\n\n// Throws TaskCanceledException(\"Request has timed out.\")\nvar response2 = await httpClient.GetAsync(uri);\n\n// handler.RequestsMade == 2\n```\n\n---\n\n### Setting - TestSetting\n\nThe `TestSetting` type represents a single string value setting that lives external to a test project.\n\n```csharp\nusing ByteDev.Testing.Setting;\nusing ByteDev.Testing.Setting.Providers;\n\n// ...\n\nvar testSetting = new TestSetting();\n\ntestSetting.AddProvider(new FileSettingProvider(new[]\n{\n    \"C:\\Dev\\SomeSetting.apikey\",\n    \"C:\\Temp\\AnotherSetting.txt\"\n}));\n\ntestSetting.AddProvider(new EnvironmentSettingProvider(\"MyProjEnvVar\"));\n\nstring setting = testSetting.GetSetting();\n\n// The two files will be checked first for the setting and if \n// not found the environment variable will be checked.\n```\n\n---\n\n### Settings - TestSettings\n\nThe `TestSettings` type represents sets of test settings that lives external to a test project.\n\n```csharp\n// Define the settings class\n\npublic class MyAppSettings\n{\n    public string MySecret1 { get; set; }\n\n    public string MySecret2 { get; set; }\n}\n```\n\nExample JSON settings file `MyApp.settings.json` (property name case is ignored):\n\n```json\n{\n  \"MySecret1\": \"some secret 1\",\n  \"MySecret2\": \"some secret 2\"\n}\n```\n\n```csharp\nusing ByteDev.Azure.KeyVault.Secrets;\nusing ByteDev.Testing.Settings;\nusing ByteDev.Testing.Settings.Providers;\n\n// ...\n\nvar kvClient = new KeyVaultSecretClient(keyVaultUri);\n\nvar testSettings = new TestSettings();\n\ntestSettings\n    .AddProvider(new JsonFileSettingsProvider(\n        @\"X:\\Secure\\MyApp.settings.json\",\n        @\"C:\\Temp\\MyOtherApp.settings.json))\n    .AddProvider(new KeyVaultSettingsProvider(kvClient));\n\n// The TestSettings type will try to get the settings from the two \n// JSON files first and if it fails will try Azure Key Vault\n\nMyAppSettings settings = testSettings.GetSettings\u003cMyAppSettings\u003e();\n```\n\nAs well as defining and providing your own settings class you can also use the built in `TestAzureSettings` and `TestAzureKeyVaultSettings` settings classes. \n\nFor example:\n\n```csharp\nusing ByteDev.Testing.Settings.Entities;\n\n// ...\n\nTestAzureSettings settings = testSettings.GetAzureSettings();\n\n// TestAzureSettings contains common Azure settings, including:\n// SubscriptionId, TenantId, ClientId, ClientSecret etc.\n```\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytedev%2Fbytedev.testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbytedev%2Fbytedev.testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytedev%2Fbytedev.testing/lists"}