Esempio n. 1
0
 private static void ProducerOnOnRequest(object sender, RequestMessage request)
 {
     var websocket = (IRequestManager) sender;
     var toSend = projectManager.Update(request.request.projectId,
         request.request.lastUpdated, request.request.toUpdate);
     var splitonSynchRequest = new SplitonSynchRequest();
     //If there is no update, we do not change the lastUpdate
     var lastUpdated = request.request.lastUpdated;
     if (toSend.Count != 0)
     {
         //But if there is some change, the last update is the date of the last received update!
         lastUpdated = toSend.Select(o => o.lastUpdated).Max();
     }
     splitonSynchRequest.lastUpdated = lastUpdated;
     splitonSynchRequest.projectId = request.request.projectId;
     splitonSynchRequest.toUpdate = toSend;
     var answer = new AnwserMessage();
     answer.id = request.id;
     answer.answer = splitonSynchRequest;
     websocket.Send(answer);
 }
        public void GoodRequestIsForwarded()
        {
            var requestReceived = new RequestMessage();

            FakeWebsocket w = new FakeWebsocket();
            IRequestManager totest = new JsonLayer(w);
            totest.OnRequest += (sender, message) => requestReceived = message;
            //Test when we receive good data
            var synchRequest = new SplitonSynchRequest();
            synchRequest.lastUpdated = DateTime.Parse("2000-02-02").JavascriptTicks();
            synchRequest.projectId = "projectwq";
            synchRequest.toUpdate = new List<UpdatableElement>() { GetFakeTransaction(1) };
            var request = new RequestMessage();
            request.id = 12;
            request.request = synchRequest;
            string serializeRequest = JsonConvert.SerializeObject(request);
            Write("Simulating a string request from websocket connection ...");
            w.SimulateReceived(serializeRequest);

            Assert.AreEqual(request.id, requestReceived.id);
            Assert.AreEqual(request.request.lastUpdated, requestReceived.request.lastUpdated);
            Assert.AreEqual(request.request.projectId, requestReceived.request.projectId);
            Assert.AreEqual(request.request.toUpdate, requestReceived.request.toUpdate);
        }