Beispiel #1
0
        public void Correctly_executes_service_agents()
        {
            MockRepository mocks = new MockRepository();

            IApplicationSettings settings      = mocks.CreateMock <IApplicationSettings>();
            ITypeActivator       activator     = mocks.CreateMock <ITypeActivator>();
            IServiceAgentFactory factory       = mocks.CreateMock <IServiceAgentFactory>();
            IServiceAgent        serviceAgent1 = mocks.CreateMock <IServiceAgent>();
            IServiceAgent        serviceAgent2 = mocks.CreateMock <IServiceAgent>();

            IServiceAgent[] serviceAgents = new IServiceAgent[] { serviceAgent1, serviceAgent2 };

            IServiceAgentAggregator aggregator = new ServiceAgentAggregator(settings, activator);

            using (mocks.Record())
            {
                Expect.Call(settings.GetServiceAgentFactory()).Return("serviceAgentType");
                Expect.Call(activator.ActivateType <IServiceAgentFactory>("serviceAgentType")).Return(factory);
                Expect.Call(factory.GetServiceAgents()).Return(serviceAgents);

                Expect.Call(serviceAgent1.AgentName).Return("FirstAgent").Repeat.Any();
                serviceAgent1.Run();

                Expect.Call(serviceAgent2.AgentName).Return("SecondAgent").Repeat.Any();
                serviceAgent2.Run();
            }

            using (mocks.Playback())
            {
                aggregator.ExecuteServiceAgentCycle();
            }

            mocks.VerifyAll();
        }
        public void ExecuteServiceAgentCycle()
        {
            string factoryType           = _settings.GetServiceAgentFactory();
            IServiceAgentFactory factory = _activator.ActivateType <IServiceAgentFactory>(factoryType);

            foreach (IServiceAgent agent in factory.GetServiceAgents())
            {
                try
                {
                    Logger.Debug(this, string.Format("Executing agent: {0}", agent.AgentName));
                    agent.Run();
                    Logger.Debug(this, string.Format("Agent execution completed: {0}", agent.AgentName));
                }
                catch (Exception ex)
                {
                    Logger.Error(this, ex.Message, ex);
                }
            }
        }
Beispiel #3
0
        public void Should_continue_with_next_agents_event_if_one_agent_fails()
        {
            ApplicationException exception = new ApplicationException("Test Exception");

            MockRepository mocks = new MockRepository();

            IApplicationSettings settings  = mocks.CreateMock <IApplicationSettings>();
            ITypeActivator       activator = mocks.CreateMock <ITypeActivator>();
            IServiceAgentFactory factory   = mocks.CreateMock <IServiceAgentFactory>();

            IServiceAgent serviceAgent1 = mocks.CreateMock <IServiceAgent>();
            IServiceAgent serviceAgent2 = mocks.CreateMock <IServiceAgent>();

            IServiceAgent[] serviceAgents = new IServiceAgent[] { serviceAgent1, serviceAgent2 };


            IServiceAgentAggregator aggregator = new ServiceAgentAggregator(settings, activator);

            using (mocks.Record())
            {
                Expect.Call(settings.GetServiceAgentFactory()).Return("serviceAgentType");
                Expect.Call(activator.ActivateType <IServiceAgentFactory>("serviceAgentType")).Return(factory);
                Expect.Call(factory.GetServiceAgents()).Return(serviceAgents);

                Expect.Call(serviceAgent1.AgentName).Return("FirstAgent").Repeat.Any();
                serviceAgent1.Run();
                LastCall.On(serviceAgent1).Throw(exception);

                Expect.Call(serviceAgent2.AgentName).Return("SecondAgent").Repeat.Any();
                serviceAgent2.Run();
            }

            using (mocks.Playback())
            {
                aggregator.ExecuteServiceAgentCycle();
            }

            mocks.VerifyAll();
        }