public void CreateTest()
        {
            PartialViewResult rv = (PartialViewResult)_controller.Create();

            Assert.IsInstanceOfType(rv.Model, typeof(GoodsInputVM));

            GoodsInputVM vm = rv.Model as GoodsInputVM;
            GoodsInput   v  = new GoodsInput();

            v.SupplierId  = AddSupplier();
            v.GoodsInfoId = AddGoodsInfo();
            v.InputNumber = 87;
            v.Producer    = "GAkoZLR";
            v.BatchNumber = "A2w6DoAs";
            v.ApprovalNo  = "Z4cm";
            vm.Entity     = v;
            _controller.Create(vm);

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                var data = context.Set <GoodsInput>().FirstOrDefault();

                Assert.AreEqual(data.InputNumber, 87);
                Assert.AreEqual(data.Producer, "GAkoZLR");
                Assert.AreEqual(data.BatchNumber, "A2w6DoAs");
                Assert.AreEqual(data.ApprovalNo, "Z4cm");
                Assert.AreEqual(data.CreateBy, "user");
                Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10);
            }
        }
        public void DeleteTest()
        {
            GoodsInput v = new GoodsInput();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                v.SupplierId  = AddSupplier();
                v.GoodsInfoId = AddGoodsInfo();
                v.InputNumber = 87;
                v.Producer    = "GAkoZLR";
                v.BatchNumber = "A2w6DoAs";
                v.ApprovalNo  = "Z4cm";
                context.Set <GoodsInput>().Add(v);
                context.SaveChanges();
            }

            PartialViewResult rv = (PartialViewResult)_controller.Delete(v.ID.ToString());

            Assert.IsInstanceOfType(rv.Model, typeof(GoodsInputVM));

            GoodsInputVM vm = rv.Model as GoodsInputVM;

            v         = new GoodsInput();
            v.ID      = vm.Entity.ID;
            vm.Entity = v;
            _controller.Delete(v.ID.ToString(), null);

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                Assert.AreEqual(context.Set <GoodsInput>().Count(), 1);
            }
        }
        public void EditTest()
        {
            GoodsInput v = new GoodsInput();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                v.SupplierId  = AddSupplier();
                v.GoodsInfoId = AddGoodsInfo();
                v.InputNumber = 87;
                v.Producer    = "GAkoZLR";
                v.BatchNumber = "A2w6DoAs";
                v.ApprovalNo  = "Z4cm";
                context.Set <GoodsInput>().Add(v);
                context.SaveChanges();
            }

            PartialViewResult rv = (PartialViewResult)_controller.Edit(v.ID.ToString());

            Assert.IsInstanceOfType(rv.Model, typeof(GoodsInputVM));

            GoodsInputVM vm = rv.Model as GoodsInputVM;

            v    = new GoodsInput();
            v.ID = vm.Entity.ID;

            v.InputNumber = 19;
            v.Producer    = "rzWULy";
            v.BatchNumber = "IQK0Yeopa";
            v.ApprovalNo  = "Usha";
            vm.Entity     = v;
            vm.FC         = new Dictionary <string, object>();

            vm.FC.Add("Entity.SupplierId", "");
            vm.FC.Add("Entity.GoodsInfoId", "");
            vm.FC.Add("Entity.InputNumber", "");
            vm.FC.Add("Entity.Producer", "");
            vm.FC.Add("Entity.BatchNumber", "");
            vm.FC.Add("Entity.ApprovalNo", "");
            _controller.Edit(vm);

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                var data = context.Set <GoodsInput>().FirstOrDefault();

                Assert.AreEqual(data.InputNumber, 19);
                Assert.AreEqual(data.Producer, "rzWULy");
                Assert.AreEqual(data.BatchNumber, "IQK0Yeopa");
                Assert.AreEqual(data.ApprovalNo, "Usha");
                Assert.AreEqual(data.UpdateBy, "user");
                Assert.IsTrue(DateTime.Now.Subtract(data.UpdateTime.Value).Seconds < 10);
            }
        }
Exemple #4
0
        public ActionResult Create(GoodsInputVM vm)
        {
            vm.Entity.InputTime = DateTime.Now;

            string sql = "SELECT * FROM GoodsInfos WHERE ID='{0}'";

            sql = string.Format(sql, vm.Entity.GoodsInfoId);
            DataTable dt        = DC.RunSQL(sql);
            decimal   oldNumber = new decimal();

            if (dt.Rows.Count > 0)
            {
                oldNumber = Convert.ToDecimal(dt.Rows[0]["InputNumber"].ToString());
            }

            decimal newNumber = oldNumber + vm.Entity.InputNumber;

            if (!ModelState.IsValid)
            {
                return(PartialView(vm));
            }
            else
            {
                sql = "UPDATE GoodsInfos SET InputNumber='{0}' WHERE ID='{1}'";
                sql = string.Format(sql, newNumber, vm.Entity.GoodsInfoId);
                var cmd = DC.Database.GetDbConnection().CreateCommand();
                cmd.CommandText = sql;
                cmd.CommandType = CommandType.Text;
                cmd.Connection.Open();
                cmd.ExecuteReader();
                cmd.Connection.Close();

                vm.DoAdd();
                if (!ModelState.IsValid)
                {
                    vm.DoReInit();
                    return(PartialView(vm));
                }
                else
                {
                    return(FFResult().CloseDialog().RefreshGrid());
                }
            }
        }