public async Task AccountPreferences()
        {
            // Arrange
            var exchangeApi         = ExchangeServiceHelper.GetExchangeService(ExchangeServiceType.SymbolsViewModel);
            var exchangeService     = new WpfExchangeService(exchangeApi);
            var symbolsCacheFactory = SymbolsCacheFactoryHelper.GetSymbolsCachefactory(exchangeService);
            var symbolsViewModel    = new SymbolsViewModel(exchangeService, symbolsCacheFactory, new DebugLogger());

            var userData = File.ReadAllText("UserAccounts.txt");
            var accounts = JsonConvert.DeserializeObject <UserAccounts>(userData);

            var account = accounts.Accounts.First();

            // Act
            await symbolsViewModel.SetAccount(account);

            await Task.Delay(1000);

            // Assert
            var favourites = from s in symbolsViewModel.Symbols
                             join f in account.Preferences.FavouriteSymbols on s.Name equals f
                             select s;

            foreach (var favourite in favourites)
            {
                Assert.IsNotNull(symbolsViewModel.Symbols.First(s => s.Name.Equals(favourite.Name)));
            }

            Assert.AreEqual(symbolsViewModel.SelectedSymbol.Name, account.Preferences.SelectedSymbol);
        }
Example #2
0
        public async Task Login_AccountInfo_Update()
        {
            // Arrange
            var    fail                = false;
            var    hasUpdated          = false;
            string errorMessage        = string.Empty;
            var    exchangeApi         = ExchangeServiceHelper.GetExchangeService(ExchangeServiceType.SubscribeAccountInfo);
            var    exchangeService     = new WpfExchangeService(exchangeApi);
            var    symbolsCacheFactory = SymbolsCacheFactoryHelper.GetSymbolsCachefactory(exchangeService);
            var    accountViewModel    = new AccountBalancesViewModel(exchangeService, symbolsCacheFactory, new DebugLogger());

            var account = new Account(new Core.Model.AccountInfo {
                User = new Core.Model.User()
            })
            {
                ApiKey    = "apikey",
                ApiSecret = "apisecret"
            };

            accountViewModel.Account = account;

            var accountObservable = Observable.FromEventPattern <AccountEventArgs>(
                eventHandler => accountViewModel.OnAccountNotification += eventHandler,
                eventHandler => accountViewModel.OnAccountNotification -= eventHandler)
                                    .Select(eventPattern => eventPattern.EventArgs);

            accountObservable.Subscribe(args =>
            {
                if (args.AccountEventType.Equals(AccountEventType.LoggedIn))
                {
                    // expected
                }
                else if (args.AccountEventType.Equals(AccountEventType.UpdateOrders))
                {
                    hasUpdated = true;
                }
                else
                {
                    fail = true;
                }
            });

            // Act
            await accountViewModel.Login(account);

            // Assert
            var btc  = accountViewModel.Account.Balances.SingleOrDefault(ab => ab.Asset.Equals("BTC"));
            var bcpt = accountViewModel.Account.Balances.SingleOrDefault(ab => ab.Asset.Equals("BCPT"));
            var test = accountViewModel.Account.Balances.SingleOrDefault(ab => ab.Asset.Equals("TEST"));

            Assert.IsTrue(hasUpdated);
            Assert.IsNull(btc);
            Assert.IsNull(bcpt);
            Assert.IsNotNull(test);
            Assert.IsTrue(accountViewModel.Account.Balances.Count().Equals(5));
            Assert.IsFalse(fail);
        }
        public async Task SelectedSymbol()
        {
            // Arrange
            var    fail                = false;
            Symbol selectedSymbol      = null;
            var    exchangeApi         = ExchangeServiceHelper.GetExchangeService(ExchangeServiceType.SymbolsViewModel);
            var    exchangeService     = new WpfExchangeService(exchangeApi);
            var    symbolsCacheFactory = SymbolsCacheFactoryHelper.GetSymbolsCachefactory(exchangeService);
            var    symbolsViewModel    = new SymbolsViewModel(exchangeService, symbolsCacheFactory, new DebugLogger());

            var symbolsObservable = Observable.FromEventPattern <SymbolsEventArgs>(
                eventHandler => symbolsViewModel.OnSymbolsNotification += eventHandler,
                eventHandler => symbolsViewModel.OnSymbolsNotification -= eventHandler)
                                    .Select(eventPattern => eventPattern.EventArgs);

            symbolsObservable.Subscribe((args) =>
            {
                if (args.Value != null)
                {
                    selectedSymbol = args.Value;
                }
                else if (args.Symbols.Any())
                {
                    // expected
                }
                else
                {
                    fail = true;
                }
            });

            var userAccount = new UserAccount
            {
                Preferences = new Preferences {
                    SelectedSymbol = "BNBBTC",
                }
            };

            userAccount.Preferences.FavouriteSymbols.Add("BNBBTC");
            userAccount.Preferences.FavouriteSymbols.Add("TRXBTC");

            await symbolsViewModel.SetAccount(userAccount);

            await Task.Delay(1000);

            // Act
            var trx = symbolsViewModel.Symbols.Single(s => s.Name.Equals("TRXBTC"));

            symbolsViewModel.SelectedSymbol = trx;

            // Assert
            Assert.AreEqual(symbolsViewModel.SelectedSymbol, selectedSymbol);
            Assert.IsFalse(fail);
        }
Example #4
0
        public async Task SelectedAsset()
        {
            // Arrange
            var            fail = false;
            AccountBalance selectedAccountBalance = null;
            var            exchangeApi            = ExchangeServiceHelper.GetExchangeService();
            var            exchangeService        = new WpfExchangeService(exchangeApi);
            var            symbolsCacheFactory    = SymbolsCacheFactoryHelper.GetSymbolsCachefactory(exchangeService);
            var            accountViewModel       = new AccountBalancesViewModel(exchangeService, symbolsCacheFactory, new DebugLogger());

            var account = new Account(new Core.Model.AccountInfo {
                User = new Core.Model.User()
            })
            {
                ApiKey    = "apikey",
                ApiSecret = "apisecret"
            };

            accountViewModel.Account = account;

            var accountObservable = Observable.FromEventPattern <AccountEventArgs>(
                eventHandler => accountViewModel.OnAccountNotification += eventHandler,
                eventHandler => accountViewModel.OnAccountNotification -= eventHandler)
                                    .Select(eventPattern => eventPattern.EventArgs);

            accountObservable.Subscribe(args =>
            {
                if (args.AccountEventType.Equals(AccountEventType.LoggedIn))
                {
                    // expected
                }
                else if (args.AccountEventType.Equals(AccountEventType.SelectedAsset))
                {
                    selectedAccountBalance = args.SelectedAsset;
                }
                else
                {
                    fail = true;
                }
            });

            // Act
            await accountViewModel.Login(account);

            var trx = accountViewModel.Account.Balances.Single(ab => ab.Asset.Equals("TRX"));

            accountViewModel.SelectedAsset = trx;

            // Assert
            Assert.AreEqual(selectedAccountBalance, trx);
            Assert.IsFalse(fail);
        }
Example #5
0
        public async Task SymbolsViewModel_SetAccount()
        {
            // Arrange
            var fail                = false;
            var exchangeApi         = ExchangeServiceHelper.GetExchangeService(ExchangeServiceType.SymbolsViewModel);
            var exchangeService     = new WpfExchangeService(exchangeApi);
            var symbolsCacheFactory = SymbolsCacheFactoryHelper.GetSymbolsCachefactory(exchangeService);

            // Act
            var symbolsViewModel = new SymbolsViewModel(exchangeService, symbolsCacheFactory, new DebugLogger());

            var symbolsObservable = Observable.FromEventPattern <SymbolsEventArgs>(
                eventHandler => symbolsViewModel.OnSymbolsNotification += eventHandler,
                eventHandler => symbolsViewModel.OnSymbolsNotification -= eventHandler)
                                    .Select(eventPattern => eventPattern.EventArgs);

            symbolsObservable.Subscribe((args) =>
            {
                if (args.Symbols != null || // OnLoadedSymbols
                    args.Value.Name.Equals("BNBBTC"))    // OnSelectedSymbol
                {
                    // expected
                }
                else
                {
                    fail = true;
                }
            });

            await symbolsViewModel.SetAccount(
                new UserAccount
            {
                Preferences = new Preferences
                {
                    SelectedSymbol   = "BNBBTC",
                    FavouriteSymbols = new ObservableCollection <string>(new[] { "BNBBTC", "TRXBTC" })
                }
            });

            await Task.Delay(1000);

            // Assert
            Assert.AreEqual(symbolsViewModel.Symbols.Count, 2);
            Assert.IsNotNull(symbolsViewModel.AccountPreferences);
            Assert.IsNotNull(symbolsViewModel.SelectedSymbol);
            Assert.AreEqual(symbolsViewModel.SelectedSymbol.Name, "BNBBTC");
            Assert.IsFalse(fail);
        }
Example #6
0
        public async Task Login()
        {
            // Arrange
            var     fail                = false;
            Account notifyAccount       = null;
            var     exchangeApi         = ExchangeServiceHelper.GetExchangeService();
            var     exchangeService     = new WpfExchangeService(exchangeApi);
            var     symbolsCacheFactory = SymbolsCacheFactoryHelper.GetSymbolsCachefactory(exchangeService);
            var     accountViewModel    = new AccountViewModel(exchangeService, symbolsCacheFactory, new DebugLogger());

            var account = new Account(new Core.Model.AccountInfo {
                User = new Core.Model.User()
            })
            {
                ApiKey    = "apikey",
                ApiSecret = "apisecret"
            };

            var accountObservable = Observable.FromEventPattern <AccountEventArgs>(
                eventHandler => accountViewModel.OnAccountNotification += eventHandler,
                eventHandler => accountViewModel.OnAccountNotification -= eventHandler)
                                    .Select(eventPattern => eventPattern.EventArgs);

            accountObservable.Subscribe(args =>
            {
                if (args.AccountEventType.Equals(AccountEventType.LoggedIn))
                {
                    notifyAccount = args.Value;
                }
                else
                {
                    fail = true;
                }
            });

            // Act
            await accountViewModel.Login(account);

            // Assert
            Assert.AreEqual(account.ApiKey, accountViewModel.Account.ApiKey);
            Assert.AreEqual(account.AccountInfo.User.ApiSecret, accountViewModel.Account.AccountInfo.User.ApiSecret);
            Assert.IsNotNull(notifyAccount);
            Assert.AreEqual(account.ApiKey, notifyAccount.ApiKey);
            Assert.AreEqual(account.AccountInfo.User.ApiSecret, notifyAccount.AccountInfo.User.ApiSecret);
            Assert.IsFalse(fail);
        }