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<TopBasePoco, BaseSearcher>));
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$
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();
}
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<string, object>();
$fc$
_controller.Edit(vm);
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 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<TopBasePoco>));
Assert.AreEqual(v.ID, (rv.Model as IBaseCRUDVM<TopBasePoco>).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<string, object>();
$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$
Assert.AreEqual(data1.UpdateBy, "user");
Assert.IsTrue(DateTime.Now.Subtract(data1.UpdateTime.Value).Seconds < 10);
Assert.AreEqual(data2.UpdateBy, "user");
Assert.IsTrue(DateTime.Now.Subtract(data2.UpdateTime.Value).Seconds < 10);
}
}
[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$
}
}
[TestMethod]
public void ExportTest()
{
PartialViewResult rv = (PartialViewResult)_controller.Index();
Assert.IsInstanceOfType(rv.Model, typeof(IBasePagedListVM<TopBasePoco, BaseSearcher>));
IActionResult rv2 = _controller.ExportExcel(rv.Model as $model$ListVM);
Assert.IsTrue((rv2 as FileContentResult).FileContents.Length > 0);
}
$add$
}
}
沐知全栈开发
- 粉丝: 5818
- 资源: 5227
最新资源
- 昆仑通态MCGS与3台欧姆龙E5*C温控器通讯程序功能:通过昆仑通态触摸屏,实现对3台欧姆龙E5CC温控器 设定温度值,读取实际温度,设定报警值,设定报警类型,报警上下限功能 反应灵敏,通讯稳定可靠
- 大电流电动工具,电动螺丝刀,电锯批量方案,12V,30A FOC控制
- 三菱FX3G两轴标准程序,XZ两轴,包含轴点动,回零,相对与绝对定位,只要弄明白这个程序,就可以非常了解整个项目的程序如何去编写,从哪里开始下手,
- 昆仑通态MCGS与2台台达VFD-M变频器通讯程序实现昆仑通态触摸屏与2台台达VFD-M变频器通讯,程序稳定可靠 器件:昆仑通态TPC7062KD触摸屏,2台台达VFD-M变频器,附送接线说明和设置说
- MATLAB代码:考虑安全约束及热备用的电力系统机组组合研究 关键词:机组组合 直流潮流 优化调度 参考文档:店主自编文档,模型数据清晰明了 仿真平台:MATLAB+CPLEX gurobi平台
- c#上位案例,动态添加控件 1、这是个上位机案例,自己写来通过电脑监控kuka机器人信号的工具; 3、软件界面上可以动态添加要监控的信号,可以强制输出信号 4、有c#源代码,可以作为上位机与机器人通
- 三菱FX3U与力士乐VFC-x610变频器通讯程序三菱FX3U与力士乐VFC-x610变频器通讯案例程序,有注释 并附送程序,有接线方式,设置 器件:三菱FX3U的PLC,力士乐VFCx610变频
- 台达DVP PLC与3台力士乐VFC-x610变频器通讯程序 程序带注释,并附送昆仑通态程序,有接线方式,设置 器件:台达DVP ES系列的PLC,3台力士乐VFC-x610系列变频器,昆仑通态 功
- FPGA开发:实现数码管+1602双通道秒表(联系后留邮)按键切秒表模式,所用开发板DE2-115,代码可移植,内含FPGA驱动1602代码,代码有详细注释
- 汇川PLC AM403-CPU1608TN,2020产品基于CODESYS平台二次订制软件,支持16轴ethercat总线,自带以太网 USB CANOPEN 2路485,16高速输入8高速输出,功能
- 电力电子、电机驱动、数字滤波器matlab simulink仿真模型实现及相关算法的C代码实现 配置C2000 DSP ADC DAC PWM定时器 中断等模块,提供simulink与DSP的联合仿
- labview.通用OCR识别技术
- FoobarCon_v0.9.91.0.apk
- 华为HarmonyOS应用开发者高级认证,官方专业证书
- 华为HarmonyOS应用开发者高级认证,官方专业证书
- 51单片机四层电梯控制器 基于51单片机的四层电梯控制系统 包括源代码和proteus仿真 系统硬件由51单片机最小系统、蜂鸣器电路、指示灯电路、内部按键电路、外部按键电路、步进电机、ULN2003
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈