{"id":26711658,"url":"https://github.com/swisslife-oss/testsources","last_synced_at":"2025-04-13T19:51:06.304Z","repository":{"id":39627857,"uuid":"361809931","full_name":"SwissLife-OSS/testsources","owner":"SwissLife-OSS","description":"TestSources makes easy to handle, organize and use test files from within a .NET test.","archived":false,"fork":false,"pushed_at":"2023-04-08T11:30:35.000Z","size":126,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-27T10:36:20.706Z","etag":null,"topics":["csharp","file","files","json","net","nunit","test","testing","tool","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/SwissLife-OSS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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-04-26T15:58:52.000Z","updated_at":"2023-02-17T13:14:52.000Z","dependencies_parsed_at":"2025-03-27T10:43:04.962Z","dependency_job_id":null,"html_url":"https://github.com/SwissLife-OSS/testsources","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":"SwissLife-OSS/template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwissLife-OSS%2Ftestsources","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwissLife-OSS%2Ftestsources/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwissLife-OSS%2Ftestsources/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwissLife-OSS%2Ftestsources/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SwissLife-OSS","download_url":"https://codeload.github.com/SwissLife-OSS/testsources/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248773755,"owners_count":21159517,"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","file","files","json","net","nunit","test","testing","tool","xunit"],"created_at":"2025-03-27T10:30:06.030Z","updated_at":"2025-04-13T19:51:06.279Z","avatar_url":"https://github.com/SwissLife-OSS.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"![TestSources](https://raw.githubusercontent.com/SwissLife-OSS/testsources/main/logo.png)\n## [![Nuget](https://img.shields.io/nuget/v/testsources.svg?style=flat)](https://www.nuget.org/packages/testsources.Xunit) [![GitHub Release](https://img.shields.io/github/release/SwissLife-OSS/testsources.svg?style=flat)](https://github.com/SwissLife-OSS/testsources/releases/latest) [![Build Status](https://dev.azure.com/swisslife-oss/swisslife-oss/_apis/build/status/testsources.Release?branchName=main)](https://dev.azure.com/swisslife-oss/swisslife-oss/_build/latest?definitionId=6\u0026branchName=master) [![Coverage Status](https://sonarcloud.io/api/project_badges/measure?project=SwissLife-OSS_TestSources\u0026metric=coverage)](https://sonarcloud.io/dashboard?id=SwissLife-OSS_TestSources) [![Quality](https://sonarcloud.io/api/project_badges/measure?project=SwissLife-OSS_TestSources\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=SwissLife-OSS_TestSources)\n\n**TestSources is a test file management tool for _.NET Core_ and _.NET Framework_**\n\n_TestSources_ makes easy to handle, organize and use test files in a .NET test. \nIt greatly simplifies the usual work of having to set up a file management tool/code, implement validations and enable proper access to files and its contents... Those have to be set up manually on every test project that manages files of any kind, consuming time and repeating code. THAT IS EVIL.\nBut no more, here is TestSources to help.\n\n\n## Getting Started\n\nTo get started, install the [TestSources nuget package](https://www.nuget.org/packages/TestSources):\n\n### In your favorite test tool, XUnit, NUnit or MSTest\n```bash\ndotnet add package TestSources\n```\n\n### Setting up TestSources\nIn the root of the project, add a New Folder, named \"`__testsources__`\".\nIt should be in lowercase, with two underscore characters \"`_`\" before and after.\nInside our tessources folder, create a text file named \"aTextFile.txt\" and inside add \"Some text\", or any text of your liking.\n\n### Using TestSources to get a file\nTo get this test file and use it within your unit (or integration) tests, follow the next step:\n\n#### 1. Get the file\n\nInsert a TestSources GetFile statement `TestSource.GetFile(\"aTextFile.txt\");` into your unit test.\n\nExample:\n\n```csharp\n/// \u003csummary\u003e\n/// Tests if the test file contains some text.\n/// \u003c/summary\u003e\n[Fact]\npublic void TestThatTheTextFileContainsText()\n{\n    // arrange\n    string fileName = \"aTextFile.txt\";\n\n    // act\n    string textInsideTheFile =\n        TestSource.GetFile(fileName)\n        .AsString();\n\n    // Assert\n    Assert.NotEmpty(textInsideTheFile);\n}\n```\n\n#### 2. Run the unit test to Assert that the file is not empty\n\nThe `TestSource.GetFile()` statement will obtain the file with the specified name located on the  \"`__testsources__`\" folder.\nNext, the metachained `AsString()` statement will obtain its contents and deliver them ready to use in a string form, with UTF-8 encoding. (it is configurable too)\n\u003cbr\u003e\u003cbr\u003e        \n    \n### It is herarchical (files and folders)\n\nYou can create folders inside the \"`__testsources__`\" folder, without any limit except the one set up by your operating system.\u003cbr\u003e    \nSame goes with files, you can add them at any level and use your imagination to organize your test files until it pleases you.\u003cbr\u003e  \n\nThe statement `TestSource.GetFile(filename, true)` will get any file located under the testsources root directory, given that it exists and you have typed it properly.\u003cbr\u003e    \n  \nIn addition you can get a reference to a folder with a similar statement:  \n\n`TestSource.GetFolder(foldername)` will find the folder named `foldername` in the root of the testsources root directory, whereas `TestSource.GetFile(filename, true)` will find the named folder in any of its subfolders.\n\u003cbr\u003e   \n\n#### Managing files: ITestSourceFile\nThe files fulfill the `ITestSourceFile` Interface and this enables us to check its parent, get the file name, the full name including the path and then some extensions such as:\n - `OpenRead()` - Opens a file for reading returning a file stream.\n - `AsString()` - Reads the current file and returns its content as an string with a default UTF8 encoding, which can be overridden.\n - `AsByteArray()` - Reads the current file and returns a byte array of its content.\n - `AsFileStream()` - Reads the current file and returns a FileStream to it.\n - `AsMemoryStream()` - Reads the current file and returns its contents as a MemoryStream.\n - `AsStream()` - Reads the current file and returns its contents as a Stream.\n - `GetHash()` - Returns the hash of a file, given a Cryptographic hash algorithm.\n - `AsType\u003cT\u003e()` - Returns the content of a file as a concrete type, deserializing its JSON content.\n - `AsJson()` - Reads the current file and returns its content as a JSON string with a default UTF8 encoding, which can be overridden.\n \u003cbr\u003e  \n\n #### Managing folders: ITestSourceDir\nThe folders or directories fulfill the `ITestSourceDir` Interface and this enables us to check its parent, get the folder name, the full name including the path and then some extensions such as:\n - `GetFiles()` - Returns a list of the files contained on this folder. Of course, fulfilling the ITestSourceFile interface.\n - `GetFolders()` - Returns a list of the folders contained on this folder. Of course, fulfilling the ITestSourceDir interface.\n(if no files or folders, the collection is empty)\n\n\n## Using testsources in CI-Builds\n\nThey simply work, nothing specially to set up there.\n\n## Community\n\nThis project has adopted the code of conduct defined by the [Contributor Covenant](https://contributor-covenant.org/)\nto clarify expected behavior in our community. For more information, see the [Swiss Life OSS Code of Conduct](https://swisslife-oss.github.io/coc).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswisslife-oss%2Ftestsources","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswisslife-oss%2Ftestsources","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswisslife-oss%2Ftestsources/lists"}