{"id":25773174,"url":"https://github.com/tinylit/xunitplus","last_synced_at":"2025-10-08T04:23:48.442Z","repository":{"id":229773484,"uuid":"777610897","full_name":"tinylit/xunitplus","owner":"tinylit","description":"Automatic injection of constructor parameters.","archived":false,"fork":false,"pushed_at":"2025-06-07T07:56:10.000Z","size":88,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-07T08:28:14.457Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/tinylit.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":"2024-03-26T07:17:14.000Z","updated_at":"2025-06-07T07:56:14.000Z","dependencies_parsed_at":"2024-03-26T07:31:19.624Z","dependency_job_id":"6893e650-2a19-4044-8acb-1bee47247233","html_url":"https://github.com/tinylit/xunitplus","commit_stats":null,"previous_names":["tinylit/xunitplus"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tinylit/xunitplus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinylit%2Fxunitplus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinylit%2Fxunitplus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinylit%2Fxunitplus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinylit%2Fxunitplus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tinylit","download_url":"https://codeload.github.com/tinylit/xunitplus/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinylit%2Fxunitplus/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266267291,"owners_count":23902334,"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":[],"created_at":"2025-02-27T04:38:40.676Z","updated_at":"2025-10-08T04:23:43.399Z","avatar_url":"https://github.com/tinylit.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Inkslab](inkslab.jpg 'Logo')\n\n![GitHub](https://img.shields.io/github/license/tinylit/xunitplus.svg)\n![language](https://img.shields.io/github/languages/top/tinylit/xunitplus.svg)\n![codeSize](https://img.shields.io/github/languages/code-size/tinylit/xunitplus.svg)\n\n### “[xunit+](https://www.nuget.org/packages/xunitPlus/)”是什么？\n\n[xunit+](https://www.nuget.org/packages/xunitPlus/) 是基于“[xunit](https://github.com/xunit/xunit.git)”再结合“[inkslab](https://github.com/tinylit/inkslab.git)”对构造函数参数进行自动注入的单元测试包。\n\n### 如何安装？\nFirst, [install NuGet](http://docs.nuget.org/docs/start-here/installing-nuget). Then, install [xunit+](https://www.nuget.org/packages/xunitPlus/) from the package manager console: \n\n```\nPM\u003e Install-Package xunitPlus\n```\n### 如何使用？\n* 通用模式：\n  - 单元测试类的构造函数正常注入即可。 \n* 自定义模式：\n  - 自定义启动类。\n  ```C#\n  ///\u003csummary\u003e\n  /// 启动类（可选）。\n  ///\u003c/summary\u003e\n  public class Startup {\n\n    ///\u003csummary\u003e\n    /// 创建宿主构建器（可选）。\n    ///\u003c/summary\u003e\n    public IHostBuilder CreateHostBuilder() =\u003e Host.CreateDefaultBuilder();\n\n    ///\u003csummary\u003e\n    /// 配置宿主构建器（可选）。\n    ///\u003c/summary\u003e\n    public void ConfigureHost(IHostBuilder builder){\n        //TODO: 配置构建器。\n    }\n\n    ///\u003csummary\u003e\n    /// 配置依赖注入的服务及生命周期（可选）。\n    ///\u003c/summary\u003e\n    public void ConfigureServices(IServiceCollection services){\n        //TODO: 配置依赖注入。\n    }\n\n    ///\u003csummary\u003e\n    /// 构建宿主（可选）。\n    ///\u003c/summary\u003e\n    public IHost BuildHost(IHostBuilder builder) =\u003e builder.Build();\n\n    ///\u003csummary\u003e\n    /// 配置服务（可选）。\n    ///\u003c/summary\u003e\n    public void Configure(/* 参数将被自动依赖注入。 */){\n        //TODO: 配置服务。\n    }\n  }\n  ```\n  \u003e 1. 启动类可以支持唯一的构造函数参数类型为 `Type` 表示当前运行的单元测试类。\n  \u003e 2. 启动类的所有方法均为可选，返回值类型为 `void` 的不可更改，否则方法返回值相同或返回值必须是指定接口的实现类。\n  \u003e 3. 方法均是可选方法。\n  \u003e 4. 不区分是否是静态方法。\n  \u003e 5. 不区分是否是静态类。\n  \n  - 启动类查找规则：权重从上到下依次 **递减**。\n    * 指定启动类。\n        ```C#\n        ///\u003csummary\u003e\n        /// 指定类。\n        ///\u003c/summary\u003e\n        public class SpecifyStartup { \n            \n            ///\u003csummary\u003e\n            /// 配置依赖注入的服务及生命周期（可选）。\n            ///\u003c/summary\u003e\n            public void ConfigureServices(IServiceCollection services){\n                // 注入需要的参数。\n                services.AddTransient\u003cITest, Test\u003e();\n            }\n        }\n\n        ///\u003csummary\u003e\n        /// 指定类测试。\n        ///\u003c/summary\u003e\n        [Startup(typeof(SpecifyStartup))]\n        public class SpecifyStartupTests(ITest test) {\n\n            ///\u003csummary\u003e\n            /// 测试。\n            ///\u003c/summary\u003e\n            [Fact]\n            public void Test() {\n                Assert.True(test is Test);\n            }\n        }\n        ```\n        \u003e 在单元测试类上通过 `StartupAttribute` 标记。\n\n    * 单元测试类的内嵌 `Startup` 类。\n        ```C#\n        ///\u003csummary\u003e\n        /// 内嵌类测试。\n        ///\u003c/summary\u003e\n        public class NestedStartupTests(ITest test) {\n\n            ///\u003csummary\u003e\n            /// 测试。\n            ///\u003c/summary\u003e\n            [Fact]\n            public void Test() {\n                Assert.True(test is Test);\n            }\n\n            ///\u003csummary\u003e\n            /// 内嵌类。\n            ///\u003c/summary\u003e\n            public class Startup { \n            \n                ///\u003csummary\u003e\n                /// 配置依赖注入的服务及生命周期（可选）。\n                ///\u003c/summary\u003e\n                public void ConfigureServices(IServiceCollection services){\n                    // 注入需要的参数。\n                    services.AddTransient\u003cITest, Test\u003e();\n                }\n            }\n        }\n        ```\n        \u003e 在单元测试类中，查找类名为 `Startup` 的类作为启动类。\n\n    * 单元测试类的程序集 `Startup` 类。\n        ```C#\n        ///\u003csummary\u003e\n        /// 程序集类。\n        ///\u003c/summary\u003e\n        public class Startup { \n        \n            ///\u003csummary\u003e\n            /// 配置依赖注入的服务及生命周期（可选）。\n            ///\u003c/summary\u003e\n            public void ConfigureServices(IServiceCollection services){\n                // 注入需要的参数。\n                services.AddTransient\u003cITest, Test\u003e();\n            }\n        }\n\n        ///\u003csummary\u003e\n        /// 程序集类测试。\n        ///\u003c/summary\u003e\n        public class NestedStartupTests(ITest test) {\n\n            ///\u003csummary\u003e\n            /// 测试。\n            ///\u003c/summary\u003e\n            [Fact]\n            public void Test() {\n                Assert.True(test is Test);\n            }\n        }\n        ```\n        \u003e 使用单元测试类的命名空间，或命名空间按照 `“.”` 逐步右截断查找名为 `Startup` 的类作为启动类。\n\n    * 默认 `XunitPlus.Startup` 类。\n        \u003e 1. 在以上规则都没有设置的情况下生效。\n        \u003e 2. 使用 `Inkslab.DI` 实现的自动查找和实现依赖注入。\n* 便捷标记：可以 *混合* 使用，权重从上往下依次 **递增** 。\n  - 使用 `HeaderAttribute` 添加请求头。\n  - 使用 `AuthorizationAttribute` 添加认证请求头。\n  - 继承 `HttpContextAttribute` 创建 `HttpContext` 请求上下文。\n  - 继承 `UserAttribute` 创建请求上下文的用户信息。\n  - 使用 `PatternSeekAttribute` 指定自动依赖注入扫描 `DLL` 文件的范围，如：`Inkslab.*.dll`。","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinylit%2Fxunitplus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinylit%2Fxunitplus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinylit%2Fxunitplus/lists"}