public void AddSelfActivatingSchema(DI.ServiceLifetime serviceLifetime) { var services = new ServiceCollection(); services.AddSingleton(Class2.Instance); services.AddGraphQL(b => b.AddSelfActivatingSchema <MySchema>(serviceLifetime)); services.Single(x => x.ServiceType == typeof(MySchema)).Lifetime.ShouldBe(serviceLifetime switch { DI.ServiceLifetime.Singleton => ServiceLifetime.Singleton, DI.ServiceLifetime.Scoped => ServiceLifetime.Scoped, _ => throw new ApplicationException() });
public void Register(Type serviceType, Type implementationType, DI.ServiceLifetime serviceLifetime, bool replace, bool withExisting) { bool match = false; var descriptorList = new List <ServiceDescriptor>(); var mockServiceCollection = new Mock <IServiceCollection>(MockBehavior.Strict); mockServiceCollection.Setup(x => x.Add(It.IsAny <ServiceDescriptor>())).Callback <ServiceDescriptor>(d => { if (d.ServiceType == serviceType) { match.ShouldBeFalse(); d.ImplementationType.ShouldBe(implementationType); d.Lifetime.ShouldBe(serviceLifetime switch { DI.ServiceLifetime.Singleton => ServiceLifetime.Singleton, DI.ServiceLifetime.Scoped => ServiceLifetime.Scoped, DI.ServiceLifetime.Transient => ServiceLifetime.Transient, _ => throw new ApplicationException() }); match = true; }