public void GetGetRepairOrdersResponseTest() { var message = new GetRepairOrdersResponse(); Assert.AreEqual(message.Kind, MessageKind.GetRepairOrdersResponse); var order = new RepairOrderDTO(); order.BranchID = Guid.NewGuid(); order.CallEventDate = new DateTime(2015, 06, 01); order.ClientAddress = "ClientAddress"; order.ClientEmail = "ClientEmail"; order.ClientFullName = "ClientFullName"; order.ClientPhone = "ClientPhone"; order.DateOfBeReady = new DateTime(2015, 07, 07); order.Defect = "Defect"; order.DeviceAppearance = "DeviceAppearance"; order.DeviceModel = "DeviceModel"; order.DeviceSN = "DeviceSN"; order.DeviceTitle = "DeviceTitle"; order.DeviceTrademark = "DeviceTrademark"; order.EngineerID = Guid.NewGuid(); order.EventDate = new DateTime(2014, 02, 05); order.GuidePrice = 44; order.IsUrgent = true; order.IssueDate = new DateTime(2013, 05, 04); order.IssuerID = Guid.NewGuid(); order.ManagerID = Guid.NewGuid(); order.Notes = "Notes"; order.Number = "Number" + Guid.NewGuid(); order.Options = "Options"; order.OrderKindID = Guid.NewGuid(); order.OrderStatusID = Guid.NewGuid(); order.PrePayment = 55; order.Recommendation = "Recommendation"; order.WarrantyTo = new DateTime(2017, 01, 2); var workItem = new WorkItemDTO(); workItem.WorkItemID = Guid.NewGuid(); workItem.EventDate = new DateTime(2015, 10, 7); workItem.Price = 55.66M; workItem.RepairOrderID = Guid.NewGuid(); workItem.UserID = Guid.NewGuid(); var deviceItem = new DeviceItemDTO(); deviceItem.DeviceItemID = Guid.NewGuid(); deviceItem.Count = 33; deviceItem.EventDate = new DateTime(2015, 01, 01); deviceItem.Price = 55.33M; deviceItem.RepairOrderID = Guid.NewGuid(); deviceItem.Title = "Title"; var timeLine = new OrderTimelineDTO(); timeLine.EventDateTime = new DateTime(2015, 06, 07, 01, 2, 3); timeLine.OrderTimelineID = Guid.NewGuid(); timeLine.RepairOrderID = Guid.NewGuid(); timeLine.TimelineKindID = 1; timeLine.Title = "Title"; order.WorkItems.Add(workItem); order.OrderTimelines.Add(timeLine); order.DeviceItems.Add(deviceItem); message.RepairOrders.Add(order); var serializer = new ProtocolSerializer(ProtocolVersion.Version10); var data = serializer.Serialize(message); Assert.IsNotNull(data); var savedMessage = serializer.DeserializeGetRepairOrdersResponse(data); Assert.IsNotNull(savedMessage); Assert.AreEqual(serializer.GetMessageInfoOrNull(data).Kind, MessageKind.GetRepairOrdersResponse); Assert.AreEqual(savedMessage.RepairOrders.Count, 1); Assert.AreEqual(savedMessage.RepairOrders[0].DeviceItems.Count, 1); Assert.AreEqual(savedMessage.RepairOrders[0].WorkItems.Count, 1); Assert.AreEqual(savedMessage.RepairOrders[0].OrderTimelines.Count, 1); var savedDeviceItem = savedMessage.RepairOrders[0].DeviceItems[0]; var savedWorkItem = savedMessage.RepairOrders[0].WorkItems[0]; var savedTimeline = savedMessage.RepairOrders[0].OrderTimelines[0]; var savedItem = savedMessage.RepairOrders[0]; Assert.AreEqual(order.BranchID, savedItem.BranchID); Assert.AreEqual(order.CallEventDate, savedItem.CallEventDate); Assert.AreEqual(order.ClientAddress, savedItem.ClientAddress); Assert.AreEqual(order.ClientEmail, savedItem.ClientEmail); Assert.AreEqual(order.ClientFullName, savedItem.ClientFullName); Assert.AreEqual(order.ClientPhone, savedItem.ClientPhone); Assert.AreEqual(order.DateOfBeReady, savedItem.DateOfBeReady); Assert.AreEqual(order.Defect, savedItem.Defect); Assert.AreEqual(order.DeviceAppearance, savedItem.DeviceAppearance); Assert.AreEqual(order.DeviceModel, savedItem.DeviceModel); Assert.AreEqual(order.DeviceSN, savedItem.DeviceSN); Assert.AreEqual(order.DeviceTitle, savedItem.DeviceTitle); Assert.AreEqual(order.DeviceTrademark, savedItem.DeviceTrademark); Assert.AreEqual(order.EngineerID, savedItem.EngineerID); Assert.AreEqual(order.EventDate, savedItem.EventDate); Assert.AreEqual(order.GuidePrice, savedItem.GuidePrice); Assert.AreEqual(order.IsUrgent, savedItem.IsUrgent); Assert.AreEqual(order.IssueDate, savedItem.IssueDate); Assert.AreEqual(order.IssuerID, savedItem.IssuerID); Assert.AreEqual(order.ManagerID, savedItem.ManagerID); Assert.AreEqual(order.Notes, savedItem.Notes); Assert.AreEqual(order.Number, savedItem.Number); Assert.AreEqual(order.Options, savedItem.Options); Assert.AreEqual(order.OrderKindID, savedItem.OrderKindID); Assert.AreEqual(order.OrderStatusID, savedItem.OrderStatusID); Assert.AreEqual(order.PrePayment, savedItem.PrePayment); Assert.AreEqual(order.Recommendation, savedItem.Recommendation); Assert.AreEqual(order.WarrantyTo, savedItem.WarrantyTo); Assert.AreEqual(deviceItem.DeviceItemID, savedDeviceItem.DeviceItemID); Assert.AreEqual(deviceItem.CostPrice, savedDeviceItem.CostPrice); Assert.AreEqual(deviceItem.EventDate, savedDeviceItem.EventDate); Assert.AreEqual(deviceItem.Price, savedDeviceItem.Price); Assert.AreEqual(deviceItem.RepairOrderID, savedDeviceItem.RepairOrderID); Assert.AreEqual(deviceItem.Title, savedDeviceItem.Title); Assert.AreEqual(deviceItem.UserID, savedDeviceItem.UserID); Assert.AreEqual(deviceItem.WarehouseItemID, savedDeviceItem.WarehouseItemID); Assert.AreEqual(savedWorkItem.EventDate, workItem.EventDate); Assert.AreEqual(savedWorkItem.Price, workItem.Price); Assert.AreEqual(savedWorkItem.RepairOrderID, workItem.RepairOrderID); Assert.AreEqual(savedWorkItem.Title, workItem.Title); Assert.AreEqual(savedWorkItem.UserID, workItem.UserID); Assert.AreEqual(savedWorkItem.WorkItemID, workItem.WorkItemID); Assert.AreEqual(savedTimeline.EventDateTime, timeLine.EventDateTime); Assert.AreEqual(savedTimeline.OrderTimelineID, timeLine.OrderTimelineID); Assert.AreEqual(savedTimeline.RepairOrderID, timeLine.RepairOrderID); Assert.AreEqual(savedTimeline.TimelineKindID, timeLine.TimelineKindID); Assert.AreEqual(savedTimeline.Title, timeLine.Title); }
/// <summary> /// Обработчик запроса на получение заказов. /// </summary> /// <param name="serializer">Сериализатор протокола.</param> /// <param name="postData">Данные запроса.</param> /// <param name="hostAddress">Адрес клиента.</param> /// <returns>Результат.</returns> private string ProcessGetRepairOrdersRequest(ProtocolSerializer serializer, string postData, string hostAddress) { var request = serializer.DeserializeGetRepairOrdersRequest(postData); _logger.InfoFormat( "Получен запрос на получение информации по заказам от пользователя {0} с клиента {1}", request.UserID, hostAddress); var userDomainID = CheckSignedMessage(request); var response = new GetRepairOrdersResponse(); foreach (var repairOrderId in request.RepairOrderIds) { var repairOrder = RemontinkaServer.Instance.DataStore.GetRepairOrderLight(repairOrderId, userDomainID); if (repairOrder != null) { var orderDto = new Protocol.SynchronizationMessages.RepairOrderDTO { BranchID = repairOrder.BranchID, CallEventDate = repairOrder.CallEventDate, ClientAddress = repairOrder.ClientAddress, ClientEmail = repairOrder.ClientEmail, EventDate = repairOrder.EventDate, Number = repairOrder.Number, RepairOrderID = repairOrder.RepairOrderID, OrderKindID = repairOrder.OrderKindID, OrderStatusID = repairOrder.OrderStatusID, DeviceSN = repairOrder.DeviceSN, DeviceTitle = repairOrder.DeviceTitle, ClientFullName = repairOrder.ClientFullName, ClientPhone = repairOrder.ClientPhone, DateOfBeReady = repairOrder.DateOfBeReady, Defect = repairOrder.Defect, DeviceAppearance = repairOrder.DeviceAppearance, DeviceModel = repairOrder.DeviceModel, DeviceTrademark = repairOrder.DeviceTrademark, EngineerID = repairOrder.EngineerID, GuidePrice = repairOrder.GuidePrice, IsUrgent = repairOrder.IsUrgent, IssueDate = repairOrder.IssueDate, IssuerID = repairOrder.IssuerID, ManagerID = repairOrder.ManagerID, Notes = repairOrder.Notes, Options = repairOrder.Options, PrePayment = repairOrder.PrePayment, Recommendation = repairOrder.Recommendation, WarrantyTo = repairOrder.WarrantyTo }; response.RepairOrders.Add(orderDto); var workItems = RemontinkaServer.Instance.DataStore.GetWorkItems(repairOrderId); foreach (var item in workItems) { orderDto.WorkItems.Add(new Protocol.SynchronizationMessages.WorkItemDTO { EventDate = item.EventDate, Price = item.Price, RepairOrderID = item.RepairOrderID, Title = item.Title, UserID = item.UserID, WorkItemID = item.WorkItemID }); } //foreach var deviceItems = RemontinkaServer.Instance.DataStore.GetDeviceItems(repairOrderId); foreach (var item in deviceItems) { orderDto.DeviceItems.Add(new Protocol.SynchronizationMessages.DeviceItemDTO { EventDate = item.EventDate, Price = item.Price, RepairOrderID = item.RepairOrderID, Title = item.Title, UserID = item.UserID, CostPrice = item.CostPrice, Count = item.Count, DeviceItemID = item.DeviceItemID, WarehouseItemID = item.WarehouseItemID }); } //foreach var orderLines = RemontinkaServer.Instance.DataStore.GetOrderTimelines(repairOrderId); foreach (var item in orderLines) { orderDto.OrderTimelines.Add(new OrderTimelineDTO { RepairOrderID = item.RepairOrderID, Title = item.Title, EventDateTime = item.EventDateTime, OrderTimelineID = item.OrderTimelineID, TimelineKindID = item.TimelineKindID }); } //foreach } //if } //foreach return(serializer.Serialize(response)); }