forked from dotnetcore/AgileConfig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestAppController.cs
70 lines (64 loc) · 2.63 KB
/
TestAppController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using AgileConfig.Server.Apisite.Controllers;
using AgileConfig.Server.Apisite.Controllers.api;
using AgileConfig.Server.Apisite.Models;
using AgileConfig.Server.Data.Entity;
using AgileConfig.Server.IService;
using Microsoft.AspNetCore.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
namespace ApiSiteTests
{
[TestClass]
public class TestAppController
{
[TestMethod]
public async Task TestAdd()
{
var appService = new Mock<IAppService>();
var logService = new Mock<ISysLogService>();
var userService = new Mock<IUserService>();
var permissionService = new Mock<IPremissionService>();
var ctl = new AgileConfig.Server.Apisite.Controllers.AppController(appService.Object, permissionService.Object, userService.Object);
Assert.ThrowsException<ArgumentNullException>( () => {
ctl.Add(null).GetAwaiter().GetResult();
});
appService.Setup(s => s.GetAsync("01")).ReturnsAsync(new App());
var result = await ctl.Add(new AppVM
{
Id = "01"
});
Assert.IsNotNull(result);
Assert.IsInstanceOfType(result, typeof(JsonResult));
var jr = result as JsonResult;
Assert.IsNotNull(jr.Value);
Assert.IsTrue(jr.Value.ToString().Contains("应用Id已存在,请重新输入"));
App nullApp = null;
appService.Setup(s => s.GetAsync("02")).ReturnsAsync(nullApp);
appService.Setup(s => s.AddAsync(It.IsAny<App>())).ReturnsAsync(false);
result = await ctl.Add(new AppVM
{
Id = "02"
});
Assert.IsNotNull(result);
Assert.IsInstanceOfType(result, typeof(JsonResult));
jr = result as JsonResult;
Assert.IsNotNull(jr.Value);
Assert.IsTrue(jr.Value.ToString().Contains("新建应用失败,请查看错误日志"));
appService.Setup(s => s.AddAsync(It.IsAny<App>())).ReturnsAsync(true);
appService.Setup(s => s.AddAsync(It.IsAny<App>(), It.IsAny<List<AppInheritanced>>())).ReturnsAsync(true);
result = await ctl.Add(new AppVM
{
Id = "02"
});
Assert.IsNotNull(result);
Assert.IsInstanceOfType(result, typeof(JsonResult));
jr = result as JsonResult;
Assert.IsNotNull(jr.Value);
Assert.IsFalse(jr.Value.ToString().Contains("新建应用失败,请查看错误日志"));
}
}
}