{"id":15425753,"url":"https://github.com/olegsych/inspector","last_synced_at":"2026-04-21T10:03:13.050Z","repository":{"id":54507737,"uuid":"107798675","full_name":"olegsych/inspector","owner":"olegsych","description":"A simple .NET Reflection API for white-box unit testing.","archived":false,"fork":false,"pushed_at":"2021-02-14T22:36:42.000Z","size":442,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-22T07:38:19.465Z","etag":null,"topics":["dotnet","dotnet-standard","reflection","unit-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/olegsych.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-21T16:59:36.000Z","updated_at":"2021-02-14T22:34:27.000Z","dependencies_parsed_at":"2022-08-13T18:10:25.566Z","dependency_job_id":null,"html_url":"https://github.com/olegsych/inspector","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/olegsych/inspector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olegsych%2Finspector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olegsych%2Finspector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olegsych%2Finspector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olegsych%2Finspector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/olegsych","download_url":"https://codeload.github.com/olegsych/inspector/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olegsych%2Finspector/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268171954,"owners_count":24207433,"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-01T02:00:08.611Z","response_time":67,"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","dotnet-standard","reflection","unit-testing"],"created_at":"2024-10-01T17:53:38.526Z","updated_at":"2026-04-21T10:03:13.021Z","avatar_url":"https://github.com/olegsych.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build](https://github.com/olegsych/inspector/actions/workflows/build.yml/badge.svg)](https://github.com/olegsych/inspector/actions/workflows/build.yml)\n[![Nuget](https://img.shields.io/nuget/v/inspector.svg)](https://www.nuget.org/packages/inspector)\n\nInspector is a simple .NET Reflection API for white-box unit testing.\n\nWhy use white-box testing? Because building fully-tested .NET code shouldn't require breaking of encapsulation and _unnecessary_ exposure of internal types as public, wrapping of well-defined external dependencies or resorting to integration testing.\n\n# install\n\nAdd the [inspector](https://www.nuget.org/packages/inspector) package to your .NET project.\n```PowerShell\ndotnet add package inspector\n```\n\n# import\n\nImport the `Inspector` namespace in your .NET source file. Most of the Inspector APIs are extension methods of the .NET `Object` and `Type`.\n```C#\nusing Inspector;\n```\n\n# use\n\nSuppose you have the following class that serves as a base for a number of derived types in your system.\n```C#\npublic class MyClass\n{\n    protected readonly int field;\n\n    protected MyClass(int parameter) {\n        if (parameter \u003c 42)\n            throw new ArgumentOutOfRangeException(nameof(parameter));\n        field = parameter;\n    }\n}\n```\n\nBecause the class members are meant to be used only by the derived types, its members have protected visibility and aren't directly accessible from unit tests. Testing this class can be done through its derived classes at the cost of duplicating the tests of the base class for each derived type. Alternatively, you could make members of this class `internal` and use the `[assembly:InternalsVisibleTo()]` attribute to allow your unit tests access them directly at the cost of breaking the encapsulation and making the class more accessible than intended. Finally, you could derive a special class that provides public API for accessing the protected members of its base in your unit tests. While this last option may be trivial, it is also wasteful and verbose.\n\nWith Inspector, you can create a new instance of a class with non-public constructor without redundant typecasting.\n```C#\nclass MyClass\n{\n    private string s;\n    private MyClass(int i) =\u003e s = i.ToString();\n}\n\nMyClass sut = Type\u003cMyClass\u003e.New(42);\n```\n\nYou can use Inspector's strongly-typed extension methods to access non-public members.\n```C#\nstring fieldValue = sut.Field\u003cstring\u003e();\nAssert.Equal(\"42\", fieldValue);\n```\n\nYou can verify that exceptions thrown by your class implement the expected contract.\n```C#\nvar thrown = Assert.Throws\u003cArgumentOutOfRangeException\u003e(() =\u003e Type\u003cMyClass\u003e.New(41));\nAssert.Equal(sut.Constructor().Parameter().Name, thrown.ParamName);\n```\n\nNow suppose that `MyClass` is an external dependency in your code. Pretend that instead of a simple `int` parameter, its constructor requires a second-level dependency with complex setup that would not only be difficult to implement, it would also break the [Law of Demeter](https://en.wikipedia.org/wiki/Law_of_Demeter) and make your unit tests fragile. To deal with this problem, the conventional wisdom requires introduction of a new, testable abstraction in your code to encapsulate the external dependency and allow testing your code by mocking or stubbing your own abstraction instead of the dependency. While this option is straightforward, it could also be wasteful if the external dependency has a well-defined and stable API.\n\nWith Inspector, you can create an instance of this class without invoking its constructor and then manipulate its non-public members to prepare conditions expected by your code.\n```C#\nMyClass dependency = Type\u003cMyClass\u003e.Uninitialized();\ndependency.Field\u003cstring\u003e().Set(\"41\");\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folegsych%2Finspector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Folegsych%2Finspector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folegsych%2Finspector/lists"}