public void GetServerRepairOrderHashesResponseTest() { var message = new GetServerRepairOrderHashesResponse(); Assert.AreEqual(message.Kind, MessageKind.GetServerRepairOrderHashesResponse); message.TotalCount = 55; var order = new RepairOrderServerHashDTO(); order.DataHash = "HashData111"; order.OrderTimelinesCount = 112; order.RepairOrderID = Guid.NewGuid(); var workItem = new WorkItemServerHashDTO(); workItem.WorkItemID = Guid.NewGuid(); workItem.DataHash = "Titl1231231e"; var deviceItem = new DeviceItemServerHashDTO(); deviceItem.DeviceItemID = Guid.NewGuid(); deviceItem.DataHash = "Tiqsdqw1233123tle"; order.WorkItems.Add(workItem); order.DeviceItems.Add(deviceItem); message.RepairOrderServerHashes.Add(order); var serializer = new ProtocolSerializer(ProtocolVersion.Version10); var data = serializer.Serialize(message); Assert.IsNotNull(data); var savedMessage = serializer.DeserializeGetServerRepairOrderHashesResponse(data); Assert.IsNotNull(savedMessage); Assert.AreEqual(serializer.GetMessageInfoOrNull(data).Kind, MessageKind.GetServerRepairOrderHashesResponse); Assert.AreEqual(savedMessage.RepairOrderServerHashes.Count, 1); Assert.AreEqual(savedMessage.RepairOrderServerHashes[0].DeviceItems.Count, 1); Assert.AreEqual(savedMessage.RepairOrderServerHashes[0].WorkItems.Count, 1); Assert.AreEqual(savedMessage.TotalCount, message.TotalCount); var savedDeviceItem = savedMessage.RepairOrderServerHashes[0].DeviceItems[0]; var savedWorkItem = savedMessage.RepairOrderServerHashes[0].WorkItems[0]; var savedOrder = savedMessage.RepairOrderServerHashes[0]; Assert.AreEqual(savedOrder.DataHash, order.DataHash); Assert.AreEqual(savedOrder.RepairOrderID, order.RepairOrderID); Assert.AreEqual(savedOrder.OrderTimelinesCount, order.OrderTimelinesCount); Assert.AreEqual(deviceItem.DeviceItemID, savedDeviceItem.DeviceItemID); Assert.AreEqual(deviceItem.DataHash, savedDeviceItem.DataHash); Assert.AreEqual(savedWorkItem.DataHash, workItem.DataHash); Assert.AreEqual(savedWorkItem.WorkItemID, workItem.WorkItemID); }
/// <summary> /// Обработчик запроса на получение хэшей заказов. /// </summary> /// <param name="serializer">Сериализатор протокола.</param> /// <param name="postData">Данные запроса.</param> /// <param name="hostAddress">Адрес клиента.</param> /// <returns>Результат.</returns> private string ProcessGetServerRepairOrderHashesRequest(ProtocolSerializer serializer, string postData, string hostAddress) { var request = serializer.DeserializeGetServerRepairOrderHashesRequest(postData); _logger.InfoFormat( "Получен запрос на получение информации по хэшам заказов от пользователя {0} с клиента {1}", request.UserID, hostAddress); var userDomainID = CheckSignedMessage(request); var response = new GetServerRepairOrderHashesResponse(); int total; var hashes = RemontinkaServer.Instance.DataStore.GetRepairOrderHashes(userDomainID, request.LastRepairOrderID, out total).ToList(); response.TotalCount = total; foreach (var repairOrderHash in hashes) { var item = new RepairOrderServerHashDTO { DataHash = repairOrderHash.DataHash, OrderTimelinesCount = repairOrderHash.OrderTimelinesCount, RepairOrderID = repairOrderHash.RepairOrderID }; response.RepairOrderServerHashes.Add(item); foreach (var deviceItemHash in repairOrderHash.DeviceItemHashes) { item.DeviceItems.Add(new DeviceItemServerHashDTO { DeviceItemID = deviceItemHash.DeviceItemID, DataHash = deviceItemHash.DataHash }); } //foreach foreach (var workItemHash in repairOrderHash.WorkItemHashes) { item.WorkItems.Add(new WorkItemServerHashDTO { WorkItemID = workItemHash.WorkItemID, DataHash = workItemHash.DataHash }); } //foreach } //foreach return(serializer.Serialize(response)); }