{"id":25311890,"url":"https://github.com/rsvilenov/fluentassertions.properties","last_synced_at":"2025-04-07T12:23:32.926Z","repository":{"id":139885866,"uuid":"392112901","full_name":"rsvilenov/FluentAssertions.Properties","owner":"rsvilenov","description":"Unofficial FluentAssertions extensions for testing the behavior of class/struct/record properties.","archived":false,"fork":false,"pushed_at":"2024-07-19T15:27:16.000Z","size":213,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T17:37:03.840Z","etag":null,"topics":["assertions","c-sharp","fluent-assertions","unit-testing","xunit"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rsvilenov.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":"2021-08-02T22:33:28.000Z","updated_at":"2024-07-19T15:25:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"4d7b3aaa-8d2f-4ec0-aa5b-3f60d81db6eb","html_url":"https://github.com/rsvilenov/FluentAssertions.Properties","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsvilenov%2FFluentAssertions.Properties","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsvilenov%2FFluentAssertions.Properties/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsvilenov%2FFluentAssertions.Properties/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsvilenov%2FFluentAssertions.Properties/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rsvilenov","download_url":"https://codeload.github.com/rsvilenov/FluentAssertions.Properties/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247649714,"owners_count":20973113,"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":["assertions","c-sharp","fluent-assertions","unit-testing","xunit"],"created_at":"2025-02-13T14:55:08.374Z","updated_at":"2025-04-07T12:23:32.905Z","avatar_url":"https://github.com/rsvilenov.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FluentAssertions.Properties\n\nUnofficial FluentAssertions extensions for testing the behavior of class/struct/record properties.\n\n[![build workflow](https://github.com/rsvilenov/FluentAssertions.Properties/actions/workflows/build.yml/badge.svg)](https://github.com/rsvilenov/FluentAssertions.Properties/actions/workflows/build.yml) \n[![Coverage Status](https://coveralls.io/repos/github/rsvilenov/FluentAssertions.Properties/badge.svg)](https://coveralls.io/github/rsvilenov/FluentAssertions.Properties)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) \n[![nuget](https://img.shields.io/nuget/v/FluentAssertions.Properties)](https://www.nuget.org/packages/FluentAssertions.Properties)\n\n## Table of Contents  \n\n- [How?](#How)\n- [Why?](#Why)\n- [Installation](#Installation)\n- [Documentation](#Documentation)\n\n## How?\n\nSome common scenarios:\n\n* Testing that all properties in a class provide symmetric access, i.e. they return the same value that has been assigned to them\n```csharp\n    var instanceUnderTest = new SampleDto();\n    var testValues = new Fixture().Create\u003cSampleDto\u003e();\n\n    instanceUnderTest\n        .Properties()\n        .ThatAreWritable\n        .WhenCalledWithValuesFrom(testValues)\n        .Should()\n        .ProvideSymmetricAccess();\n```\n\nSpeaking in the lingo of AutoFixture, we can say that `ProvideSymmetricAccess()` verifies that the properteis are \"well-behaved writables\" (see [AutoFixture's WritablePropertyAssertion idiom](http://www.shujaat.net/2013/05/writable-property-assertions-using.html)).\n\n* Testing that getters/setters throw exceptions in certain cases\n\n```csharp\n    var instanceUnderTest = new TestClass();\n            \n    instanceUnderTest\n        .Properties()\n        .ExactlyOfType\u003cstring\u003e()\n        .WhenCalledWith(string.Empty)\n        .Should()\n        .ThrowFromSetter\u003cArgumentException\u003e()\n        .WithMessage(\"Empty strings are not accepted.\");\n```\n\n* Selecting specific properties to test by their type and value\n\n```csharp\n    var instanceUnderTest = new TestClass();\n            \n    instanceUnderTest\n        .Properties()\n        .ExactlyOfType\u003cstring\u003e()\n        .HavingValue(\"some value\")\n        .Should()\n        .HaveCount(2);\n```\n\nor selecting individual properties by name\n```csharp\n    var instanceUnderTest = new TestRecord();\n    string testValue = Guid.NewGuid().ToString();\n\n    instanceUnderTest\n        .Properties(o =\u003e o.StringPropertyOne, o =\u003e o.StringPropertyTwo)\n        .WhenCalledWith(testValue)\n        .Should()\n        .ProvideSymmetricAccess();\n```\n\nA more comprehensive explanation of the selection and assertions methods, provided by this library, can be found [here](./Selectors.md) and [here](./Assertions.md).\n\n## Why?\n\n\u003e Even if code is trivial you should still test it.\n\u003e \n\u003e -- \u003ccite\u003eMark Seemann\u003c/cite\u003e\n\n### Why should I consider testing my class properties?\nFrom the perspective of the caller, the public properties are part of the public \"interface\" of a type. They imply a contract - their semantics is such that\none expects them to behave like public fields. However, they have accessor methods, \nwhich can contain logic that modifies the expected behavior. Implementing nontrivial logic in the accessors is sometimes considered\nto be an [anti-pattern](https://www.codeproject.com/Tips/1069467/Asymmetric-Property-anti-pattern),\nand rightfully so - in order for a programmer to see how a particular property behaves,\nthey have to open the implementation of the type and look inside the code. The presence of accessor\nmethods is a big part of the reason why Microsoft has provided a list of [bad practices and design guidelines](https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/property), concerning the implementation of properties.\n\n### But testing property accessors goes against the conventional wisdom!\nThere is a rule of thumb that says properties should not be tested if their getter and setter do not\ncontain any logic, e.g. if they are [auto-implemented](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/auto-implemented-properties). Robert C. Martin goes as far as to say that [testing property accessors is foolish](https://blog.cleancoder.com/uncle-bob/2013/03/06/ThePragmaticsOfTDD.html), regardless of whether their accessors contain logic or not. However, there are other prominent authors, such as Mark Seeman, who [strongly disagree](https://blog.ploeh.dk/2013/03/08/test-trivial-code/). And there seems to be a [not-so-small minority](https://stackoverflow.com/questions/18967697/should-you-unit-test-simple-properties), which thinks that testing all public properties is absolutely necessary.\n\n## Installation\nThis library is distributed as a [NuGet](https://www.nuget.org/packages/FluentAssertions.Properties/).\n\nTo install `FluentAssertions.Properties`, run the following command in the Package Manager Console:\n\n```\nPM\u003e Install-Package FluentAssertions.Properties\n```\nOr use this command with the .NET CLI:\n```\n\u003e dotnet add package FluentAssertions.Properties\n```\n\n## Documentation\n\n* [Property selector methods](https://github.com/rsvilenov/FluentAssertions.Properties/blob/master/docs/Selectors.md).\n* [Assertion methods](https://github.com/rsvilenov/FluentAssertions.Properties/blob/master/docs/Assertions.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frsvilenov%2Ffluentassertions.properties","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frsvilenov%2Ffluentassertions.properties","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frsvilenov%2Ffluentassertions.properties/lists"}