public void BasicTest()
        {
            string goodInstance = "goodInstance";
            var statePersister = new Mock<IStatePersister>();
            // Creating fake data for the statePersister...
            var configurationsPersisted = new List<Configuration>()
            {
                GetConfig(1),
                GetConfig(2),
                GetConfig(3)
            };
            Configuration firstGoodConfiguration = GetConfig(1);
            Configuration secondGoodConfiguration = GetConfig(6);
            firstGoodConfiguration.Instance = goodInstance;
            secondGoodConfiguration.Instance = goodInstance;
            configurationsPersisted.Add(firstGoodConfiguration);
            configurationsPersisted.Add(secondGoodConfiguration);

            statePersister.Setup(o => o.Read()).Returns(configurationsPersisted);

            //Creating a fake requestmanager.
            var subscriptionsRequest = new Mock<IRequestManager<ConfigurationSubscription, ConfigurationSubscriptionAnswer>>();
            var updateRequest = new Mock<IRequestManager<ConfigurationUpdate, ConfigurationUpdateAnswer>>();
            var allAnswerSent = new List<AnwserMessage<ConfigurationSubscriptionAnswer>>();
            subscriptionsRequest.Setup(o => o.Send(It.IsAny<AnwserMessage<ConfigurationSubscriptionAnswer>>())).
                Callback<AnwserMessage<ConfigurationSubscriptionAnswer>>(allAnswerSent.Add);

            var toTest = new ConfigurationRequestHandler(subscriptionsRequest.Object, updateRequest.Object, statePersister.Object);

            //Sending a request to the manager
            var requestId = 1021;
            var request = GetRequestMessage(requestId, goodInstance);
            subscriptionsRequest.Raise(mock => mock.OnRequest += null, null, request);

            //We check that we received what we should, one message with two elements
            Assert.AreEqual(1, allAnswerSent.Count);
            Assert.AreEqual(requestId, allAnswerSent.First().id);
            var sentConfigurations = allAnswerSent.First().answer.result;
            Assert.AreEqual(2, sentConfigurations.Count);
            Assert.AreEqual(firstGoodConfiguration, sentConfigurations.First());
            Assert.AreEqual(secondGoodConfiguration, sentConfigurations.Last());

            //test wildcard :
            var requestAll = GetRequestMessage(requestId+1, ConfigurationRequestHandler.ConfigurationInstanceWildcard);
            subscriptionsRequest.Raise(mock => mock.OnRequest += null, null, requestAll);
            Assert.AreEqual(configurationsPersisted.Count, allAnswerSent.Last().answer.result.Count);
        }
예제 #2
0
        static void Main(string[] args)
        {
            logger.Info("Starting application");
            IWebsocket connection = new RequestFlickerService("ConfigurationService");
            //Expected input :
            //{"service":"ConfigurationService","request":{"type":"ConfigurationSubscription", "instance":"*"}}
            var subscriptionsRequestManager = new JsonRequestManager<ConfigurationSubscription, ConfigurationSubscriptionAnswer>(connection);
            //{"service":"ConfigurationService","request":{"type":"ConfigurationUpdate", "update":{"Instance": "inst9", "Value": "value9", "Key": "key9"}}}
            var updateRequestManager = new JsonRequestManager<ConfigurationUpdate, ConfigurationUpdateAnswer>(connection);

            var requestHandler = new ConfigurationRequestHandler(subscriptionsRequestManager,updateRequestManager, new StatePersister());

            while (true)
            {
                Thread.Sleep(300000);
                NLog.LogManager.GetCurrentClassLogger().Info("I am still alive!(Providing some infos here...)");
            }
        }