public async Task Saving_should_save_the_assets_till_next_load() { var viewModel = new MainViewModel(); await viewModel.Load(); viewModel.NewAssetSymbol = "MSFT"; viewModel.NewAssetAmount = 100; await viewModel.AddAsset(); await viewModel.Save(); viewModel.NewAssetSymbol = "AAPL"; viewModel.NewAssetAmount = 10; await viewModel.AddAsset(); await viewModel.Load(); viewModel.Portfolio.Assets.Should().BeEquivalentTo(new Asset(new Symbol("MSFT"), 100)); }
public async Task Adding_invalid_asset_should_set_error_message() { var viewModel = new MainViewModel(); await viewModel.Load(); viewModel.ErrorMessage.Should().BeNull(); using (IMonitor <MainViewModel> viewModelMonitored = viewModel.Monitor()) { viewModel.NewAssetSymbol = "MSFT"; viewModel.NewAssetAmount = -10; await viewModel.AddAsset(); viewModelMonitored.Should().RaisePropertyChangeFor(vm => vm.ErrorMessage); viewModel.ErrorMessage.Should().NotBeNull(); } }
public async Task Adding_an_asset_should_change_the_portfolio_assets_and_fire_property_changed_event() { // ReSharper disable once ConvertToLocalFunction QuoteLoaderDelegate quoteLoaderPrice100 = symbols => Task.FromResult(symbols.Select(symbol => new Quote(symbol, 100))); var viewModel = new MainViewModel(new PortfolioWithValue(quoteLoaderPrice100)); await viewModel.Load(); using (IMonitor <MainViewModel> viewModelMonitored = viewModel.Monitor()) { viewModel.NewAssetSymbol = "MSFT"; viewModel.NewAssetAmount = 100; await viewModel.AddAsset(); viewModelMonitored.Should().RaisePropertyChangeFor(vm => vm.PortfolioDescription); viewModel.Portfolio.Assets.Should().BeEquivalentTo(new Asset(new Symbol("MSFT"), 100)); viewModelMonitored.Should().RaisePropertyChangeFor(vm => vm.PortfolioValueDescription); viewModel.TotalValue.Should().Be(10000); } }