Пример #1
0
        public async Task ReturnsResponse()
        {
            // arrange
            var generatedWorkOrders = _generator.GenerateList(5);
            var expectedWorkOrder   = _generator.Generate();

            expectedWorkOrder.Id = 7;
            generatedWorkOrders.Add(expectedWorkOrder);
            var appointment = new AppointmentDetails
            {
                Date        = DateTime.UtcNow,
                Description = "test",
                End         = DateTime.UtcNow,
                Start       = DateTime.UtcNow
            };

            _repairsGatewayMock.ReturnsWorkOrders(generatedWorkOrders);
            _appointmentsGatewayMock.Setup(a => a.GetAppointment(It.IsAny <int>())).ReturnsAsync(appointment);
            var items             = MockTasks();
            var expectedTotalSMVs = items.Sum(i => i.StandardMinuteValue * i.Quantity);

            // act
            var response = await _classUnderTest.Execute(expectedWorkOrder.Id);

            // assert
            var expectedResponse = expectedWorkOrder.ToResponse(appointment, _drsOptions.ManagementAddress, true);

            expectedResponse.TotalSMVs = expectedTotalSMVs;
            response.Should().BeEquivalentTo(expectedResponse);
        }
        private IEnumerable <WorkOrder> CreateWorkOrders(int quantity = 5)
        {
            var generator = new Helpers.StubGeneration.Generator <WorkOrder>()
                            .AddWorkOrderGenerators()
                            .AddGenerator(() => _workOrderId++, (WorkOrder wo) => wo.Id);

            var workOrders = generator.GenerateList(quantity);

            _listWorkOrdersMock
            .Setup(m => m.Execute(It.IsAny <WorkOrderSearchParameters>()))
            .ReturnsAsync(workOrders);

            _repairsGatewayMock.Setup(x => x.GetWorkOrder(Moq.It.IsAny <int>()))
            .Returns((int reqId) => Task.FromResult(workOrders.Where(wo => wo.Id == reqId).First()));

            return(workOrders);
        }