我正在嘗試為我繼承的遺留代碼創(chuàng)建 API 集成測(cè)試。目前我有一段測(cè)試代碼:重新創(chuàng)建數(shù)據(jù)庫(kù)(使用 Fluent Migrations)啟動(dòng)網(wǎng)絡(luò)應(yīng)用程序 (Owin.Hosting)調(diào)用 api 獲取授權(quán)令牌對(duì)授權(quán)端點(diǎn)進(jìn)行 api 調(diào)用如果我跳過第一步并只執(zhí)行 2) 3) 4),它會(huì)完美地工作。我還能夠執(zhí)行步驟 1) 2) 3)(因此 auth API 調(diào)用可以與包括的數(shù)據(jù)庫(kù)重新創(chuàng)建一起使用),這有點(diǎn)奇怪。我以為我的 web api 工作不正常,但是當(dāng)我不重新創(chuàng)建數(shù)據(jù)庫(kù)時(shí),我可以執(zhí)行基本路徑。然后我想當(dāng)我重新創(chuàng)建數(shù)據(jù)庫(kù)時(shí)它可能根本不起作用,但我能夠授權(quán)用戶。我不知道我現(xiàn)在可以嘗試什么。[Collection("Database Create collection")]public class RoleControllerTests : IDisposable{ private readonly IDisposable _server; private readonly string _url = new Configuration().ServerUrl; public RoleControllerTests() { _server = WebApp.Start<Startup>(_url); } public void Dispose() { _server.Dispose(); } [Fact] public async Task basic_roles_should_exist_in_the_database() { // Arrange var roleApi = RestClient.For<IRoleController>(_url); IAuthorize auth = new Authorize(); roleApi.AuthenticationHeader = await auth.GetAuthenticationHeaderAsync(); // Act var rolesData = await roleApi.List(); // Assert rolesData.ShouldContain(x => x.Name == "User"); rolesData.ShouldContain(x => x.Name == "Displayer"); }}
1 回答
瀟瀟雨雨
TA貢獻(xiàn)1833條經(jīng)驗(yàn) 獲得超4個(gè)贊
所以我將測(cè)試框架更改為 NUnit 并且它正在運(yùn)行。我不知道為什么,XUnit 在運(yùn)行時(shí)更改內(nèi)容時(shí)是否存在一些問題?
- 1 回答
- 0 關(guān)注
- 135 瀏覽
添加回答
舉報(bào)
0/150
提交
取消
