All Projects → pengweiqhca → Xunit.dependencyinjection

pengweiqhca / Xunit.dependencyinjection

Licence: mit
Use Microsoft.Extensions.DependencyInjection to resolve xUnit test cases.

Labels

Projects that are alternatives of or similar to Xunit.dependencyinjection

Hangfire.autofac
Hangfire job activator based on Autofac IoC container
Stars: ✭ 54 (-51.79%)
Mutual labels:  ioc
Python Dependency Injector
Dependency injection framework for Python
Stars: ✭ 1,203 (+974.11%)
Mutual labels:  ioc
Detections
This repository contains all public indicators identified by 401trg during the course of our investigations. It also includes relevant yara rules and ids signatures to detect these indicators.
Stars: ✭ 95 (-15.18%)
Mutual labels:  ioc
Singularity
A extremely fast ioc container for high performance applications
Stars: ✭ 63 (-43.75%)
Mutual labels:  ioc
Thunder
Stars: ✭ 70 (-37.5%)
Mutual labels:  ioc
Countries
Countries - ISO 3166 (ISO3166-1, ISO3166, Digit, Alpha-2 and Alpha-3) countries codes and names (on eng and rus), ISO 4217 currency designators, ITU-T E.164 IDD calling phone codes, countries capitals, UN M.49 regions codes, ccTLD countries domains, IOC/NOC and FIFA letters codes, VERY FAST, NO maps[], NO slices[], NO init() funcs, NO external links/files/data, NO interface{}, NO specific dependencies, Databases/JSON/GOB/XML/CSV compatible, Emoji countries flags and currencies support, full support ISO-3166-1, ISO-4217, ITU-T E.164, Unicode CLDR and ccTLD standarts.
Stars: ✭ 85 (-24.11%)
Mutual labels:  ioc
Malware Ioc
Indicators of Compromises (IOC) of our various investigations
Stars: ✭ 955 (+752.68%)
Mutual labels:  ioc
Analyzer
🔍 Offline Analyzer for extracting features, artifacts and IoCs from Windows, Linux, Android, iPhone, Blackberry, macOS binaries, emails and more
Stars: ✭ 108 (-3.57%)
Mutual labels:  ioc
Minioc
Single-file minimal C# IoC container
Stars: ✭ 71 (-36.61%)
Mutual labels:  ioc
Doodle
A Simple Java MVC Framework。提供Bean容器、Ioc、Aop、MVC功能
Stars: ✭ 90 (-19.64%)
Mutual labels:  ioc
Injex
Simple, Decorated, Pluggable dependency-injection framework for TypeScript applications
Stars: ✭ 65 (-41.96%)
Mutual labels:  ioc
Koatty
Koa2 + Typescript = Koatty. Use Typescript's decorator implement IOC and AOP.
Stars: ✭ 67 (-40.18%)
Mutual labels:  ioc
Aspnetcore Ddd
Full ASP.NET Core 3.1 LTS application with DDD, CQRS and Event Sourcing
Stars: ✭ 88 (-21.43%)
Mutual labels:  ioc
Poodinis
A dependency injection framework for D with support for autowiring.
Stars: ✭ 57 (-49.11%)
Mutual labels:  ioc
Awesome Yara
A curated list of awesome YARA rules, tools, and people.
Stars: ✭ 1,394 (+1144.64%)
Mutual labels:  ioc
Inversifyjs
InversifyJS is a lightweight inversion of control (IoC) container for TypeScript and JavaScript apps. An IoC container uses a class constructor to identify and inject its dependencies. InversifyJS has a friendly API and encourages the usage of the best OOP and IoC practices.
Stars: ✭ 8,399 (+7399.11%)
Mutual labels:  ioc
Signature Base
Signature base for my scanner tools
Stars: ✭ 1,212 (+982.14%)
Mutual labels:  ioc
Unity
This repository contains all relevant information about Unity Container suit
Stars: ✭ 1,513 (+1250.89%)
Mutual labels:  ioc
Patrowldocs
PatrOwl - Open Source, Free and Scalable Security Operations Orchestration Platform
Stars: ✭ 105 (-6.25%)
Mutual labels:  ioc
Container Ioc
Inversion of Control container & Dependency Injection for Javascript and Node.js apps powered by Typescript.
Stars: ✭ 89 (-20.54%)
Mutual labels:  ioc

Use Microsoft.Extensions.DependencyInjection to resolve xUnit test cases.

How to use

Install the Nuget package.

Install-Package Xunit.DependencyInjection

In your testing project, add the following framework

namespace Your.Test.Project
{
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddTransient<IDependency, DependencyClass>();
        }
    }
}

Example test class.

public interface IDependency
{
    int Value { get; }
}

internal class DependencyClass : IDependency
{
    public int Value => 1;
}

public class MyAwesomeTests
{
    private readonly IDependency _d;

    public MyAwesomeTests(IDependency d) => _d = d;

    [Fact]
    public void AssertThatWeDoStuff()
    {
        Assert.Equal(1, _d.Value);
    }
}

Integration asp.net core TestHost(3.0+)

Install-Package Microsoft.AspNetCore.TestHost
public class Startup
{
    public void ConfigureHost(IHostBuilder hostBuilder) =>
        hostBuilder.ConfigureWebHost(webHostBuilder => webHostBuilder
            .UseTestServer()
            .Configure(Configure)
            .ConfigureServices(services => services.AddRouting()));

    private void Configure(IApplicationBuilder app) =>
        app.UseRouting().UseEndpoints(endpoints => xxx);
}

V7 new features

  • Don't need to add the assembly attribute TestFramework.
  • Startup does not need to inherit DependencyInjectionTestFramework.
  • Configure method support multiple parameters, like asp.net core Startup.

V6 to V7 break changes

-[assembly: TestFramework("Your.Test.Project.Startup", "Your.Test.Project")]

namespace Your.Test.Project
{
-   public class Startup : DependencyInjectionTestFramework
+   public class Startup
    {
-       public Startup(IMessageSink messageSink) : base(messageSink) { }

-       protected void ConfigureServices(IServiceCollection services)
+       public void ConfigureServices(IServiceCollection services)
        {
            services.AddTransient<IDependency, DependencyClass>();
        }

-       protected override IHostBuilder CreateHostBuilder() =>
-           base.CreateHostBuilder(assemblyName)
-               .ConfigureServices(ConfigureServices);

-       protected override void Configure(IServiceProvider provider)
+       public void Configure(IServiceProvider provider)
    }
}

Startup limitation

  • CreateHostBuilder method
public class Startup
{
    public IHostBuilder CreateHostBuilder([AssemblyName assemblyName]) { }
}
  • ConfigureHost method
public class Startup
{
    public void ConfigureHost(IHostBuilder hostBuilder) { }
}
  • ConfigureServices method
public class Startup
{
    public void ConfigureServices(IServiceCollection services[, HostBuilderContext context]) { }
}
  • Configure method Anything defined in ConfigureServices, can be specified in the Configure method signature. These services are injected if they're available.

How to find Startup?

Default is find Your.Test.Project.Startup, Your.Test.Project. If you want use a special Startup, you can defined XunitStartupAssembly and XunitStartupFullName in PropertyGroup section

<Project>
  <PropertyGroup>
    <XunitStartupAssembly>Abc</XunitStartupAssembly>
    <XunitStartupFullName>Xyz</XunitStartupFullName>
  </PropertyGroup>
</Project>
XunitStartupAssembly XunitStartupFullName Startup
Your.Test.Project.Startup, Your.Test.Project
Abc Abc.Startup, Abc
Xyz Xyz, Your.Test.Project
Abc Xyz Xyz, Abc

V5 to V6 break changes

namespace Your.Test.Project
{
    public class Startup : DependencyInjectionTestFramework
    {
        public Startup(IMessageSink messageSink) : base(messageSink) { }

-       protected override void ConfigureServices(IServiceCollection services)
+       protected void ConfigureServices(IServiceCollection services)
        {
            services.AddTransient<IDependency, DependencyClass>();
        }

+       protected override IHostBuilder CreateHostBuilder(AssemblyName assemblyName) =>
+           base.CreateHostBuilder(assemblyName)
+               .ConfigureServices(ConfigureServices);
    }
}

How to inject ITestOutputHelper

internal class DependencyClass : IDependency
{
    private readonly ITestOutputHelperAccessor _testOutputHelperAccessor;

    public DependencyClass(ITestOutputHelperAccessor testOutputHelperAccessor)
    {
        _testOutputHelperAccessor = testOutputHelperAccessor;
    }
}

Write Microsoft.Extensions.Logging to ITestOutputHelper

    public class Startup
    {
        public void Configure(ILoggerFactory loggerFactory, ITestOutputHelperAccessor accessor) =>
            loggerFactory.AddProvider(new XunitTestOutputLoggerProvider(accessor));
    }

How to inject IConfiguration or IHostingEnvironment into Startup?

    public class Startup
    {
        public void ConfigureHost(IHostBuilder hostBuilder) =>
            hostBuilder
                .ConfigureServices((context, services) => { context.XXXX });
    }

or

    public class Startup
    {
        public void ConfigureServices(IServiceCollection services, HostBuilderContext context)
        {
            context.XXXX;
        }
    }

How to configure IConfiguration?

    public class Startup
    {
        public void ConfigureHost(IHostBuilder hostBuilder) =>
            hostBuilder
                .ConfigureHostConfiguration(builder => { })
                .ConfigureAppConfiguration((context, builder) => { });
    }
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].