{"id":26542252,"url":"https://github.com/nuskey8/expect","last_synced_at":"2025-10-18T05:25:55.699Z","repository":{"id":273963507,"uuid":"921476563","full_name":"nuskey8/Expect","owner":"nuskey8","description":"Expression-based Assertion Library for .NET","archived":false,"fork":false,"pushed_at":"2025-01-24T07:53:44.000Z","size":23,"stargazers_count":26,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T02:13:32.633Z","etag":null,"topics":["assert","dotnet","testing"],"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/nuskey8.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":"2025-01-24T02:40:08.000Z","updated_at":"2025-02-28T16:32:18.000Z","dependencies_parsed_at":"2025-02-08T17:46:46.454Z","dependency_job_id":null,"html_url":"https://github.com/nuskey8/Expect","commit_stats":null,"previous_names":["annulusgames/expect","yn01dev/expect","yn01-dev/expect","nuskey8/expect"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuskey8%2FExpect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuskey8%2FExpect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuskey8%2FExpect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuskey8%2FExpect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nuskey8","download_url":"https://codeload.github.com/nuskey8/Expect/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244894316,"owners_count":20527677,"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":["assert","dotnet","testing"],"created_at":"2025-03-22T02:13:37.253Z","updated_at":"2025-10-18T05:25:55.589Z","avatar_url":"https://github.com/nuskey8.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Expect  \n Expression-based Assertion Library for .NET  \n\n[![NuGet](https://img.shields.io/nuget/v/Expect.svg)](https://www.nuget.org/packages/Expect)\n[![Releases](https://img.shields.io/github/release/AnnulusGames/Expect.svg)](https://github.com/AnnulusGames/Expect/releases)\n[![GitHub license](https://img.shields.io/github/license/AnnulusGames/Expect.svg)](./LICENSE)\n\nEnglish | [日本語](./README_JA.md) \n\n**Expect** is an assertion library for .NET.  \n\nThe concept of Expect is inspired by [power-assert](https://github.com/power-assert-js/power-assert) and [swift-testing](https://github.com/swiftlang/swift-testing), offering better assertions using Expression Trees.  \n\n## Why Expect?  \n\nIn test frameworks like NUnit, assertions are written using `Assert.That`. Below is an example of a unit test using NUnit:  \n\n```cs\n// Define a record for testing\nrecord Person(string Name, int Age);\n```\n\n```cs\n[Test]\npublic void Example()\n{\n    var person = new Person(\"Alice\", 16);\n    Assert.That(person.Age, Is.GreaterThanOrEqualTo(18));   \n}\n```\n\nThis test will fail, displaying the following message:  \n\n```\nExpected: greater than or equal to 18\nBut was:  16\n```\n\nThe problem with assertions using `Assert.That` is that users are required to distinguish between a large number of `Is.**` usages. Many test frameworks provide a vast number of APIs to cover all use cases, forcing users to memorize them.  \n\nSome assertion libraries adopt a Fluent Interface, such as `foo.Should().Not.Be.Null()`. However, I believe such APIs should not be used, as they reduce readability. Overly verbose Fluent Interfaces, modeled after natural language, are not necessarily easy to read. Tests should not aim to mimic natural language but instead be programmer-friendly and written in readable code.  \n\nWith Expect, there is only one API provided:  \n\n```cs\nusing static Expect.Expectation;\n\n[Test]\npublic void Example()\n{\n    var person = new Person(\"Alice\", 16);\n\n    // Pass a condition\n    Expect(() =\u003e person.Age \u003e= 18);\n}\n```\n\nThis displays the following message:  \n\n```\n(person.Age → 16) \u003e= 18\n```\n\nExpect analyzes the provided expression to display an appropriate error message.  \n\nBelow is a comparison of collection assertions:  \n\n```cs\nint[] array = [1, 2, 3, 4, 5];\n\n// NUnit\nAssert.That(array, Has.Member(-1));\n\n// Expect\nExpect(() =\u003e array.Contains(-1));\n```\n\nThe error messages will be as follows:  \n\n```\nExpected: some item equal to -1\nBut was:  \u003c 1, 2, 3, 4, 5 \u003e\n```\n\n```\n(array → [1, 2, 3, 4, 5]).Contains(-1)\n```\n\n## Installation  \n\n### NuGet packages  \n\nExpect requires .NET Standard 2.0 or higher. The package is available via NuGet.  \n\n### .NET CLI  \n\n```ps1\ndotnet add package Expect\n```\n\n### Package Manager  \n\n```ps1\nInstall-Package Expect\n```\n\n## License  \n\nThis library is released under the [MIT License](LICENSE).  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuskey8%2Fexpect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnuskey8%2Fexpect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuskey8%2Fexpect/lists"}