public void TestInitialize() { // Arrange context = new ApplicationDbContext(); stockAdjustmentRepository = new StockAdjustmentRepository(context); stockAdjustmentDetailRepository = new StockAdjustmentDetailRepository(context); }
public void RejectStockAdjustmentMobile_Valid() { // Arrange var stockAdjustmentRepository = new StockAdjustmentRepository(context); var stockAdjustmentService = new StockAdjustmentService(context); var stockAdjustment = stockAdjustmentRepository.Save(new StockAdjustment() { StockAdjustmentId = "ADJAPPROVETEST", CreatedBy = new UserService(context).FindUserByEmail("*****@*****.**"), CreatedDateTime = DateTime.Now, Status = new StatusService(context).FindStatusByStatusId(4), StockAdjustmentDetails = new List <StockAdjustmentDetail>() { new StockAdjustmentDetail() { StockAdjustmentId = "ADJAPPROVETEST", ItemCode = "E030", Item = new ItemService(context).FindItemByItemCode("E030"), OriginalQuantity = 10, AfterQuantity = 10, } } }); // Act stockAdjustmentService.RejectStockAdjustment("ADJAPPROVETEST", "*****@*****.**"); // Assert Assert.AreEqual(5, stockAdjustment.Status.StatusId); Assert.IsTrue(new StockMovementRepository(context).FindByStockAdjustmentId("ADJAPPROVETEST").FirstOrDefault() == null); }
public void RejectStockAdjustmentMobile_AlreadyApproved_ThrowsException() { // Arrange var stockAdjustmentRepository = new StockAdjustmentRepository(context); var stockAdjustmentService = new StockAdjustmentService(context); var stockAdjustment = stockAdjustmentRepository.Save(new StockAdjustment() { StockAdjustmentId = "ADJAPPROVETEST", CreatedBy = new UserService(context).FindUserByEmail("*****@*****.**"), CreatedDateTime = DateTime.Now, Status = new StatusService(context).FindStatusByStatusId(6), StockAdjustmentDetails = new List <StockAdjustmentDetail>() { new StockAdjustmentDetail() { StockAdjustmentId = "ADJAPPROVETEST", ItemCode = "E030", Item = new ItemService(context).FindItemByItemCode("E030"), OriginalQuantity = 10, AfterQuantity = 10, } } }); // Act stockAdjustmentService.RejectStockAdjustment("ADJAPPROVETEST", "*****@*****.**"); }
public void TestInitialize() { context = new ApplicationDbContext(); statusRepository = new StatusRepository(context); saRepository = new StockAdjustmentRepository(context); userRepository = new UserRepository(context); //Create a draft stockadjustment StockAdjustment sa1 = new StockAdjustment(); sa1.StockAdjustmentId = "he01"; sa1.CreatedDateTime = DateTime.Now; sa1.Status = statusRepository.FindById(3); sa1.CreatedBy = userRepository.FindByEmail("*****@*****.**"); sa1.ApprovedBySupervisor = userRepository.FindByEmail("*****@*****.**"); StockAdjustmentDetail s1 = new StockAdjustmentDetail(); s1.StockAdjustmentId = "he01"; s1.ItemCode = "C002"; s1.OriginalQuantity = 10; s1.AfterQuantity = 20; StockAdjustmentDetail s2 = new StockAdjustmentDetail(); s2.StockAdjustmentId = "he01"; s2.ItemCode = "C003"; s2.OriginalQuantity = 20; s2.AfterQuantity = 30; List <StockAdjustmentDetail> list = new List <StockAdjustmentDetail>(); list.Add(s1); list.Add(s2); sa1.StockAdjustmentDetails = list; saRepository.Save(sa1); }
public StockAdjustmentService(ApplicationDbContext context) { this.context = context; this.statusRepository = new StatusRepository(context); this.stockAdjustmentRepository = new StockAdjustmentRepository(context); this.stockAdjustmentDetailRepository = new StockAdjustmentDetailRepository(context); this.itemService = new ItemService(context); this.inventoryRepository = new InventoryRepository(context); this.stockMovementRepository = new StockMovementRepository(context); this.stockMovementService = new StockMovementService(context); }
public void TestInitialize() { context = new ApplicationDbContext(); saService = new StockAdjustmentService(context); saRepository = new StockAdjustmentRepository(context); sadRepository = new StockAdjustmentDetailRepository(context); statusRepository = new StatusRepository(context); itemRepository = new ItemRepository(context); smRepository = new StockMovementRepository(context); userService = new UserService(context); }
public void TestCleanUp() { var stockAdjustmentRepository = new StockAdjustmentRepository(context); if (saService.FindAllStockAdjustment().Where(x => x.Remarks == "THIS IS A TEST").FirstOrDefault() != null) { saRepository.Delete(saService.FindAllStockAdjustment().Where(x => x.Remarks == "THIS IS A TEST").FirstOrDefault()); } if (stockAdjustmentRepository.ExistsById("ADJCONTROLTEST")) { stockAdjustmentRepository.Delete(stockAdjustmentRepository.FindById("ADJCONTROLTEST")); } }
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)); } }
public static string GetNewStockAdjustmentId(ApplicationDbContext context) { string prefix = "ADJ"; int serialNo = new StockAdjustmentRepository(context) .FindByCreatedDateTime(DateTime.Now.Date.AddDays(1 - DateTime.Now.Date.Day), DateTime.Now.Date.AddDays(1)) .Where(x => x.StockAdjustmentId.Length == 14) .Count() > 0 ? new StockAdjustmentRepository(context) .FindByCreatedDateTime(DateTime.Now.Date.AddDays(1 - DateTime.Now.Date.Day), DateTime.Now.Date.AddDays(1)) .Where(x => x.StockAdjustmentId.Length == 14) .AsEnumerable() .Select(x => Int32.Parse(x.StockAdjustmentId.Substring(x.StockAdjustmentId.Length - 3))) .OrderByDescending(x => x) .FirstOrDefault() + 1 : 1; return($"{prefix}-{DateTime.Now.Year}{DateTime.Now.Month:00}-{serialNo:000}"); }
public void RejectStockAdjustment_Valid() { // Arrange var expected = new StatusService(context).FindStatusByStatusId(5); var controller = new StockAdjustmentAPIController() { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration(), Context = context, }; var stockAdjustment = new StockAdjustmentRepository(context).Save(new StockAdjustment() { StockAdjustmentId = "ADJCONTROLTEST", CreatedBy = new UserService(context).FindUserByEmail("*****@*****.**"), CreatedDateTime = DateTime.Now, Status = new StatusService(context).FindStatusByStatusId(4), StockAdjustmentDetails = new List <StockAdjustmentDetail>() { new StockAdjustmentDetail() { StockAdjustmentId = "ADJCONTROLTEST", ItemCode = "E030", Item = new ItemService(context).FindItemByItemCode("E030"), OriginalQuantity = 10, AfterQuantity = 10, } } }); // Act IHttpActionResult actionResult = controller.RejectStockAdjustment(new StockAdjustmentIdViewModel() { StockAdjustmentId = "ADJCONTROLTEST", Email = "*****@*****.**", }); var contentResult = actionResult as OkNegotiatedContentResult <MessageViewModel>; // Assert Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.AreEqual(contentResult.Content.Message, "Successfully rejected"); var result = new StockAdjustmentRepository(context).FindById("ADJCONTROLTEST"); Assert.AreEqual(expected.Name, result.Status.Name); }
public void TestInitialize() { // Arrange context = new ApplicationDbContext(); stockAdjustmentRepository = new StockAdjustmentRepository(context); stockAdjustmentDetailRepository = new StockAdjustmentDetailRepository(context); service = new StockAdjustmentService(context); itemRepository = new ItemRepository(context); inventoryRepository = new InventoryRepository(context); itemService = new ItemService(context); this.stockMovementRepository = new StockMovementRepository(context); //save new item object into db Item item = new Item(); item.ItemCode = "he06"; item.CreatedDateTime = DateTime.Now; itemRepository.Save(item); itemService.SaveInventory(item, 40); }
public void RejectStockAdjustment_AlreadyApproved_BadRequest() { // Arrange var controller = new StockAdjustmentAPIController() { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration(), Context = context, }; var stockAdjustment = new StockAdjustmentRepository(context).Save(new StockAdjustment() { StockAdjustmentId = "ADJCONTROLTEST", CreatedBy = new UserService(context).FindUserByEmail("*****@*****.**"), CreatedDateTime = DateTime.Now, Status = new StatusService(context).FindStatusByStatusId(6), StockAdjustmentDetails = new List <StockAdjustmentDetail>() { new StockAdjustmentDetail() { StockAdjustmentId = "ADJCONTROLTEST", ItemCode = "E030", Item = new ItemService(context).FindItemByItemCode("E030"), OriginalQuantity = 10, AfterQuantity = 10, } } }); // Act IHttpActionResult actionResult = controller.RejectStockAdjustment(new StockAdjustmentIdViewModel() { StockAdjustmentId = "ADJCONTROLTEST", Email = "*****@*****.**", }); var badRequestResult = actionResult as BadRequestErrorMessageResult; // Assert Assert.IsInstanceOfType(actionResult, typeof(BadRequestErrorMessageResult)); Assert.AreEqual("Stock Adjustment already approved/rejected", badRequestResult.Message); }
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); }
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); }