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$
}
}
沐知全栈开发
- 粉丝: 5819
- 资源: 5219
最新资源
- v5vv5v5v55v5v5v55v5
- 基于java+ssm+mysql的新闻网站 源码+数据库+论文(高分毕设项目).zip
- 基于java+ssm+mysql的校园线上订餐系统 源码+数据库+论文(高分毕设项目).zip
- 基于java+ssm+mysql的校园心理健康网站 源码+数据库+论文(高分毕设项目).zip
- Python游戏源码-09五子棋
- 基于主从博弈的电热综合能源系统动态定价与能量管理策略优化-粒子群算法与CPLEX求解器的应用,MATLAB代码:基于主从博弈的电热综合能源系统动态定价与能量管理 超值 关键词:主从博弈 电热综合能源
- 基于java+ssm+mysql的学生资助管理系统 源码+数据库+论文(高分毕设项目).zip
- RexVision 1.6.1:C#与Halcon机器视觉框架集成源码,适用于视觉检测与机械手定位,插件式开发,手眼标定与C#脚本支持,高效省时,RexVision 1.6.1,C#+Halcon机器
- 基于java+ssm+mysql的学生在线考试系统 源码+数据库+论文(高分毕设项目).zip
- 基于分时电价机制的家庭能量管理策略优化研究:结合空调、电动汽车与可平移负荷的智能调控模型,MATLAB代码:基于分时电价条件下家庭能量管理策略研究 关键词:家庭能量管理模型 分时电价 空调 电动汽车
- 基于java+ssm+mysql的医院交互系统 源码+数据库+论文(高分毕设项目).zip
- 基于java+ssm+mysql的音乐电影分享系统 源码+数据库+论文(高分毕设项目).zip
- 基于java+ssm+mysql的眼镜网店销售系统 源码+数据库+论文(高分毕设项目).zip
- Python游戏源码-10植物大战僵尸
- **《电子凸轮控制系统Ver2.3.0:双轴定速伺服运动与送料动作的精准协调》**,电子凸轮-区间运动Ver2.3.0(位置跟随,去程+返程,适合送料动作) 1.一个主轴伺服(定速运动)+一个从轴伺服
- 基于java+ssm+mysql的游戏资源管理系统 源码+数据库+论文(高分毕设项目).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈