public int Start(params string[] args)
        {
            var communicator = _container.Resolve <Communicator>();

            communicator.Send("Starting!");
            return(0);
        }
        public void Start(params string[] args)
        {
            var threads = int.Parse(args.First());
            var messageConsumerFactory  = _configurer.Resolve <IMessageConsumerFactory>();
            var messagePublisherFactory = _configurer.Resolve <IMessagePublisherFactory>();

            Task.Run(() =>
            {
                Parallel.For(0, threads, i =>
                {
                    _messageConsumers.Add(messageConsumerFactory.Consume <TestMessage>(
                                              "myExchange" + i % 2,
                                              "queue" + i % 2,
                                              "routing" + i % 2,
                                              message =>
                    {
                        using (var messagePublisher = messagePublisherFactory.Create("myExchange" + i % 2))
                        {
                            messagePublisher.Publish("myMessage",
                                                     new TestMessage(i + ": " + message.Message));
                        }
                    }));
                });
            }).ContinueWith(task =>
            {
                OnUnhandledException?.Invoke(task.Exception);
            }, TaskContinuationOptions.OnlyOnFaulted);
        }
        public void RegisterFactory_WithSingleton_Should_Return_OneInstance()
        {
            var resolver = new SimpleInjectorDependencyResolver();

            resolver.RegisterFactory(typeof(Class6), () => new Class6(), LifetimeScope.Singleton);

            var result        = resolver.Resolve <Class6>();
            var anotherResult = resolver.Resolve <Class6>();

            Assert.IsNotNull(result);
            Assert.AreEqual(result, anotherResult);
            Assert.AreEqual(1, Class6.Instances);
        }
        public void Start(params string[] args)
        {
            var messagePublisherFactory = _configurer.Resolve <IMessagePublisherFactory>();

            Task.Run(() =>
            {
                var publishConfirmTimeOut = TimeSpan.FromSeconds(3);
                using (var messagePublisher = messagePublisherFactory.Create("myExchange0"))
                {
                    var confirmed = messagePublisher
                                    .Publish("myMessage",
                                             new TestMessage("Testing sending a message using RabbitMQ"))
                                    .WaitForConfirm(publishConfirmTimeOut, out var timedOut);

                    if (confirmed == false)
                    {
                        throw new InvalidOperationException("Failed waiting for publish confirm.");
                    }

                    if (timedOut)
                    {
                        throw new TimeoutException($"Timed out waiting for confirms. Waited for {publishConfirmTimeOut.TotalSeconds}s.");
                    }

                    messagePublisher
                    .Publish("messageConfirmed",
                             new TestMessage("Test message has been confirmed"));
                }
            }).ContinueWith(task =>
            {
                OnUnhandledException?.Invoke(task.Exception);
            }, TaskContinuationOptions.OnlyOnFaulted);
        }
Exemplo n.º 5
0
        public void Unresolveable_Should_Return_Default()
        {
            var resolver = new SimpleInjectorDependencyResolver();

            var result = resolver.Resolve <Class3>();

            Assert.IsNotNull(result);
        }
Exemplo n.º 6
0
        public void Unresolveable_Should_Return_Null()
        {
            var resolver = new SimpleInjectorDependencyResolver();

            var result = resolver.Resolve <IFace1>();

            Assert.IsNull(result);
        }
 public void Start(params string[] args)
 {
     Task.Run(() =>
     {
         var connectionFactory = _configurer.Resolve <IConnectionFactory>();
         _connection           = connectionFactory.CreateConnection();
     }).ContinueWith(task =>
     {
         OnUnhandledException?.Invoke(task.Exception);
     }, TaskContinuationOptions.OnlyOnFaulted);
 }
Exemplo n.º 8
0
        public void Array_Injector_Should_Inject_One_Registed_Type_As_Enumerable()
        {
            var resolver = new SimpleInjectorDependencyResolver();

            resolver.RegisterType <IFace1, Class1>();

            var resolve = resolver.Resolve <Class5>();

            Assert.AreEqual(1, resolve.Ifaces.Count());
            Assert.IsTrue(resolve.Ifaces.OfType <Class1>().Any());
            Assert.IsFalse(resolve.Ifaces.OfType <Class2>().Any());
            Assert.IsFalse(resolve.Ifaces.OfType <Class3>().Any());
        }
        public void Array_Injector_Should_Inject_All_Registed_Types()
        {
            var resolver = new SimpleInjectorDependencyResolver();
            resolver.RegisterType<IFace1, Class1>();
            resolver.RegisterType<IFace1, Class2>();
            resolver.RegisterInstance<IFace1>(new Class3());

            var resolve = resolver.Resolve<Class4>();
            Assert.AreEqual(3, resolve.Ifaces.Count());
            Assert.IsTrue(resolve.Ifaces.OfType<Class1>().Any());
            Assert.IsTrue(resolve.Ifaces.OfType<Class2>().Any());
            Assert.IsTrue(resolve.Ifaces.OfType<Class3>().Any());
        }
Exemplo n.º 10
0
        public void Array_Injector_Should_Inject_All_Registed_Types()
        {
            var resolver = new SimpleInjectorDependencyResolver();

            resolver.RegisterType <IFace1, Class1>();
            resolver.RegisterType <IFace1, Class2>();
            resolver.RegisterInstance <IFace1>(new Class3());

            var resolve = resolver.Resolve <Class4>();

            Assert.AreEqual(3, resolve.Ifaces.Count());
            Assert.IsTrue(resolve.Ifaces.OfType <Class1>().Any());
            Assert.IsTrue(resolve.Ifaces.OfType <Class2>().Any());
            Assert.IsTrue(resolve.Ifaces.OfType <Class3>().Any());
        }
Exemplo n.º 11
0
        public void Start(params string[] args)
        {
            var messagesToPublish       = int.Parse(args.First());
            var messagePublisherFactory = _configurer.Resolve <IMessagePublisherFactory>();

            Task.Run(() =>
            {
                Parallel.For(0, messagesToPublish, i =>
                {
                    using (var messagePublisher = messagePublisherFactory.Create("myExchange" + i % 2))
                    {
                        messagePublisher.Publish("myMessage",
                                                 new TestMessage("Testing sending a message using RabbitMQ"));
                    }
                });
            }).ContinueWith(task =>
            {
                OnUnhandledException?.Invoke(task.Exception);
            }, TaskContinuationOptions.OnlyOnFaulted);
        }
        public void Unresolveable_Should_Return_Null()
        {
            var resolver = new SimpleInjectorDependencyResolver();

            var result = resolver.Resolve<IFace1>();
            Assert.IsNull(result);
        }
        public void Unresolveable_Should_Return_Default()
        {
            var resolver = new SimpleInjectorDependencyResolver();

            var result = resolver.Resolve<Class3>();
            Assert.IsNotNull(result);
        }
        public void Array_Injector_Should_Inject_One_Registed_Type_As_Enumerable()
        {
            var resolver = new SimpleInjectorDependencyResolver();
            resolver.RegisterType<IFace1, Class1>();

            var resolve = resolver.Resolve<Class5>();
            Assert.AreEqual(1, resolve.Ifaces.Count());
            Assert.IsTrue(resolve.Ifaces.OfType<Class1>().Any());
            Assert.IsFalse(resolve.Ifaces.OfType<Class2>().Any());
            Assert.IsFalse(resolve.Ifaces.OfType<Class3>().Any());
        }