Пример #1
0
        public void ProcessRequisitionsTest_CreatesRetrieval()
        {
            // Arrange
            List <Requisition> reqList = new List <Requisition>();

            reqList.Add(context.Requisition.Where(x => x.RequisitionId == "GAB1").ToList().First());
            reqList.Add(context.Requisition.Where(x => x.RequisitionId == "GAB2").ToList().First());
            reqList.Add(context.Requisition.Where(x => x.RequisitionId == "GAB3").ToList().First());

            // Act
            string retrievalId = requisitionService.ProcessRequisitions(reqList);

            // Assert - the Retrieval ID that ProcessRequisitions returns should return a Requisition
            Retrieval result = context.Retrieval.Where(x => x.RetrievalId == retrievalId).ToList().First();

            Assert.IsNotNull(result);

            // Cleanup
            var disb = context.Disbursement.Where(x => x.Retrieval.RetrievalId == result.RetrievalId).AsEnumerable();

            context.Disbursement.RemoveRange(disb);

            context.Retrieval.Remove(result);
            context.SaveChanges();
        }
Пример #2
0
        public IHttpActionResult ProcessRequisitions(List <string> reqIdList)
        {
            List <Requisition> reqList = new List <Requisition>();
            string             rid;
            List <string>      errorList = new List <string>();

            try
            {
                foreach (string s in reqIdList)
                {
                    Requisition req = requisitionRepository.FindById(s);
                    if (req.Status.StatusId == 6)
                    {
                        reqList.Add(req);
                    }
                    else
                    {
                        errorList.Add(req.RequisitionId);
                    }
                }

                // create retrieval only if there are Requisitions to be processed
                if (reqList.Count > 0)
                {
                    rid = requisitionService.ProcessRequisitions(reqList);
                }
                else
                {
                    throw new Exception("No Requisitions could be processed.");
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
            return(Ok(new { rid, count = reqList.Count }));
        }