public void ConfirmCollect_Valid()
        {
            // Arrange
            var expected   = new StatusService(context).FindStatusByStatusId(10);
            var controller = new DisbursementAPIController()
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration(),
                Context       = context,
            };

            // Act
            IHttpActionResult actionResult = controller.ConfirmCollection(new DisbursementIdViewModel()
            {
                DisbursementId = "DAPICONTROLTEST",
            });
            var contentResult = actionResult as OkNegotiatedContentResult <MessageViewModel>;

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(contentResult.Content.Message, "Collection confirmed");
            var result = new DisbursementRepository(context).FindById("DAPICONTROLTEST");

            Assert.AreEqual(expected.Name, result.Status.Name);
        }
 public DisbursementController()
 {
     context                = new ApplicationDbContext();
     disbursementService    = new DisbursementService(context);
     disbursementRepository = new DisbursementRepository(context);
     itemService            = new ItemService(context);
 }
Beispiel #3
0
 public void TestInitialize()
 {
     // Arrange
     context = new ApplicationDbContext();
     disbursementRepository       = new DisbursementRepository(context);
     disbursementDetailRepository = new DisbursementDetailRepository(context);
 }
 public DisbursementApiControllerTest()
 {
     context = new ApplicationDbContext();
     requisitionRepository  = new RequisitionRepository(context);
     retrievalRepository    = new RetrievalRepository(context);
     disbursementRepository = new DisbursementRepository(context);
     departmentRepository   = new DepartmentRepository(context);
 }
        public void TestInitialize()
        {
            context = new ApplicationDbContext();

            retrievalService    = new RetrievalService(context);
            itemService         = new ItemService(context);
            disbursementService = new DisbursementService(context);

            retrievalRepository          = new RetrievalRepository(context);
            disbursementRepository       = new DisbursementRepository(context);
            disbursementdetailRepository = new DisbursementDetailRepository(context);
            stockmovementRepository      = new StockMovementRepository(context);
            statusRepository             = new StatusRepository(context);

            Retrieval retrieval = new Retrieval();

            if (retrievalRepository.FindById("TEST") == null)
            {
                //save retrieval object into db

                retrieval.RetrievalId     = "TEST";
                retrieval.CreatedDateTime = DateTime.Now;
                retrievalRepository.Save(retrieval);
                retrieval.Status = statusRepository.FindById(19);
            }
            else
            {
                retrieval = retrievalRepository.FindById("TEST");
            }

            Disbursement disbursement = new Disbursement();

            if (disbursementRepository.FindById("TEST") == null)
            {
                disbursement.DisbursementId  = "TEST";
                disbursement.CreatedDateTime = DateTime.Now;
                disbursement.Retrieval       = retrieval;
            }
            else
            {
                disbursement = disbursementRepository.FindById("TEST");
            }

            disbursementRepository.Save(disbursement);

            //save disbursement detail object into db
            DisbursementDetail detail = new DisbursementDetail()
            {
                Disbursement   = disbursement,
                Item           = context.Item.Where(x => x.ItemCode == "C003").First(),
                PlanQuantity   = 5,
                ActualQuantity = 5
            };

            disbursementdetailRepository.Save(detail);
        }
Beispiel #6
0
 public RetrievalApiControllerTests()
 {
     context                = new ApplicationDbContext();
     retrievalController    = new RetrievalController();
     departmentService      = new DepartmentService(context);
     retrievalRepository    = new RetrievalRepository(context);
     disbursementRepository = new DisbursementRepository(context);
     ItemRepository         = new ItemRepository(context);
     disbursementRepository = new DisbursementRepository(context);
 }
Beispiel #7
0
 public DisbursementService(ApplicationDbContext context)
 {
     this.context                 = context;
     disbursementRepository       = new DisbursementRepository(context);
     disbursementDetailRepository = new DisbursementDetailRepository(context);
     itemService           = new ItemService(context);
     stockMovementService  = new StockMovementService(context);
     statusService         = new StatusService(context);
     requisitionRepository = new RequisitionRepository(context);
 }
Beispiel #8
0
        public RetrievalService(ApplicationDbContext context)
        {
            this.context           = context;
            retrievalRepository    = new RetrievalRepository(context);
            statusRepository       = new StatusRepository(context);
            disbursementRepository = new DisbursementRepository(context);

            itemService          = new ItemService(context);
            stockmovementService = new StockMovementService(context);
            disbursementService  = new DisbursementService(context);
        }
        public void TestCleanup()
        {
            // Delete DeliveryOrders
            var deliveryOrderRepository = new DeliveryOrderRepository(context);

            if (deliveryOrderRepository.FindAll().Where(x => x.InvoiceFileName == "IDSERVICETEST").Count() > 0)
            {
                deliveryOrderRepository.FindAll().Where(x => x.InvoiceFileName == "IDSERVICETEST").ToList().ForEach(x => deliveryOrderRepository.Delete(x));
            }

            // Delete Disbursements
            var disbursementRepository = new DisbursementRepository(context);

            if (disbursementRepository.FindAll().Where(x => x.Remarks == "IDSERVICETEST").Count() > 0)
            {
                disbursementRepository.FindAll().Where(x => x.Remarks == "IDSERVICETEST").ToList().ForEach(x => disbursementRepository.Delete(x));
            }

            // Delete Purchase Orders
            var purchaseOrderRepository = new PurchaseOrderRepository(context);

            if (purchaseOrderRepository.FindAll().Where(x => x.Status.StatusId == 16).Count() > 0)
            {
                purchaseOrderRepository.FindAll().Where(x => x.Status.StatusId == 16).ToList().ForEach(x => purchaseOrderRepository.Delete(x));
            }

            // Delete Requisitions
            var requisitionRepository = new RequisitionRepository(context);

            if (requisitionRepository.FindAll().Where(x => x.EmployeeRemarks == "IDSERVICETEST").Count() > 0)
            {
                requisitionRepository.FindAll().Where(x => x.EmployeeRemarks == "IDSERVICETEST").ToList().ForEach(x => requisitionRepository.Delete(x));
            }

            // Delete Retrievals
            var retrievalRepository = new RetrievalRepository(context);

            if (retrievalRepository.FindAll().Where(x => x.Status.StatusId == 16).Count() > 0)
            {
                retrievalRepository.FindAll().Where(x => x.Status.StatusId == 16).ToList().ForEach(x => retrievalRepository.Delete(x));
            }

            // Delete StockAdjustments
            var stockAdjustmentRepository = new StockAdjustmentRepository(context);

            if (stockAdjustmentRepository.FindAll().Where(x => x.Remarks == "IDSERVICETEST").Count() > 0)
            {
                stockAdjustmentRepository.FindAll().Where(x => x.Remarks == "IDSERVICETEST").ToList().ForEach(x => stockAdjustmentRepository.Delete(x));
            }
        }
Beispiel #10
0
        public static string GetNewDisbursementId(ApplicationDbContext context)
        {
            string prefix   = "DSB";
            int    serialNo = new DisbursementRepository(context)
                              .FindByCreatedDateTime(DateTime.Now.Date.AddDays(1 - DateTime.Now.Date.Day), DateTime.Now.Date.AddDays(1))
                              .Where(x => x.DisbursementId.Length == 14)
                              .Count() > 0 ?
                              new DisbursementRepository(context)
                              .FindByCreatedDateTime(DateTime.Now.Date.AddDays(1 - DateTime.Now.Date.Day), DateTime.Now.Date.AddDays(1))
                              .Where(x => x.DisbursementId.Length == 14)
                              .AsEnumerable()
                              .Select(x => Int32.Parse(x.DisbursementId.Substring(x.DisbursementId.Length - 3)))
                              .OrderByDescending(x => x)
                              .FirstOrDefault() + 1 : 1;

            return($"{prefix}-{DateTime.Now.Year}{DateTime.Now.Month:00}-{serialNo:000}");
        }
Beispiel #11
0
        public void TestCleanup()
        {
            var disbursementRepository = new DisbursementRepository(context);
            var retrievalRepository    = new RetrievalRepository(context);
            var requisitionRepository  = new RequisitionRepository(context);

            if (requisitionRepository.ExistsById("RETCONTROLTEST"))
            {
                requisitionRepository.Delete(requisitionRepository.FindById("RETCONTROLTEST"));
            }
            if (disbursementRepository.ExistsById("RETCONTROLTEST"))
            {
                disbursementRepository.Delete(disbursementRepository.FindById("RETCONTROLTEST"));
            }
            if (retrievalRepository.ExistsById("RETCONTROLTEST"))
            {
                retrievalRepository.Delete(retrievalRepository.FindById("RETCONTROLTEST"));
            }
        }
        public void TestInitialize()
        {
            context = new ApplicationDbContext();
            notificationRepository = new NotificationRepository(context);
            notificationService    = new NotificationService(context);

            disbursementRepository = new DisbursementRepository(context);
            saRepository           = new StockAdjustmentRepository(context);
            requisitionRepository  = new RequisitionRepository(context);

            var retrieval = new RetrievalRepository(context).Save(new Retrieval()
            {
                RetrievalId     = "NOTIFICATIONTEST",
                CreatedDateTime = DateTime.Now,
            });

            //save new disbursement object into db
            Disbursement disbursement = new Disbursement();

            if (disbursementRepository.FindById("TEST") == null)
            {
                disbursement.Department          = new DepartmentRepository(context).FindById("ENGL");
                disbursement.DisbursementId      = "TEST";
                disbursement.CreatedDateTime     = DateTime.Now;
                disbursement.Retrieval           = retrieval;
                disbursement.DisbursementDetails = new List <DisbursementDetail>()
                {
                    new DisbursementDetail()
                    {
                        DisbursementId = "TEST",
                        Item           = new ItemService(context).FindItemByItemCode("E030"),
                        ActualQuantity = 20,
                    }
                };
            }
            else
            {
                disbursement = disbursementRepository.FindById("TEST");
            }
            disbursementRepository.Save(disbursement);

            //save new requisition object into db
            Requisition requisition = new Requisition();

            if (requisitionRepository.FindById("TEST") == null)
            {
                requisition.Department         = new DepartmentRepository(context).FindById("ENGL");
                requisition.RequisitionId      = "TEST";
                requisition.CreatedDateTime    = DateTime.Now;
                requisition.Retrieval          = retrieval;
                requisition.RequisitionDetails = new List <RequisitionDetail>()
                {
                    new RequisitionDetail()
                    {
                        RequisitionId = "TEST",
                        Item          = new ItemService(context).FindItemByItemCode("E030"),
                        Status        = new StatusService(context).FindStatusByStatusId(8),
                    }
                };
            }
            else
            {
                requisition = requisitionRepository.FindById("TEST");
            }
            requisitionRepository.Save(requisition);

            //create new SA object and save into db
            StockAdjustment SA = new StockAdjustment();

            if (saRepository.FindById("TEST") == null)
            {
                SA.StockAdjustmentId = "TEST";
                SA.CreatedDateTime   = DateTime.Now;
            }
            else
            {
                SA = saRepository.FindById("TEST");
            }
            saRepository.Save(SA);
        }
Beispiel #13
0
        public void UpdateRetrievalFormTest()
        {
            // ARRANGE
            RetrievalAPIController retrievalAPIController = new RetrievalAPIController()
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration(),
                Context       = context,
            };

            string retId    = "RETRIEVAL";
            string deptId   = "COMM";
            string itemCode = "C001";
            string disbId   = "DISBURSEMENT";
            int    actual   = 99;

            Retrieval r = new Retrieval
            {
                RetrievalId     = retId,
                CreatedDateTime = DateTime.Now
            };
            Disbursement d = new Disbursement
            {
                DisbursementId      = disbId,
                Department          = departmentService.FindDepartmentByDepartmentCode(deptId),
                Retrieval           = r,
                CreatedDateTime     = DateTime.Now,
                DisbursementDetails = new List <DisbursementDetail>
                {
                    new DisbursementDetail
                    {
                        Item           = ItemRepository.FindById(itemCode),
                        PlanQuantity   = 99,
                        ActualQuantity = 0
                    }
                }
            };

            retrievalRepository.Save(r);
            disbursementRepository.Save(d);

            try
            {
                SaveJson json = new SaveJson
                {
                    ItemCode = itemCode,
                    RetId    = retId,
                    List     = new List <BreakdownByDepartment>
                    {
                        new BreakdownByDepartment
                        {
                            DeptId = deptId,
                            Actual = actual
                        }
                    }
                };

                // ACT
                retrievalAPIController.UpdateRetrievalForm(json);


                // ASSERT
                int expected = 99;

                DisbursementDetail dd;
                //using (context = new ApplicationDbContext())
                //{
                disbursementRepository = new DisbursementRepository(context);
                dd = disbursementRepository
                     .FindById(disbId)
                     .DisbursementDetails
                     .Where(x => x.ItemCode == itemCode).First();
                //}

                Assert.AreEqual(expected, dd.ActualQuantity);
            }
            finally
            {
                //using (context = new ApplicationDbContext())
                //{
                Disbursement deleteD = context.Disbursement.Where(x => x.DisbursementId == disbId).First();
                context.Disbursement.Remove(deleteD);

                Retrieval deleteR = context.Retrieval.Where(x => x.RetrievalId == retId).First();
                context.Retrieval.Remove(deleteR);
                context.SaveChanges();
                //}
            }
        }
        public void TestInitialize()
        {
            context = new ApplicationDbContext();

            stockmovementService = new StockMovementService(context);
            itemService          = new ItemService(context);

            stockmovementRepository = new StockMovementRepository(context);

            ddRepository           = new DisbursementDetailRepository(context);
            sadRepository          = new StockAdjustmentDetailRepository(context);
            dodRepository          = new DeliveryOrderDetailRepository(context);
            disbursementRepository = new DisbursementRepository(context);
            doRepository           = new DeliveryOrderRepository(context);
            saRepository           = new StockAdjustmentRepository(context);

            //create new test object and save into db
            StockMovement sm = new StockMovement()
            {
                StockMovementId   = IdService.GetNewStockMovementId(context),
                DisbursementId    = "TEST",
                StockAdjustmentId = "TEST",
                DeliveryOrderNo   = "TEST",
                Item             = context.Item.Where(x => x.ItemCode == "C003").First(),
                CreatedDateTime  = DateTime.Now,
                OriginalQuantity = 1,
                AfterQuantity    = 2
            };

            stockmovementRepository.Save(sm);

            //create new disbursement object and save into db
            Disbursement disbursement = new Disbursement();

            if (disbursementRepository.FindById("TEST") == null)
            {
                disbursement.DisbursementId  = "TEST";
                disbursement.CreatedDateTime = DateTime.Now;
            }
            else
            {
                disbursement = disbursementRepository.FindById("TEST");
            }
            disbursementRepository.Save(disbursement);

            //create new DisbursementDetail object and save into db
            DisbursementDetail detail = new DisbursementDetail()
            {
                DisbursementId = "TEST",
                Item           = context.Item.First(),
                PlanQuantity   = 3,
                ActualQuantity = 3
            };

            ddRepository.Save(detail);

            //create new DO object and save into db
            DeliveryOrder d = new DeliveryOrder();

            if (doRepository.FindById("TEST") == null)
            {
                d.DeliveryOrderNo = "TEST";
                d.CreatedDateTime = DateTime.Now;
            }
            else
            {
                d = doRepository.FindById("TEST");
            }
            doRepository.Save(d);

            //create new DO detail object and save into db
            DeliveryOrderDetail dod = new DeliveryOrderDetail()
            {
                DeliveryOrder  = d,
                Item           = context.Item.First(),
                PlanQuantity   = 4,
                ActualQuantity = 4
            };

            dodRepository.Save(dod);

            //create new SA object and save into db
            StockAdjustment SA = new StockAdjustment();

            if (saRepository.FindById("TEST") == null)
            {
                SA.StockAdjustmentId = "TEST";
                SA.CreatedDateTime   = DateTime.Now;
            }
            else
            {
                SA = saRepository.FindById("TEST");
            }
            saRepository.Save(SA);

            //create new SA detail object and save into db
            StockAdjustmentDetail SADetail = new StockAdjustmentDetail()
            {
                StockAdjustment  = SA,
                Item             = context.Item.First(),
                OriginalQuantity = 2,
                AfterQuantity    = 4
            };

            sadRepository.Save(SADetail);
        }
        public void TestInitialize()
        {
            context = new ApplicationDbContext();
            disbursementRepository       = new DisbursementRepository(context);
            disbursementdetailRepository = new DisbursementDetailRepository(context);
            disbursementService          = new DisbursementService(context);
            itemRepository              = new ItemRepository(context);
            retrievalRepository         = new RetrievalRepository(context);
            requisitionRepository       = new RequisitionRepository(context);
            requisitiondetailRepository = new RequisitionDetailRepository(context);
            departmentRepository        = new DepartmentRepository(context);

            Retrieval retrieval = new Retrieval();

            if (retrievalRepository.FindById("TEST") == null)
            {
                //save retrieval object into db

                retrieval.RetrievalId     = "TEST";
                retrieval.CreatedDateTime = DateTime.Now;
                retrievalRepository.Save(retrieval);
            }
            else
            {
                retrieval = retrievalRepository.FindById("TEST");
            }

            //save disbursement object into db

            Disbursement disbursement = new Disbursement();

            if (disbursementRepository.FindById("TEST") == null)
            {
                disbursement.DisbursementId  = "TEST";
                disbursement.CreatedDateTime = DateTime.Now;
                disbursement.Retrieval       = retrieval;
            }
            else
            {
                disbursement = disbursementRepository.FindById("TEST");
            }

            disbursementRepository.Save(disbursement);

            //save disbursement detail object into db
            DisbursementDetail detail = new DisbursementDetail()
            {
                Disbursement   = disbursement,
                Item           = context.Item.First(),
                PlanQuantity   = 20,
                ActualQuantity = 20
            };

            disbursementdetailRepository.Save(detail);

            Requisition requisition = new Requisition()
            {
                RequisitionId   = "TEST",
                Retrieval       = retrieval,
                CreatedDateTime = DateTime.Now,
                Status          = new StatusService(context).FindStatusByStatusId(8)
            };

            requisitionRepository.Save(requisition);
        }