using Microsoft.AspNetCore.Mvc; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; using System.Linq; using System.Text; using WalkingTec.Mvvm.Core; using $cns$; using $vns$; using $mns$; using $dns$; $othernamespace$ namespace $tns$ { [TestClass] public class $model$ControllerTest { private $model$Controller _controller; private string _seed; public $model$ControllerTest() { _seed = Guid.NewGuid().ToString(); _controller = MockController.CreateController<$model$Controller>(new DataContext(_seed, DBTypeEnum.Memory), "user"); } [TestMethod] public void SearchTest() { PartialViewResult rv = (PartialViewResult)_controller.Index(); Assert.IsInstanceOfType(rv.Model, typeof(IBasePagedListVM)); string rv2 = _controller.Search((rv.Model as $model$ListVM).Searcher); Assert.IsTrue(rv2.Contains("\"Code\":200")); } [TestMethod] public void CreateTest() { PartialViewResult rv = (PartialViewResult)_controller.Create(); Assert.IsInstanceOfType(rv.Model, typeof($model$VM)); $model$VM vm = rv.Model as $model$VM; $model$ v = new $model$(); $cpros$ vm.Entity = v; _controller.Create(vm); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set<$model$>().Find(v.ID); $assert$ } } [TestMethod] public void EditTest() { $model$ v = new $model$(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { $pros$ context.Set<$model$>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Edit(v.ID.ToString()); Assert.IsInstanceOfType(rv.Model, typeof($model$VM)); $model$VM vm = rv.Model as $model$VM; vm.Wtm.DC = new DataContext(_seed, DBTypeEnum.Memory); v = new $model$(); v.ID = vm.Entity.ID; $epros$ vm.Entity = v; vm.FC = new Dictionary(); $fc$ _controller.Edit(vm); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set<$model$>().Find(v.ID); $eassert$ } } [TestMethod] public void DeleteTest() { $model$ v = new $model$(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { $pros$ context.Set<$model$>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Delete(v.ID.ToString()); Assert.IsInstanceOfType(rv.Model, typeof($model$VM)); $model$VM vm = rv.Model as $model$VM; v = new $model$(); v.ID = vm.Entity.ID; vm.Entity = v; _controller.Delete(v.ID.ToString(),null); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set<$model$>().Find(v.ID); $del$ } } [TestMethod] public void DetailsTest() { $model$ v = new $model$(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { $pros$ context.Set<$model$>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Details(v.ID.ToString()); Assert.IsInstanceOfType(rv.Model, typeof(IBaseCRUDVM)); Assert.AreEqual(v.ID, (rv.Model as IBaseCRUDVM).Entity.GetID()); } [TestMethod] public void BatchEditTest() { $model$ v1 = new $model$(); $model$ v2 = new $model$(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { $mpros$ context.Set<$model$>().Add(v1); context.Set<$model$>().Add(v2); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.BatchDelete(new string[] { v1.ID.ToString(), v2.ID.ToString() }); Assert.IsInstanceOfType(rv.Model, typeof($model$BatchVM)); $model$BatchVM vm = rv.Model as $model$BatchVM; vm.Ids = new string[] { v1.ID.ToString(), v2.ID.ToString() }; $linkedpros$ vm.FC = new Dictionary(); $linkedfc$ _controller.DoBatchEdit(vm, null); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data1 = context.Set<$model$>().Find(v1.ID); var data2 = context.Set<$model$>().Find(v2.ID); $meassert$ } } [TestMethod] public void BatchDeleteTest() { $model$ v1 = new $model$(); $model$ v2 = new $model$(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { $mpros$ context.Set<$model$>().Add(v1); context.Set<$model$>().Add(v2); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.BatchDelete(new string[] { v1.ID.ToString(), v2.ID.ToString() }); Assert.IsInstanceOfType(rv.Model, typeof($model$BatchVM)); $model$BatchVM vm = rv.Model as $model$BatchVM; vm.Ids = new string[] { v1.ID.ToString(), v2.ID.ToString() }; _controller.DoBatchDelete(vm, null); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data1 = context.Set<$model$>().Find(v1.ID); var data2 = context.Set<$model$>().Find(v2.ID); $mdel$ } } $add$ } }