public MainWindowViewModel(IFundViewModel fundViewModel, ISummaryViewModel summaryViewModel, IAddStockViewModel addStockViewModel) { // This is painful to look at, and we should really use DI here with a proper composition root and bindings and everything, // but I couldn't bring myself to also introduce a DI container here. This solution feels slightly bloated as it is. // I hope the overall design that I strove for in the Domain Model will demonstrate my awareness of the concept. //Fund = new FundViewModel(TestDataProvider.CreateTestFund()); //Summary = new SummaryViewModel(Fund.GetStocksFunc); //AddStock = new AddStockViewModel(_addStockHelper); //_addStockHelper = addStockHelper; AddStock = addStockViewModel; Fund = fundViewModel; Summary = summaryViewModel; }
public void ValidateOnFundChangedEventHandler() { _fundServiceMock.Setup(f => f.AllTotals()).Returns(new[] { new TotalStocksModel() { Type = null, Number = 100, MarketValue = 200, StockWeight = 300 }, new TotalStocksModel() { Type = StockType.Bond, Number = 40, MarketValue = 200, StockWeight = 300 }, new TotalStocksModel() { Type = StockType.Equity, Number = 60, MarketValue = 200, StockWeight = 300 }, }); _fundChangedEventMock.Setup(e => e.Subscribe(It.IsAny <Action>(), It.IsAny <bool>())).Callback( (Action act, bool keep) => { _model.OnFundChanged(); }); _model = new FundViewModel(_eventAggregatorMock.Object, _fundServiceMock.Object, new StockConverter()); Assert.That(_model.FundSummaryItems, Is.NaN); Assert.That(_model.FundSummaryItems.Count(), Is.EqualTo(3)); Assert.That(_model.FundSummaryItems.Count(t => t.Type == null), Is.EqualTo(1)); Assert.That(_model.FundSummaryItems.Count(t => t.Type == StockType.Bond), Is.EqualTo(1)); Assert.That(_model.FundSummaryItems.Count(t => t.Type == StockType.Equity), Is.EqualTo(1)); }