public IActionResult GetWatchOnlyWallet() { try { // Map a watch-only wallet to a model object for display in the front end. var watchOnlyWallet = this.watchOnlyWalletManager.GetWatchOnlyWallet(); WatchOnlyWalletModel model = new WatchOnlyWalletModel { CoinType = watchOnlyWallet.CoinType, Network = watchOnlyWallet.Network, CreationTime = watchOnlyWallet.CreationTime }; foreach (var watchAddress in watchOnlyWallet.WatchedAddresses) { WatchedAddressModel watchedAddressModel = new WatchedAddressModel { Address = watchAddress.Value.Address, Transactions = new List <TransactionModel>() }; foreach (var transactionData in watchAddress.Value.Transactions) { Transaction transaction = watchOnlyWallet.Network.CreateTransaction(transactionData.Value.Hex); watchedAddressModel.Transactions.Add(new TransactionBriefModel(transaction, watchOnlyWallet.Network)); } model.WatchedAddresses.Add(watchedAddressModel); } foreach (var transactionData in watchOnlyWallet.WatchedTransactions) { Transaction transaction = watchOnlyWallet.Network.CreateTransaction(transactionData.Value.Hex); WatchedTransactionModel watchedTransactionModel = new WatchedTransactionModel { Transaction = new TransactionBriefModel(transaction, watchOnlyWallet.Network) }; model.WatchedTransactions.Add(watchedTransactionModel); } return(this.Json(model)); } catch (Exception e) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public void Given_NoExceptionIsThrown_When_GetWatchOnlyWalletIsCalled_Then_WatchOnlyWalletModelIsReturned() { var mockWalletManager = new Mock <IWatchOnlyWalletManager>(); mockWalletManager.Setup(wallet => wallet.GetWatchOnlyWallet()).Returns(new Features.WatchOnlyWallet.WatchOnlyWallet()); var controller = new WatchOnlyWalletController(mockWalletManager.Object); IActionResult result = controller.GetWatchOnlyWallet(); mockWalletManager.VerifyAll(); Assert.NotNull(result); JsonResult viewResult = Assert.IsType <JsonResult>(result); WatchOnlyWalletModel resultValue = Assert.IsType <WatchOnlyWalletModel>(viewResult.Value); Assert.NotNull(resultValue); }