Пример #1
0
        public void DeletePurchaseOrderDetailTempTest()
        {
            // Get a test user
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser, true);
            var testPurchase = GetTestPurchaseOrderHeader(testCompany, testUser, 1);

            var pohtModel = PurchasingService.CopyPurchaseOrderToTemp(testCompany, testPurchase, testUser);
            var model     = PurchasingService.FindPurchaseOrderDetailTempsListModel(testCompany.Id, pohtModel.Id, 0, 1, PageSize, "");

            // Create a record
            var newItem = createPurchaseOrderDetailTemp(model);

            var error = PurchasingService.InsertOrUpdatePurchaseOrderDetailTemp(newItem, testUser, "");

            Assert.IsTrue(!error.IsError, error.Message);

            // Check that it was written
            var result = db.FindPurchaseOrderDetailTemp(newItem.Id);
            var test   = PurchasingService.MapToModel(result);

            AreEqual(model, test);

            // Now delete it
            PurchasingService.DeletePurchaseOrderDetailTemp(newItem.Id);

            // And check that is was deleted
            result = db.FindPurchaseOrderDetailTemp(newItem.Id);
            Assert.IsTrue(result == null, "Error: A non-NULL value was returned when a NULL value was expected - record delete failed");
        }
        public ActionResult Delete(int index, int id, int parentId)
        {
            var model = new PurchaseOrderDetailTempListModel();

            model.GridIndex = index;
            try {
                PurchasingService.DeletePurchaseOrderDetailTemp(id);
            } catch (Exception e1) {
                model.Error.SetError(e1);
            }
            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        public void FindPurchaseOrderDetailTempsListModelTest()
        {
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser, true);
            var testPurchase = GetTestPurchaseOrderHeader(testCompany, testUser, 10);

            var pohtModel = PurchasingService.CopyPurchaseOrderToTemp(testCompany, testPurchase, testUser);

            var model  = PurchasingService.FindPurchaseOrderDetailTempsListModel(testCompany.Id, pohtModel.Id, 0, 1, PageSize, "");
            var dbData = db.FindPurchaseOrderDetailTemps(testCompany.Id, pohtModel.Id);

            int expected = dbData.Count(),
                actual   = model.Items.Count();

            Assert.IsTrue(actual == expected, $"Error: {actual} items were found when {expected} were expected");

            // Check that all the items match
            foreach (var item in model.Items)
            {
                var dbItem = dbData.Where(m => m.Id == item.Id).FirstOrDefault();
                Assert.IsTrue(dbItem != null, "Error: Model item not found in db item list");
                var temp = PurchasingService.MapToModel(dbItem);
                AreEqual(item, temp);
            }

            // Add another item a make sure it is found
            var newItem = createPurchaseOrderDetailTemp(model);
            var error   = PurchasingService.InsertOrUpdatePurchaseOrderDetailTemp(newItem, testUser, "");

            Assert.IsTrue(!error.IsError, $"Error: {error.Message}");

            model = PurchasingService.FindPurchaseOrderDetailTempsListModel(testCompany.Id, pohtModel.Id, 0, 1, PageSize, "");
            var testItem = model.Items.Where(i => i.Id == newItem.Id).FirstOrDefault();

            Assert.IsTrue(testItem != null, "Error: A NULL value was returned when a non-NULL value was expected");

            // Delete it and make sure it disappears
            PurchasingService.DeletePurchaseOrderDetailTemp(newItem.Id);

            model    = PurchasingService.FindPurchaseOrderDetailTempsListModel(testCompany.Id, pohtModel.Id, 0, 1, PageSize, "");
            testItem = model.Items.Where(i => i.Id == newItem.Id).FirstOrDefault();
            Assert.IsTrue(testItem == null, "Error: A non-NULL value was returned when a NULL value was expected");
        }