public void ApproveStockAdjustment_Test() { StockAdjustment sa = new StockAdjustment(); sa.StockAdjustmentId = "test1"; sa.Remarks = "THIS IS A TEST"; sa.CreatedBy = new UserService(context).FindUserByEmail("*****@*****.**"); sa.CreatedDateTime = DateTime.Now; sa.Status = statusRepository.FindById(4); StockAdjustmentDetail sad = new StockAdjustmentDetail(); sad.StockAdjustmentId = "test1"; sad.Reason = "test1"; sad.ItemCode = "C001"; sad.Item = itemRepository.FindById("C001"); sad.OriginalQuantity = 0; sad.AfterQuantity = 10; List <StockAdjustmentDetail> detaillist = new List <StockAdjustmentDetail>(); detaillist.Add(sad); sa.StockAdjustmentDetails = detaillist; saRepository.Save(sa); //sadRepository.Save(sad); List <ViewModelFromEditDetail> list = new List <ViewModelFromEditDetail>(); ViewModelFromEditDetail v1 = new ViewModelFromEditDetail(); v1.StockAdjustmentID = "test1"; v1.Reason = "test1"; v1.Itemcode = "C001"; list.Add(v1); StockAdjustmentAPIController controller = new StockAdjustmentAPIController() { CurrentUserName = "******", Context = this.context }; controller.ApproveStockAdjustment(list); Assert.AreEqual(saRepository.FindById("test1").Status.StatusId, 6); saRepository.Delete(saRepository.FindById("test1")); StockMovement sv = context.StockMovement.OrderByDescending(x => x.StockMovementId).First(); smRepository.Delete(sv); }
public void ApproveStockAdjustment_Valid() { // Arrange var expected = new StatusService(context).FindStatusByStatusId(6); 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.ApproveStockAdjustment(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 approved"); var result = new StockAdjustmentRepository(context).FindById("ADJCONTROLTEST"); Assert.AreEqual(expected.Name, result.Status.Name); }
public void ApproveStockAdjustment_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.ApproveStockAdjustment(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 ApproveStockAdjustment_DoesNotExist_BadRequest() { // Arrange var controller = new StockAdjustmentAPIController() { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration(), Context = context, }; // Act IHttpActionResult actionResult = controller.ApproveStockAdjustment(new StockAdjustmentIdViewModel() { StockAdjustmentId = "ADJCONTROLTEST", Email = "*****@*****.**", }); var badRequestResult = actionResult as BadRequestErrorMessageResult; // Assert Assert.IsInstanceOfType(actionResult, typeof(BadRequestErrorMessageResult)); Assert.AreEqual("Stock Adjustment does not exist", badRequestResult.Message); }