iotgateway/WalkingTec.Mvvm/WalkingTec.Mvvm.Mvc/GeneratorFiles/ApiTestTopPoco.txt
2021-12-14 14:10:44 +08:00

127 lines
3.6 KiB
Plaintext

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$
}
}
[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<string, object>();
$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$
}
}
[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$
}
}