public async Task CanToggleCoinSwitchPaymentMethod() { using (var tester = ServerTester.Create()) { await tester.StartAsync(); var user = tester.NewAccount(); user.GrantAccess(); var controller = tester.PayTester.GetController <StoresController>(user.UserId, user.StoreId); var updateModel = new UpdateCoinSwitchSettingsViewModel() { MerchantId = "aaa", Enabled = true }; Assert.Equal("UpdateStore", Assert.IsType <RedirectToActionResult>( await controller.UpdateCoinSwitchSettings(user.StoreId, updateModel, "save")).ActionName); var store = await tester.PayTester.StoreRepository.FindStore(user.StoreId); Assert.True(store.GetStoreBlob().CoinSwitchSettings.Enabled); updateModel.Enabled = false; Assert.Equal("UpdateStore", Assert.IsType <RedirectToActionResult>( await controller.UpdateCoinSwitchSettings(user.StoreId, updateModel, "save")).ActionName); store = await tester.PayTester.StoreRepository.FindStore(user.StoreId); Assert.False(store.GetStoreBlob().CoinSwitchSettings.Enabled); } }
public async void CanSetCoinSwitchPaymentMethod() { using (var tester = ServerTester.Create()) { tester.Start(); var user = tester.NewAccount(); user.GrantAccess(); var controller = tester.PayTester.GetController <StoresController>(user.UserId, user.StoreId); var storeBlob = controller.StoreData.GetStoreBlob(); Assert.Null(storeBlob.CoinSwitchSettings); var updateModel = new UpdateCoinSwitchSettingsViewModel() { MerchantId = "aaa", }; Assert.Equal("UpdateStore", Assert.IsType <RedirectToActionResult>( await controller.UpdateCoinSwitchSettings(user.StoreId, updateModel, "save")).ActionName); var store = await tester.PayTester.StoreRepository.FindStore(user.StoreId); storeBlob = controller.StoreData.GetStoreBlob(); Assert.NotNull(storeBlob.CoinSwitchSettings); Assert.NotNull(storeBlob.CoinSwitchSettings); Assert.IsType <CoinSwitchSettings>(storeBlob.CoinSwitchSettings); Assert.Equal(storeBlob.CoinSwitchSettings.MerchantId, updateModel.MerchantId); } }
private void SetExistingValues(StoreData store, UpdateCoinSwitchSettingsViewModel vm) { var existing = store.GetStoreBlob().CoinSwitchSettings; if (existing == null) { return; } vm.MerchantId = existing.MerchantId; vm.Enabled = existing.Enabled; vm.Mode = existing.Mode; }
public IActionResult UpdateCoinSwitchSettings(string storeId) { var store = HttpContext.GetStoreData(); if (store == null) { return(NotFound()); } UpdateCoinSwitchSettingsViewModel vm = new UpdateCoinSwitchSettingsViewModel(); SetExistingValues(store, vm); return(View(vm)); }
public async Task <IActionResult> UpdateCoinSwitchSettings(string storeId, UpdateCoinSwitchSettingsViewModel vm, string command) { var store = HttpContext.GetStoreData(); if (store == null) { return(NotFound()); } if (vm.Enabled) { if (!ModelState.IsValid) { return(View(vm)); } } var coinSwitchSettings = new CoinSwitchSettings() { MerchantId = vm.MerchantId, Enabled = vm.Enabled, Mode = vm.Mode, AmountMarkupPercentage = vm.AmountMarkupPercentage }; switch (command) { case "save": var storeBlob = store.GetStoreBlob(); storeBlob.CoinSwitchSettings = coinSwitchSettings; store.SetStoreBlob(storeBlob); await _Repo.UpdateStore(store); TempData[WellKnownTempData.SuccessMessage] = "CoinSwitch settings modified"; return(RedirectToAction(nameof(UpdateStore), new { storeId })); default: return(View(vm)); } }