예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }