fix(#IXE2H): 重构单元测试工具

RevokePocoMapper方法支持泛型

close https://gitee.com/LongbowEnterprise/dashboard/issues?id=IXE2H
This commit is contained in:
Argo Zhang 2019-06-04 10:18:27 +08:00
parent db8dbbefb1
commit 4cd8d6c9f4
3 changed files with 27 additions and 16 deletions

View File

@ -1,4 +1,4 @@
using Longbow.Web.Mvc;
using Longbow.Web.Mvc;
using PetaPoco;
using System;
using System.Collections.Generic;
@ -95,6 +95,9 @@ namespace Bootstrap.DataAccess
}
loopEx = loopEx.InnerException;
}
try
{
// 防止数据库写入操作失败后陷入死循环
DbManager.Create().Insert(new Exceptions
{
AppDomainName = AppDomain.CurrentDomain.FriendlyName,
@ -108,6 +111,8 @@ namespace Bootstrap.DataAccess
Category = category
});
ClearExceptions();
}
catch { }
return true;
}

View File

@ -79,7 +79,7 @@ namespace Bootstrap.DataAccess
var newUser = new User() { UserName = "U_Reset", DisplayName = "UnitTest", ApprovedTime = DateTime.Now, ApprovedBy = "System", Password = "1", Description = "UnitTest", RegisterTime = DateTime.Now };
Assert.True(UserHelper.Save(newUser));
Assert.True(UserHelper.ForgotPassword(new ResetUser() { DisplayName = "UnitTest", Reason = "UnitTest", ResetTime = DateTime.Now, UserName = newUser.UserName }));
Assert.ThrowsAny<Exception>(() => TestHelper.RevokeUserMapper(() => new User().ResetPassword(newUser.UserName, "123789")));
Assert.ThrowsAny<Exception>(() => TestHelper.RevokePocoMapper<User>(() => new User().ResetPassword(newUser.UserName, "123789")));
Assert.True(UserHelper.Delete(new string[] { newUser.Id }));
}
@ -106,5 +106,11 @@ namespace Bootstrap.DataAccess
{
Assert.ThrowsAny<Exception>(() => TestHelper.RevokeMapper(() => new User().SaveByGroupId("1", new string[] { "1" })));
}
[Fact]
public void Exceptions_Log()
{
TestHelper.RevokePocoMapper<Exceptions>(() => new Exceptions().Log(new Exception(), null));
}
}
}

View File

@ -103,10 +103,10 @@ namespace UnitTest
}
}
public static void RevokeUserMapper(Action callback)
public static void RevokePocoMapper<T>(Action callback)
{
var foo = new FooMapper();
Mappers.Register(typeof(User), foo);
Mappers.Register(typeof(T), foo);
try { callback(); }
catch (Exception ex) { throw ex; }
finally