public void ProcessGenerateWallet_ShouldSuccessfullyGenerateAWallet() { // Arrange var args = new[] { "wallet-file=wallet.json", }; var expectedPathToFile = Path.Combine("Wallets", "wallet.json"); var password = new SecureString(); password.AppendChar('p'); password.AppendChar('a'); password.AppendChar('s'); password.AppendChar('s'); password.AppendChar('w'); password.AppendChar('o'); password.AppendChar('r'); password.AppendChar('d'); IBitcoinLibrary bitcoinLibrary = new BitcoinLibrary(); // Act var mnemonic = bitcoinLibrary.GenerateWallet(args, password); // Assert mnemonic.Should().NotBeNull(); mnemonic.Split(",").Length.Should().Be(12); File.Exists(expectedPathToFile).Should().BeTrue(); // Cleanup // Ensure Wallets directory doesn't already exist Directory.Delete("Wallets", true); }
public void ProcessGenerateWallet_ShouldThrowAnExceptionIfWalletAlreadyExists() { // Arrange const string walletDirectory = "Wallets"; Directory.CreateDirectory(walletDirectory); const string walletFileName = "wallet_generate_test.json"; using (File.Create(Path.Combine(walletDirectory, walletFileName))) { } var args = new[] { $"wallet-file={walletFileName}", }; var password = new SecureString(); password.AppendChar('p'); password.AppendChar('a'); password.AppendChar('s'); password.AppendChar('s'); password.AppendChar('w'); password.AppendChar('o'); password.AppendChar('r'); password.AppendChar('d'); IBitcoinLibrary bitcoinLibrary = new BitcoinLibrary(); try { // Act bitcoinLibrary.GenerateWallet(args, password); // Should not get here - Force a fail if we do bitcoinLibrary.Should().BeNull(); } catch (WalletAlreadyExistsException ex) { // Assert ex.Message.Should().Be("The request to generate a wallet failed because the wallet already exists."); } catch (Exception ex) { // Should not get here. ex.Should().BeNull(); } // Cleanup Directory.Delete("Wallets", true); File.Delete(walletFileName); // Default results in locally created wallet file. }
public void ProcessGenerateWallet_ShouldThrowAnExceptionIfArgumentIsInvalid() { // Arrange var args = new[] { "wallet-fi=", // Invalid spelling of 'wallet-file' }; var password = new SecureString(); password.AppendChar('p'); password.AppendChar('a'); password.AppendChar('s'); password.AppendChar('s'); password.AppendChar('w'); password.AppendChar('o'); password.AppendChar('r'); password.AppendChar('d'); IBitcoinLibrary bitcoinLibrary = new BitcoinLibrary(); try { // Act bitcoinLibrary.GenerateWallet(args, password); // Should not get here - Force a fail if we do bitcoinLibrary.Should().BeNull(); } catch (GenerateWalletFailedException ex) { // Assert ex.Message.Should().Be("Could not generate wallet 'wallet-file' argument is invalid."); } catch (Exception ex) { // Should not get here. ex.Should().BeNull(); } // Cleanup File.Delete("BitcoinWallet.json"); }