public void SaveWorkOrder_updates_timestamp() { // //Arrange _repo = new Mock <IWorkOrderRepository>(); _uow = new Mock <IUnitOfWork>(); _lRepo = new Mock <ILookupRepository>(); _cfg = new Mock <IConfigService>(); Lookup _l = (Lookup)Records.lookup.Clone(); _lRepo.Setup(r => r.GetById(It.IsAny <int>())).Returns(_l); string user = "******"; var _wo = (WorkOrder)Records.order.Clone(); _wo.datecreated = DateTime.MinValue; _wo.dateupdated = DateTime.MinValue; _waServ = new Mock <IWorkAssignmentService>(); _tpServ = new Mock <ITransportProvidersService>(); var _tp = (TransportProvider)Records.transportProvider.Clone(); _tpServ.Setup(r => r.Get(It.IsAny <int>())).Returns(_tp); var _serv = new WorkOrderService(_repo.Object, _waServ.Object, _tpServ.Object, _lRepo.Object, _uow.Object, _map.Object, _cfg.Object); // //Act _serv.Save(_wo, user); // //Assert Assert.IsTrue(_wo.updatedby == user); Assert.IsTrue(_wo.dateupdated > DateTime.MinValue); }
public void SaveWorkOrder_updates_timestamp() { // //Arrange _repo = new Mock<IWorkOrderRepository>(); _uow = new Mock<IUnitOfWork>(); string user = "******"; var _wo = (WorkOrder)Records.order.Clone(); _wo.datecreated = DateTime.MinValue; _wo.dateupdated = DateTime.MinValue; _waServ = new Mock<IWorkAssignmentService>(); var _serv = new WorkOrderService(_repo.Object, _waServ.Object, _uow.Object); // //Act _serv.Save(_wo, user); // //Assert Assert.IsTrue(_wo.Updatedby == user); Assert.IsTrue(_wo.dateupdated > DateTime.MinValue); }
public void SaveWorkOrder_finds_duplicate_workrequests() { // //Arrange // Lookups are called for updateComputedValues Lookup _l = (Lookup)Records.lookup.Clone(); TransportProvider _tp = (TransportProvider)Records.transportProvider.Clone(); _lRepo.Setup(r => r.GetById(It.IsAny <int>())).Returns(_l); int testid = 4242; WorkOrder fakeworkOrder = new WorkOrder(); var workerRequest = new List <WorkerRequest> { }; fakeworkOrder.workerRequests = workerRequest; fakeworkOrder.ID = testid; WorkerRequest wr1 = new WorkerRequest { ID = 111, WorkerID = 1, WorkOrderID = testid, workerRequested = new Worker { ID = 1, dwccardnum = 12345 } }; WorkerRequest wr2 = new WorkerRequest { ID = 222, WorkerID = 2, WorkOrderID = testid, workerRequested = new Worker { ID = 2, dwccardnum = 12346 } }; workerRequest.Add(wr1); workerRequest.Add(wr2); // receives WO passed to repository WorkOrder savedworkOrder = new WorkOrder(); List <WorkerRequest> list = new List <WorkerRequest>(); list.Add(new WorkerRequest { WorkerID = 12345 }); list.Add(new WorkerRequest { WorkerID = 30002 }); list.Add(new WorkerRequest { WorkerID = 30311 }); list.Add(new WorkerRequest { WorkerID = 30420 }); list.Add(new WorkerRequest { WorkerID = 30421 }); string user = ""; _repo.Setup(r => r.GetById(testid)).Returns(fakeworkOrder); _wrServ.Setup(x => x.GetByWorkerID(testid, 1)).Returns(wr1); _wrServ.Setup(x => x.GetByWorkerID(testid, 2)).Returns(wr2); _wrServ.Setup(x => x.Delete(It.IsAny <int>(), It.IsAny <string>())); _tpServ.Setup(x => x.Get(It.IsAny <int>())).Returns(_tp); _tpServ.Setup(x => x.Get(It.IsAny <int>())).Returns(_tp); // //Act _serv.Save(fakeworkOrder, list, user); // //Assert //Assert.AreEqual(fakeworkOrder, savedworkOrder); Assert.AreEqual(fakeworkOrder.workerRequests.Count(), 5); Assert.AreEqual(fakeworkOrder.workerRequests.Count(a => a.WorkerID == 12345), 1); Assert.AreEqual(fakeworkOrder.workerRequests.Count(a => a.WorkerID == 30002), 1); Assert.AreEqual(fakeworkOrder.workerRequests.Count(a => a.WorkerID == 30311), 1); Assert.AreEqual(fakeworkOrder.workerRequests.Count(a => a.WorkerID == 30420), 1); Assert.AreEqual(fakeworkOrder.workerRequests.Count(a => a.WorkerID == 30421), 1); Assert.AreEqual(fakeworkOrder.workerRequests.Count(a => a.WorkerID == 12346), 0); }