{"id":19838300,"url":"https://github.com/barisates/dotnet-core-xunit-example","last_synced_at":"2025-09-07T07:34:00.202Z","repository":{"id":37663961,"uuid":"224031264","full_name":"barisates/dotnet-core-xunit-example","owner":"barisates","description":"Unit Test in .NET Core Web Api with xUnit","archived":false,"fork":false,"pushed_at":"2022-07-06T06:20:08.000Z","size":27,"stargazers_count":30,"open_issues_count":1,"forks_count":12,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-18T17:56:36.067Z","etag":null,"topics":["dotnet-core","functional-testing","unit-testing","web-api","xunit"],"latest_commit_sha":null,"homepage":null,"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/barisates.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}},"created_at":"2019-11-25T20:01:31.000Z","updated_at":"2025-03-25T07:01:33.000Z","dependencies_parsed_at":"2022-09-09T04:01:00.078Z","dependency_job_id":null,"html_url":"https://github.com/barisates/dotnet-core-xunit-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/barisates/dotnet-core-xunit-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barisates%2Fdotnet-core-xunit-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barisates%2Fdotnet-core-xunit-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barisates%2Fdotnet-core-xunit-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barisates%2Fdotnet-core-xunit-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/barisates","download_url":"https://codeload.github.com/barisates/dotnet-core-xunit-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barisates%2Fdotnet-core-xunit-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271242485,"owners_count":24725056,"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","status":"online","status_checked_at":"2025-08-19T02:00:09.176Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["dotnet-core","functional-testing","unit-testing","web-api","xunit"],"created_at":"2024-11-12T12:17:17.270Z","updated_at":"2025-08-20T00:17:38.532Z","avatar_url":"https://github.com/barisates.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dotnet-core-xunit-example\n**Unit Test in .NET Core Web Api with xUnit.**\n\nIn this example, we have a simple Web Api developed with .Net Core which performs database operations. Our Web API consists of the following endpoints;\n\n\u003e `UserDto.User GetUser(int id);` get user with id in database\n\n\u003e `UserDto.User AddUser(UserDto.User user);` add user to database\n\n\u003e `UserDto.User DeleteUser(int id;` delete user with id from database\n\nWhen testing these endpoints, we actually write **functional tests**. In this way, we can manage test processes more realistically.\n\nOur tests use **memory database** when testing our endpoints and our live data is not affected by the testing process.\n\nWhen developing a test, we use the library **[xUnit.net](https://github.com/xunit/xunit \"xUnit.net\")**.\n\n### xUnit\n\n xUnit is an open-source unit testing tool for the .Net Framework and offers **.NET Core support**. Compared to other unit testing frameworks, it stands out with its ease of development and its approach to behaviors like *SetUp, TearDown, OneTimeSetup*.\n\n**[Comparing xUnit.net to other frameworks.](https://xunit.net/docs/comparisons.html \"Comparing xUnit.net to other frameworks.\")**\n\n**SetUp (before each test)**\nXUnit uses constructors for test setup operations. You don't need to use a separate attirubute as in NUnit, MSTest frameworks.\n\n**TearDown (after each test)**\nXUnit uses IDisposable classes for teardown operations.\n\n**Implementing SetUp and Teardown Method in XUnit;**\n\n```csharp\npublic class TruthTests : IDisposable\n{\n    public TruthTests()\n    {\n\t// It will work before each test.\n\t// NUnit: [SetUp]\n\t// MSTest: [TestInitialize]\n    }\n    \n    public void Dispose()\n    {\n\t// It will work after each test.\n\t// NUnit: [TearDown]\n\t// MSTest: [TestCleanup]\n    }\n\n    [Fact]\n    public void Test1()\n    {\n\t// Your Test\n    }\n}\n```\n\n**OneTimeSetup (share context between tests)**\n\nWe use xUnit's IClassFixture feature to create shared contexts, such as Databases. With the fixture, we can share a single object instance between all tests.\n\nFor more; [xUnit.net Documentation](https://xunit.net/#documentation \"xUnit.net Documentation\")\n- [Running Tests in Parallel](https://xunit.net/docs/running-tests-in-parallel \"Running Tests in Parallel\")\n- [Shared Context between Tests](https://xunit.net/docs/shared-context \"Shared Context between Tests\")","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarisates%2Fdotnet-core-xunit-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbarisates%2Fdotnet-core-xunit-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarisates%2Fdotnet-core-xunit-example/lists"}