예제 #1
0
        //Delete one item if StockAdjustment in Draft Status
        public string DeleteItemFromDraftOrPendingStockAdjustment(string stockadjustment_id, string itemcode)
        {
            //controller pass stockadjustmentid and itemcode to the method
            StockAdjustment       s1 = stockAdjustmentRepository.FindById(stockadjustment_id);
            StockAdjustmentDetail s  = stockAdjustmentDetailRepository.FindById(stockadjustment_id, itemcode);

            if (stockAdjustmentRepository.FindById(stockadjustment_id) == null)
            {
                throw new Exception("can't find StockAdjustment");
            }
            else if (stockAdjustmentDetailRepository.FindById(stockadjustment_id, itemcode) == null)
            {
                throw new Exception("can't find stockAdjustmentDetail");
            }

            if (s1.Status.StatusId == 3 || s1.Status.StatusId == 4)
            {
                //remove one StockAdjustmentDetail in List<StockAdjustmentDetail>
                s1.StockAdjustmentDetails.Remove(s);
                //delete one stockadjustmentdetail
                stockAdjustmentDetailRepository.Delete(s);
                stockAdjustmentRepository.Save(s1);
            }
            return(itemcode);
        }
        public void UpdateStockAdjustmentAsDraft_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(3);

            StockAdjustmentDetail sad = new StockAdjustmentDetail();

            sad.StockAdjustmentId = "test1";
            sad.Reason            = "test1";
            sad.ItemCode          = "C001";

            List <StockAdjustmentDetail> detaillist = new List <StockAdjustmentDetail>();

            detaillist.Add(sad);

            sa.StockAdjustmentDetails = detaillist;
            saRepository.Save(sa);

            List <ViewModelFromEditDetail> list = new List <ViewModelFromEditDetail>();
            ViewModelFromEditDetail        v1   = new ViewModelFromEditDetail();

            v1.StockAdjustmentID = "test1";
            v1.Reason            = "test2";
            v1.Itemcode          = "C001";
            v1.Adjustment        = 10;
            list.Add(v1);

            StockAdjustmentAPIController controller = new StockAdjustmentAPIController()
            {
                CurrentUserName = "******",
                Context         = this.context
            };

            controller.UpdateStockAdjustmentAsDraft(list);

            Assert.AreEqual(sadRepository.FindById("test1", "C001").Reason, "test2");

            saRepository.Delete(saRepository.FindById("test1"));
        }
예제 #3
0
        public void FindByIdTestNotNull()
        {
            // Arrange
            var expected = new StockAdjustmentDetail()
            {
                StockAdjustmentId = "SADREPOTEST",
                ItemCode          = "E030",
            };

            stockAdjustmentRepository.Save(new StockAdjustment()
            {
                StockAdjustmentId = "SADREPOTEST",
                CreatedDateTime   = DateTime.Now,
            });
            stockAdjustmentDetailRepository.Save(expected);

            // Act
            var result = stockAdjustmentDetailRepository.FindById("SADREPOTEST", "E030");

            // Assert
            Assert.IsInstanceOfType(result, typeof(StockAdjustmentDetail));
        }
        public void DeleteItemFromDraftOrPendingStockAdjustmentTest()
        {
            //Arrange
            Random          rd     = new Random();
            int             i      = rd.Next();
            string          id     = "he02";
            StockAdjustment expect = new StockAdjustment();

            expect.StockAdjustmentId = id;
            expect.CreatedDateTime   = DateTime.Now;
            StockAdjustmentDetail s1 = new StockAdjustmentDetail();

            s1.StockAdjustmentId = id;
            s1.ItemCode          = "C003";
            s1.OriginalQuantity  = 10;
            s1.AfterQuantity     = 20;
            StockAdjustmentDetail s2 = new StockAdjustmentDetail();

            s2.StockAdjustmentId = id;
            s2.ItemCode          = "C002";
            s2.OriginalQuantity  = 20;
            s2.AfterQuantity     = 30;
            List <StockAdjustmentDetail> list = new List <StockAdjustmentDetail>();

            list.Add(s1);
            list.Add(s2);
            expect.StockAdjustmentDetails = list;
            service.CreateDraftStockAdjustment(expect);
            string delete_Item = "C003";

            //test can't find StockAdjustment
            try
            {
                var result = service.DeleteItemFromDraftOrPendingStockAdjustment(id, "123");
                //Assert
                Assert.AreEqual(delete_Item, result);
                Assert.AreEqual(stockAdjustmentDetailRepository.FindById(id, result), null);
                Assert.AreEqual(expect.StockAdjustmentDetails.Count, 1);
                //stockAdjustmentRepository.Delete(expect);
            }
            catch (Exception e)
            { Assert.IsTrue(e.Message.Contains("can't find stockAdjustmentDetail")); }


            // test can't find stockAdjustment
            try
            {
                var result = service.DeleteItemFromDraftOrPendingStockAdjustment("3", delete_Item);//don't exist
                //Assert
                Assert.AreEqual(delete_Item, result);
                Assert.AreEqual(stockAdjustmentDetailRepository.FindById(id, result), null);
                Assert.AreEqual(expect.StockAdjustmentDetails.Count, 1);
                // stockAdjustmentRepository.Delete(expect);
            }
            catch (Exception e)
            { Assert.IsTrue(e.Message.Contains("can't find StockAdjustment")); }

            // No Exception part
            try
            {
                string delete_Item1 = "C003";
                var    result       = service.DeleteItemFromDraftOrPendingStockAdjustment(id, delete_Item1);
                //Assert
                Assert.AreEqual(delete_Item1, result);
                Assert.AreEqual(stockAdjustmentDetailRepository.FindById(id, result), null);
                Assert.AreEqual(expect.StockAdjustmentDetails.Count, 1);
                stockAdjustmentRepository.Delete(expect);
            }
            catch (Exception e)
            { Assert.IsTrue(e.Message.Contains("can't find StockAdjustmentDetail")); }
        }