public void CreateTest() { PartialViewResult rv = (PartialViewResult)_controller.Create(); Assert.IsInstanceOfType(rv.Model, typeof(WxProductVM)); WxProductVM vm = rv.Model as WxProductVM; WxProduct v = new WxProduct(); v.ID = 41; v.Name = "2QFM62s3"; v.VenueId = AddVenue(); v.Price = 33; v.AvailableStock = 24; v.Description = "XhKg7NCQK"; vm.Entity = v; _controller.Create(vm); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <WxProduct>().FirstOrDefault(); Assert.AreEqual(data.ID, 41); Assert.AreEqual(data.Name, "2QFM62s3"); Assert.AreEqual(data.Price, 33); Assert.AreEqual(data.AvailableStock, 24); Assert.AreEqual(data.Description, "XhKg7NCQK"); Assert.AreEqual(data.CreateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10); } }
public void DeleteTest() { WxProduct v = new WxProduct(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.ID = 41; v.Name = "2QFM62s3"; v.VenueId = AddVenue(); v.Price = 33; v.AvailableStock = 24; v.Description = "XhKg7NCQK"; context.Set <WxProduct>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Delete(v.ID.ToString()); Assert.IsInstanceOfType(rv.Model, typeof(WxProductVM)); WxProductVM vm = rv.Model as WxProductVM; v = new WxProduct(); 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 <WxProduct>().Count(), 1); } }
public void EditTest() { WxProduct v = new WxProduct(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.ID = 41; v.Name = "2QFM62s3"; v.VenueId = AddVenue(); v.Price = 33; v.AvailableStock = 24; v.Description = "XhKg7NCQK"; context.Set <WxProduct>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Edit(v.ID.ToString()); Assert.IsInstanceOfType(rv.Model, typeof(WxProductVM)); WxProductVM vm = rv.Model as WxProductVM; v = new WxProduct(); v.ID = vm.Entity.ID; v.Name = "pmOS9wR"; v.Price = 83; v.AvailableStock = 94; v.Description = "RG1wBqk"; vm.Entity = v; vm.FC = new Dictionary <string, object>(); vm.FC.Add("Entity.ID", ""); vm.FC.Add("Entity.Name", ""); vm.FC.Add("Entity.VenueId", ""); vm.FC.Add("Entity.Price", ""); vm.FC.Add("Entity.AvailableStock", ""); vm.FC.Add("Entity.Description", ""); _controller.Edit(vm); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <WxProduct>().FirstOrDefault(); Assert.AreEqual(data.Name, "pmOS9wR"); Assert.AreEqual(data.Price, 83); Assert.AreEqual(data.AvailableStock, 94); Assert.AreEqual(data.Description, "RG1wBqk"); Assert.AreEqual(data.UpdateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.UpdateTime.Value).Seconds < 10); } }
public ActionResult Edit(WxProductVM vm) { if (!ModelState.IsValid) { return(PartialView(vm)); } else { vm.DoEdit(); if (!ModelState.IsValid) { vm.DoReInit(); return(PartialView(vm)); } else { return(FFResult().CloseDialog().RefreshGridRow(vm.Entity.ID)); } } }
public ActionResult Create(WxProductVM vm) { if (!ModelState.IsValid) { return(PartialView(vm)); } else { vm.DoAdd(); if (!ModelState.IsValid) { vm.DoReInit(); return(PartialView(vm)); } else { return(FFResult().CloseDialog().RefreshGrid()); } } }