150 lines
5.2 KiB
C#
150 lines
5.2 KiB
C#
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 wtmProject.Controllers;
|
|
using wtmProject.ViewModel._Admin.FrameworkCustomVMs;
|
|
using wtmProject.Model;
|
|
using wtmProject.DataAccess;
|
|
|
|
|
|
namespace wtmProject.Test
|
|
{
|
|
[TestClass]
|
|
public class FrameworkCustomApiTest
|
|
{
|
|
private FrameworkCustomController _controller;
|
|
private string _seed;
|
|
|
|
public FrameworkCustomApiTest()
|
|
{
|
|
_seed = Guid.NewGuid().ToString();
|
|
_controller = MockController.CreateApi<FrameworkCustomController>(new DataContext(_seed, DBTypeEnum.Memory), "user");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void SearchTest()
|
|
{
|
|
ContentResult rv = _controller.Search(new FrameworkCustomSearcher()) as ContentResult;
|
|
Assert.IsTrue(string.IsNullOrEmpty(rv.Content)==false);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CreateTest()
|
|
{
|
|
FrameworkCustomVM vm = _controller.Wtm.CreateVM<FrameworkCustomVM>();
|
|
FrameworkCustom v = new FrameworkCustom();
|
|
|
|
v.CustomCode = "OVSFqqyL4sSNNRnvSoqhNCEXKl";
|
|
v.CustomName = "Q4mWuAbk";
|
|
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<FrameworkCustom>().Find(v.ID);
|
|
|
|
Assert.AreEqual(data.CustomCode, "OVSFqqyL4sSNNRnvSoqhNCEXKl");
|
|
Assert.AreEqual(data.CustomName, "Q4mWuAbk");
|
|
Assert.AreEqual(data.CreateBy, "user");
|
|
Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10);
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void EditTest()
|
|
{
|
|
FrameworkCustom v = new FrameworkCustom();
|
|
using (var context = new DataContext(_seed, DBTypeEnum.Memory))
|
|
{
|
|
|
|
v.CustomCode = "OVSFqqyL4sSNNRnvSoqhNCEXKl";
|
|
v.CustomName = "Q4mWuAbk";
|
|
context.Set<FrameworkCustom>().Add(v);
|
|
context.SaveChanges();
|
|
}
|
|
|
|
FrameworkCustomVM vm = _controller.Wtm.CreateVM<FrameworkCustomVM>();
|
|
var oldID = v.ID;
|
|
v = new FrameworkCustom();
|
|
v.ID = oldID;
|
|
|
|
v.CustomCode = "jAQCNx8At2z6fFC2ipJy2qszH";
|
|
v.CustomName = "dXygBTzx54lkdhmXowr7bzmeK2FUunw";
|
|
vm.Entity = v;
|
|
vm.FC = new Dictionary<string, object>();
|
|
|
|
vm.FC.Add("Entity.CustomCode", "");
|
|
vm.FC.Add("Entity.CustomName", "");
|
|
var rv = _controller.Edit(vm);
|
|
Assert.IsInstanceOfType(rv, typeof(OkObjectResult));
|
|
|
|
using (var context = new DataContext(_seed, DBTypeEnum.Memory))
|
|
{
|
|
var data = context.Set<FrameworkCustom>().Find(v.ID);
|
|
|
|
Assert.AreEqual(data.CustomCode, "jAQCNx8At2z6fFC2ipJy2qszH");
|
|
Assert.AreEqual(data.CustomName, "dXygBTzx54lkdhmXowr7bzmeK2FUunw");
|
|
Assert.AreEqual(data.UpdateBy, "user");
|
|
Assert.IsTrue(DateTime.Now.Subtract(data.UpdateTime.Value).Seconds < 10);
|
|
}
|
|
|
|
}
|
|
|
|
[TestMethod]
|
|
public void GetTest()
|
|
{
|
|
FrameworkCustom v = new FrameworkCustom();
|
|
using (var context = new DataContext(_seed, DBTypeEnum.Memory))
|
|
{
|
|
|
|
v.CustomCode = "OVSFqqyL4sSNNRnvSoqhNCEXKl";
|
|
v.CustomName = "Q4mWuAbk";
|
|
context.Set<FrameworkCustom>().Add(v);
|
|
context.SaveChanges();
|
|
}
|
|
var rv = _controller.Get(v.ID.ToString());
|
|
Assert.IsNotNull(rv);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void BatchDeleteTest()
|
|
{
|
|
FrameworkCustom v1 = new FrameworkCustom();
|
|
FrameworkCustom v2 = new FrameworkCustom();
|
|
using (var context = new DataContext(_seed, DBTypeEnum.Memory))
|
|
{
|
|
|
|
v1.CustomCode = "OVSFqqyL4sSNNRnvSoqhNCEXKl";
|
|
v1.CustomName = "Q4mWuAbk";
|
|
v2.CustomCode = "jAQCNx8At2z6fFC2ipJy2qszH";
|
|
v2.CustomName = "dXygBTzx54lkdhmXowr7bzmeK2FUunw";
|
|
context.Set<FrameworkCustom>().Add(v1);
|
|
context.Set<FrameworkCustom>().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<FrameworkCustom>().Find(v1.ID);
|
|
var data2 = context.Set<FrameworkCustom>().Find(v2.ID);
|
|
Assert.AreEqual(data1, null);
|
|
Assert.AreEqual(data2, null);
|
|
}
|
|
|
|
rv = _controller.BatchDelete(new string[] {});
|
|
Assert.IsInstanceOfType(rv, typeof(OkResult));
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|