我正在嘗試為我繼承的遺留代碼創(chuàng)建 API 集成測試。目前我有一段測試代碼:重新創(chuàng)建數(shù)據(jù)庫(使用 Fluent Migrations)啟動網(wǎng)絡(luò)應(yīng)用程序 (Owin.Hosting)調(diào)用 api 獲取授權(quán)令牌對授權(quán)端點進行 api 調(diào)用如果我跳過第一步并只執(zhí)行 2) 3) 4),它會完美地工作。我還能夠執(zhí)行步驟 1) 2) 3)(因此 auth API 調(diào)用可以與包括的數(shù)據(jù)庫重新創(chuàng)建一起使用),這有點奇怪。我以為我的 web api 工作不正常,但是當我不重新創(chuàng)建數(shù)據(jù)庫時,我可以執(zhí)行基本路徑。然后我想當我重新創(chuàng)建數(shù)據(jù)庫時它可能根本不起作用,但我能夠授權(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 回答
- 0 關(guān)注
- 115 瀏覽
添加回答
舉報
0/150
提交
取消