public void Resolve_FromInternalServices_FindsType() { var serviceProvider = new ServiceCollection() .AddTransient(typeof(ITriggerInstanceFactory <IBeforeSaveTrigger <object> >), _ => new TriggerInstanceFactory <SampleTrigger>(null)) .BuildServiceProvider(); var applicationServiceProvider = new ServiceCollection().BuildServiceProvider(); var subject = new TriggerFactory(serviceProvider); var triggers = subject.Resolve(applicationServiceProvider, typeof(IBeforeSaveTrigger <object>)); Assert.Single(triggers); }
public void Resolve_FromExternalServiceProvider_FindsType() { var serviceProvider = new ServiceCollection().BuildServiceProvider(); var applicationServiceProvider = new ServiceCollection() .AddTransient <IBeforeSaveTrigger <object>, SampleTrigger>() .BuildServiceProvider(); var subject = new TriggerFactory(serviceProvider); var triggers = subject.Resolve(applicationServiceProvider, typeof(IBeforeSaveTrigger <object>)); Assert.Single(triggers); }
public void Resolve_FromInternalServices_GetsConstructedUsingExternalServiceProvider() { var serviceProvider = new ServiceCollection() .AddLogging() .AddTransient(typeof(ITriggerInstanceFactory <IBeforeSaveTrigger <object> >), _ => new TriggerInstanceFactory <SampleTrigger2>(null)) .BuildServiceProvider(); var subject = new TriggerFactory(serviceProvider); var applicationServiceProvider = new ServiceCollection() .AddSingleton(subject) .BuildServiceProvider(); var trigger = subject.Resolve(applicationServiceProvider, typeof(IBeforeSaveTrigger <object>)).FirstOrDefault() as SampleTrigger2; Assert.NotNull(trigger); Assert.Equal(subject, trigger.TriggerFactory); }