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$ApiTest { private $classnamel$Controller _controller; private string _seed; public $model$ApiTest() { _seed = Guid.NewGuid().ToString(); _controller = MockController.CreateApi<$classnamel$Controller>(new DataContext(_seed, DBTypeEnum.Memory), "user"); } [TestMethod] public void SearchTest() { ContentResult rv = _controller.Search(new $classnamel$Searcher()) as ContentResult; Assert.IsTrue(string.IsNullOrEmpty(rv.Content)==false); } [TestMethod] public void CreateTest() { $classnamel$VM vm = _controller.Wtm.CreateVM<$classnamel$VM>(); $model$ v = new $model$(); $cpros$ vm.Entity = v; var rv = _controller.Add(vm); Assert.IsInstanceOfType(rv, typeof(OkObjectResult)); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set<$model$>().Find(v.ID); $assert$ Assert.AreEqual(data.CreateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10); } } [TestMethod] public void EditTest() { $model$ v = new $model$(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { $pros$ context.Set<$model$>().Add(v); context.SaveChanges(); } $classnamel$VM vm = _controller.Wtm.CreateVM<$classnamel$VM>(); var oldID = v.ID; v = new $model$(); v.ID = oldID; $epros$ vm.Entity = v; vm.FC = new Dictionary(); $fc$ var rv = _controller.Edit(vm); Assert.IsInstanceOfType(rv, typeof(OkObjectResult)); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set<$model$>().Find(v.ID); $eassert$ Assert.AreEqual(data.UpdateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.UpdateTime.Value).Seconds < 10); } } [TestMethod] public void GetTest() { $model$ v = new $model$(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { $pros$ context.Set<$model$>().Add(v); context.SaveChanges(); } var rv = _controller.Get(v.ID.ToString()); Assert.IsNotNull(rv); } [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(); } var rv = _controller.BatchDelete(new string[] { v1.ID.ToString(), v2.ID.ToString() }); Assert.IsInstanceOfType(rv, typeof(OkObjectResult)); 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$ } rv = _controller.BatchDelete(new string[] {}); Assert.IsInstanceOfType(rv, typeof(OkResult)); } $add$ } }