From b2a5b3c3c438c3bab0076d8b2bb4dec9fa227a1b Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Mon, 20 Jun 2022 13:34:25 +0900 Subject: [PATCH] Fix tests --- .../AltcoinTests/AltcoinTests.cs | 30 +++++++------------ BTCPayServer.Tests/CrowdfundTests.cs | 10 +++---- BTCPayServer.Tests/POSTests.cs | 10 ++----- 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs b/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs index 726ecb007..d174d7475 100644 --- a/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs +++ b/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs @@ -624,8 +624,7 @@ namespace BTCPayServer.Tests var appList = Assert.IsType(Assert.IsType(apps.ListApps(user.StoreId).Result).Model); var app = appList.Apps[0]; apps.HttpContext.SetAppData(new AppData { Id = app.Id, StoreDataId = app.StoreId, Name = app.AppName }); - var vmpos = Assert.IsType(Assert - .IsType(apps.UpdatePointOfSale(app.Id)).Model); + var vmpos = await apps.UpdatePointOfSale(app.Id).AssertViewModelAsync(); vmpos.Title = "hello"; vmpos.Currency = "CAD"; vmpos.ButtonText = "{0} Purchase"; @@ -643,14 +642,11 @@ donation: custom: true "; Assert.IsType(apps.UpdatePointOfSale(app.Id, vmpos).Result); - vmpos = Assert.IsType(Assert - .IsType(apps.UpdatePointOfSale(app.Id)).Model); + vmpos = await apps.UpdatePointOfSale(app.Id).AssertViewModelAsync(); Assert.Equal("hello", vmpos.Title); var publicApps = user.GetController(); - var vmview = - Assert.IsType(Assert - .IsType(publicApps.ViewPointOfSale(app.Id, PosViewType.Cart).Result).Model); + var vmview = await publicApps.ViewPointOfSale(app.Id, PosViewType.Cart).AssertViewModelAsync(); Assert.Equal("hello", vmview.Title); Assert.Equal(3, vmview.Items.Length); Assert.Equal("good apple", vmview.Items[0].Title); @@ -701,8 +697,7 @@ donation: }) { TestLogs.LogInformation($"Testing for {test.Code}"); - vmpos = Assert.IsType(Assert - .IsType(apps.UpdatePointOfSale(app.Id)).Model); + vmpos = await apps.UpdatePointOfSale(app.Id).AssertViewModelAsync(); vmpos.Title = "hello"; vmpos.Currency = test.Item1; vmpos.ButtonText = "{0} Purchase"; @@ -720,8 +715,7 @@ donation: "; Assert.IsType(apps.UpdatePointOfSale(app.Id, vmpos).Result); publicApps = user.GetController(); - vmview = Assert.IsType(Assert - .IsType(publicApps.ViewPointOfSale(app.Id, PosViewType.Cart).Result).Model); + vmview = await publicApps.ViewPointOfSale(app.Id, PosViewType.Cart).AssertViewModelAsync(); Assert.Equal(test.Code, vmview.CurrencyCode); Assert.Equal(test.ExpectedSymbol, vmview.CurrencySymbol.Replace("¥", "¥")); // Hack so JPY test pass on linux as well); @@ -736,8 +730,7 @@ donation: } //test inventory related features - vmpos = Assert.IsType(Assert - .IsType(apps.UpdatePointOfSale(app.Id)).Model); + vmpos = await apps.UpdatePointOfSale(app.Id).AssertViewModelAsync(); vmpos.Title = "hello"; vmpos.Currency = "BTC"; vmpos.Template = @" @@ -781,17 +774,15 @@ noninventoryitem: var eventAggregator = tester.PayTester.GetService(); Assert.IsType(await controller.ChangeInvoiceState(inventoryItemInvoice.Id, "invalid")); //check that item is back in stock - TestUtils.Eventually(() => + await TestUtils.EventuallyAsync(async () => { - vmpos = Assert.IsType(Assert - .IsType(apps.UpdatePointOfSale(app.Id)).Model); + vmpos = await apps.UpdatePointOfSale(app.Id).AssertViewModelAsync(); Assert.Equal(1, appService.Parse(vmpos.Template, "BTC").Single(item => item.Id == "inventoryitem").Inventory); }, 10000); //test payment methods option - vmpos = Assert.IsType(Assert - .IsType(apps.UpdatePointOfSale(app.Id)).Model); + vmpos = await apps.UpdatePointOfSale(app.Id).AssertViewModelAsync(); vmpos.Title = "hello"; vmpos.Currency = "BTC"; vmpos.Template = @" @@ -847,8 +838,7 @@ g: "; Assert.IsType(apps.UpdatePointOfSale(app.Id, vmpos).Result); - vmpos = Assert.IsType(Assert - .IsType(apps.UpdatePointOfSale(app.Id)).Model); + vmpos = await apps.UpdatePointOfSale(app.Id).AssertViewModelAsync(); Assert.DoesNotContain("custom", vmpos.Template); var items = appService.Parse(vmpos.Template, vmpos.Currency); Assert.Contains(items, item => item.Id == "a" && item.Price.Type == ViewPointOfSaleViewModel.Item.ItemPrice.ItemPriceType.Fixed); diff --git a/BTCPayServer.Tests/CrowdfundTests.cs b/BTCPayServer.Tests/CrowdfundTests.cs index 7169055b5..2a69bdba1 100644 --- a/BTCPayServer.Tests/CrowdfundTests.cs +++ b/BTCPayServer.Tests/CrowdfundTests.cs @@ -56,7 +56,7 @@ namespace BTCPayServer.Tests Assert.IsType(apps.DeleteApp(appList.Apps[0].Id)); redirectToAction = Assert.IsType(apps.DeleteAppPost(appList.Apps[0].Id).Result); Assert.Equal(nameof(apps.ListApps), redirectToAction.ActionName); - appList = Assert.IsType(Assert.IsType(apps.ListApps(user.StoreId).Result).Model); + appList = await apps.ListApps(user.StoreId).AssertViewModelAsync(); Assert.Empty(appList.Apps); } @@ -70,7 +70,7 @@ namespace BTCPayServer.Tests await user.GrantAccessAsync(); user.RegisterDerivationScheme("BTC"); var apps = user.GetController(); - var vm = Assert.IsType(Assert.IsType(apps.CreateApp(user.StoreId)).Model); + var vm = apps.CreateApp(user.StoreId).AssertViewModel(); vm.AppName = "test"; vm.SelectedAppType = AppType.Crowdfund.ToString(); Assert.IsType(apps.CreateApp(user.StoreId, vm).Result); @@ -79,8 +79,7 @@ namespace BTCPayServer.Tests apps.HttpContext.SetAppData(new AppData { Id = app.Id, StoreDataId = app.StoreId, Name = app.AppName }); //Scenario 1: Not Enabled - Not Allowed - var crowdfundViewModel = Assert.IsType(Assert - .IsType(apps.UpdateCrowdfund(app.Id)).Model); + var crowdfundViewModel = await apps.UpdateCrowdfund(app.Id).AssertViewModelAsync(); crowdfundViewModel.TargetCurrency = "BTC"; crowdfundViewModel.Enabled = false; crowdfundViewModel.EndDate = null; @@ -167,8 +166,7 @@ namespace BTCPayServer.Tests apps.HttpContext.SetAppData(new AppData { Id = app.Id, StoreDataId = app.StoreId, Name = app.AppName }); TestLogs.LogInformation("We create an invoice with a hardcap"); - var crowdfundViewModel = Assert.IsType(Assert - .IsType(apps.UpdateCrowdfund(app.Id)).Model); + var crowdfundViewModel = await apps.UpdateCrowdfund(app.Id).AssertViewModelAsync(); crowdfundViewModel.Enabled = true; crowdfundViewModel.EndDate = null; crowdfundViewModel.TargetAmount = 100; diff --git a/BTCPayServer.Tests/POSTests.cs b/BTCPayServer.Tests/POSTests.cs index 07f68b56a..454835013 100644 --- a/BTCPayServer.Tests/POSTests.cs +++ b/BTCPayServer.Tests/POSTests.cs @@ -35,8 +35,7 @@ namespace BTCPayServer.Tests var appList = Assert.IsType(Assert.IsType(apps.ListApps(user.StoreId).Result).Model); var app = appList.Apps[0]; apps.HttpContext.SetAppData(new AppData { Id = app.Id, StoreDataId = app.StoreId, Name = app.AppName }); - var vmpos = Assert.IsType(Assert - .IsType(apps.UpdatePointOfSale(app.Id)).Model); + var vmpos = await apps.UpdatePointOfSale(app.Id).AssertViewModelAsync(); vmpos.Template = @" apple: price: 5.0 @@ -49,12 +48,9 @@ donation: custom: true "; Assert.IsType(apps.UpdatePointOfSale(app.Id, vmpos).Result); - vmpos = Assert.IsType(Assert - .IsType(apps.UpdatePointOfSale(app.Id)).Model); + vmpos = await apps.UpdatePointOfSale(app.Id).AssertViewModelAsync(); var publicApps = user.GetController(); - var vmview = - Assert.IsType(Assert - .IsType(publicApps.ViewPointOfSale(app.Id, PosViewType.Cart).Result).Model); + var vmview = await publicApps.ViewPointOfSale(app.Id, PosViewType.Cart).AssertViewModelAsync(); // apple shouldn't be available since we it's set to "disabled: true" above Assert.Equal(2, vmview.Items.Length);