internal IResult <ProductionSchedule> Update(DateTime timestamp, UpdateProductionScheduleParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(ProductionUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <ProductionSchedule>()); } var productionSchedule = ProductionUnitOfWork.ProductionScheduleRepository.FindByKey(parameters.ProductionScheduleKey, p => p.ProductionLineLocation, p => p.ScheduledItems); if (productionSchedule == null) { return(new InvalidResult <ProductionSchedule>(null, string.Format(UserMessages.ProductionScheduleNotFound, parameters.ProductionScheduleKey))); } var items = parameters.ScheduledItems.Select(i => new SetProductionScheduleItemParameters { Index = i.Parameters.Index, FlushBefore = i.Parameters.FlushBefore, FlushBeforeInstructions = i.Parameters.FlushBeforeInstructions, FlushAfter = i.Parameters.FlushAfter, FlushAfterInstructions = i.Parameters.FlushAfterInstructions, PackScheduleKey = i.PackScheduleKey }).ToList(); return(Set(productionSchedule, employeeResult.ResultingObject, timestamp, items)); }
public void Updates_ProductionSchedule_as_expected() { //Arrange var productionSchedule = TestHelper.CreateObjectGraphAndInsertIntoDatabase <ProductionSchedule>(p => p.ScheduledItems = TestHelper.List <ProductionScheduleItem>(3)); var parameters = new UpdateProductionScheduleParameters { UserToken = TestUser.UserName, ProductionScheduleKey = productionSchedule.ToProductionScheduleKey(), ScheduledItems = new List <ISetProductionScheduleItemParameters> { new SetProductionScheduleItemParameters { Index = 0, FlushBefore = true, FlushBeforeInstructions = "hi", PackScheduleKey = TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackSchedule>().ToPackScheduleKey() }, new SetProductionScheduleItemParameters { Index = 1, FlushAfter = true, FlushBeforeInstructions = "bye", PackScheduleKey = TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackSchedule>().ToPackScheduleKey() } } }; //Act var result = Service.UpdateProductionSchedule(parameters); productionSchedule = RVCUnitOfWork.ProductionScheduleRepository.FindByKey(productionSchedule.ToProductionScheduleKey(), p => p.ScheduledItems); //Assert result.AssertSuccess(); parameters.ScheduledItems.OrderBy(i => i.Index) .AssertEquivalent(productionSchedule.ScheduledItems.OrderBy(i => i.Index), (e, r) => { Assert.AreEqual(e.Index, r.Index); Assert.AreEqual(e.PackScheduleKey, r.ToPackScheduleKey().KeyValue); Assert.AreEqual(e.FlushAfter, r.FlushAfter); Assert.AreEqual(e.FlushAfterInstructions, r.FlushAfterInstructions); Assert.AreEqual(e.FlushBefore, r.FlushBefore); Assert.AreEqual(e.FlushBeforeInstructions, r.FlushBeforeInstructions); }); }