예제 #1
0
 protected void Application_Start()
 {
     Resolver.Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config/unity.config"));
     GlobalConfiguration.Configure(WebApiConfig.Register);
     // GlobalConfiguration.Configuration.Filters.Add(new CrossSiteAttribute());
     GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(Resolver.Current.Container);
 }
예제 #2
0
 public void SetUp()
 {
     _objectCommandHandler = new ObjectCommandHandler();
     _commandHandlerA      = new CommandHandlerA();
     _commandHandlerB      = new CommandHandlerB();
     Resolver.Configure(type => null, LocateAllCommandHandlers, o => { });
 }
예제 #3
0
        public void GivenAMessage_WhenAskedToProcess_ShouldTryToFindHandlersForMessageTypeHierarchy()
        {
            var expected = new[]
            {
                typeof(ICommandHandler <object>),
                typeof(ICommandHandler <SimpleCommandBase>),
                typeof(ICommandHandler <SimpleCommand>),
            };

            var result = new List <Type>();

            Resolver.Reset();
            Resolver.Configure(
                type => null,
                type =>
            {
                result.Add(type);
                return(LocateAllCommandHandlers(type));
            },
                o => { });

            var processor = new CommandProcessorTestDataBuilder().Build();

            processor.Process(new SimpleCommand());

            CollectionAssert.AreEqual(expected, result);
        }
예제 #4
0
 protected void Application_Start()
 {
     Resolver.Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config/unity.config"));
     DependencyResolver.SetResolver(new UnityDependencyResolver(Resolver.Current.Container));
     AreaRegistration.RegisterAllAreas();
     RouteConfig.RegisterRoutes(RouteTable.Routes);
 }
예제 #5
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     Resolver.Configure();
     ModelValidatorProviders.Providers.Clear();
 }
예제 #6
0
        public void NullListFails()
        {
            List <InjectionConfiguration> config = null;

            using (var resolver = new Resolver())
            {
                Assert.Throws <ArgumentException>(() => { resolver.Configure(config); });
            }
        }
예제 #7
0
        public void EmptyListSucceeds()
        {
            List <InjectionConfiguration> config = new List <InjectionConfiguration>();

            using (var resolver = new Resolver())
            {
                resolver.Configure(config);
            }
        }
예제 #8
0
        public void SetUp()
        {
            _objectEventHandler = new ObjectEventHandler();
            _eventHandlerA      = new EventHandlerA();
            _eventHandlerB      = new EventHandlerB();
            _eventBus           = new EventBusTestDataBuilder().Build();

            Resolver.Configure(type => null, LocateAllEventHandlers, o => { });
            Conventions.SetRetryableEventHandlingExceptionFilter((o, exception) => false);
        }
 public void SetUp()
 {
     Resolver.Configure(type =>
     {
         if (type == typeof(ILogger))
         {
             return(new ConsoleLogger());
         }
         throw new InvalidOperationException(string.Format("No type of {0} registered.", type));
     },
                        type => null,
                        o => { });
 }
예제 #10
0
        public void NullImplementationNameFails()
        {
            List <InjectionConfiguration> config = new List <InjectionConfiguration>()
            {
                new InjectionConfiguration()
                {
                    Target         = typeof(TestCases.IService2).AssemblyQualifiedName,
                    Implementation = null
                }
            };

            using (var resolver = new Resolver())
            {
                Assert.Throws <ArgumentNullException>(() => { resolver.Configure(config); });
            }
        }
예제 #11
0
        public void InvalidTargetNameFails()
        {
            List <InjectionConfiguration> config = new List <InjectionConfiguration>()
            {
                new InjectionConfiguration()
                {
                    Target         = "",
                    Implementation = typeof(TestCases.ImplementationOfIService2).AssemblyQualifiedName
                }
            };

            using (var resolver = new Resolver())
            {
                Assert.Throws <TypeLoadException>(() => { resolver.Configure(config); });
            }
        }
예제 #12
0
        public void SetUp()
        {
            var _nullLogger = new ConsoleLogger();

            Resolver.Configure(
                type =>
            {
                if (type == typeof(ILogger))
                {
                    return(_nullLogger);
                }

                throw new NotSupportedException(string.Format("TestFixtureBase::SetUp - Nothing registered for {0}", type));
            },
                type => null,
                o => { });
        }
        public void SetUp()
        {
            Resolver.Configure(
                type =>
            {
                if (type == typeof(ILogger))
                {
                    return(new ConsoleLogger());
                }

                throw new InvalidOperationException(string.Format("No resolver registered for {0}", type));
            },
                type => null,
                o => { });

            ObjectComparisonResult.ThrowOnFail = true;
        }
예제 #14
0
        public void TransientConfigurationsSucceed()
        {
            List <InjectionConfiguration> config = new List <InjectionConfiguration>()
            {
                new InjectionConfiguration()
                {
                    Target         = typeof(TestCases.IService2).AssemblyQualifiedName,
                    Implementation = typeof(TestCases.ImplementationOfIService2).AssemblyQualifiedName,
                    Lifetime       = Lifetime.Transient
                }
            };

            using (var resolver = new Resolver())
            {
                resolver.Configure(config);
                var result = resolver.Resolve(typeof(TestCases.IService2));
                Assert.Equal(typeof(TestCases.ImplementationOfIService2), result.GetType());
            }
        }
예제 #15
0
        public void SingletonConfigurationsSucceed()
        {
            List <InjectionConfiguration> config = new List <InjectionConfiguration>()
            {
                new InjectionConfiguration()
                {
                    Target         = typeof(TestCases.IService2).AssemblyQualifiedName,
                    Implementation = typeof(TestCases.ImplementationOfIService2).AssemblyQualifiedName,
                    Lifetime       = Lifetime.Singleton
                }
            };

            using (var resolver = new Resolver())
            {
                resolver.Configure(config);
                var r1 = resolver.Resolve(typeof(TestCases.IService2));
                var r2 = resolver.Resolve(typeof(TestCases.IService2));
                Assert.Equal(r1, r2);
            }
        }
        public void SetUp()
        {
            _logger = new ConsoleLogger();

            _eventStoreConnection = EventStoreConnection.Create(new IPEndPoint(IPAddress.Loopback, 1113));
            _eventStoreConnection.ConnectAsync().Wait();

            Resolver.Configure(
                type =>
            {
                if (type == typeof(ILogger))
                {
                    return(_logger);
                }

                throw new InvalidOperationException($"No type of {type} registered.");
            },
                type => null,
                o => { });
        }
 public void SetUp()
 {
     //_documentStore = new EmbeddableDocumentStore { RunInMemory = true };
     _documentStore = new DocumentStore
     {
         Url             = "http://localhost:8080/",
         DefaultDatabase = GetType().FullName
     };
     _documentStore.Initialize();
     Resolver.Configure(type =>
     {
         if (type == typeof(ILogger))
         {
             return(new ConsoleLogger());
         }
         throw new InvalidOperationException(string.Format("No type of {0} registered.", type));
     },
                        type => null,
                        o => { });
 }
예제 #18
0
        public void GivenAMessageThatWillFailHandling_WhenAskedToPublish_ShouldAllowRetryableExceptionsToPropagate()
        {
            Conventions.SetRetryableEventHandlingExceptionFilter((o, e) => true);
            var failingEventHandler = new FailingEventHandler();

            Resolver.Reset();
            Resolver.Configure(
                type => null,
                type => new object[] { failingEventHandler }.Where(x => type.IsAssignableFrom(x.GetType())),
                o => { });

            var eventThatWillFailToBeHandled = new SimpleEvent();
            var exception = Assert.Throws <TargetInvocationException>(() => _eventBus.Publish(eventThatWillFailToBeHandled));

            CollectionAssert.AreEqual(
                new[]
            {
                typeof(SimpleEvent)
            },
                failingEventHandler.TargetsCalled);
        }
예제 #19
0
        public void GivenAMessageThatWillFailHandling_WhenAskedToPublish_ShouldGenerateFailedHandlingMessage()
        {
            var failingEventHandler = new FailingEventHandler();

            Resolver.Reset();
            Resolver.Configure(
                type => null,
                type => new object[] { failingEventHandler }.Where(x => type.IsAssignableFrom(x.GetType())),
                o => { });

            var eventThatWillFailToBeHandled = new SimpleEvent();

            _eventBus.Publish(eventThatWillFailToBeHandled);

            CollectionAssert.AreEqual(
                new[]
            {
                typeof(SimpleEvent),
                typeof(IEventHandlingFailedEvent <SimpleEvent>)
            },
                failingEventHandler.TargetsCalled);
        }
예제 #20
0
        public void GivenAMessage_WhenAskedToPublish_ShouldTryToFindHandlersForMessageTypeHierarchy()
        {
            var expected = new[]
            {
                typeof(IEventHandler <object>),
                typeof(IEventHandler <IMessage>),
                typeof(IEventHandler <Message>),
                typeof(IEventHandler <IEvent>),
                typeof(IEventHandler <Event>),
                typeof(IEventHandler <SimpleEventBase>),
                typeof(IEventHandler <SimpleEvent>),
                typeof(IEventHandler <IEventHandlingSucceededEvent <object> >),
                typeof(IEventHandler <IEventHandlingSucceededEvent <IMessage> >),
                typeof(IEventHandler <IEventHandlingSucceededEvent <Message> >),
                typeof(IEventHandler <IEventHandlingSucceededEvent <IEvent> >),
                typeof(IEventHandler <IEventHandlingSucceededEvent <Event> >),
                typeof(IEventHandler <IEventHandlingSucceededEvent <SimpleEventBase> >),
                typeof(IEventHandler <IEventHandlingSucceededEvent <SimpleEvent> >)
            };

            var result = new List <Type>();

            Resolver.Reset();
            Resolver.Configure(
                type => null,
                type =>
            {
                result.Add(type);
                return(LocateAllEventHandlers(type));
            },
                o => { });

            _eventBus.Publish(new SimpleEvent());

            CollectionAssert.AreEqual(expected, result);
        }
예제 #21
0
 public void  CacheTest2()
 {
     Resolver.Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config/unity.config"));
     _cache = Resolver.Current.Resolve <IRedisCache>();
 }