public void Index_WhenCreatingViewModel_ShouldCreateModel() { var markets = new List<IMarket> { _currentMarket, _market }; var expectedModel = new MarketViewModel() { ContentLink = _contentLink, MarketId = _currentMarket.MarketId.Value, Markets = markets.Select(x => new SelectListItem { Selected = false, Text = x.MarketName, Value = x.MarketId.Value }) }; _mockCurrentMarket.Setup(x => x.GetCurrentMarket()).Returns(_currentMarket); _mockMarketService.Setup(x => x.GetAllMarkets()).Returns(markets); var subject = CreateController(); var result = ((PartialViewResult)subject.Index(_contentLink)).Model as MarketViewModel; result.ShouldBeEquivalentTo(expectedModel); }
public ActionResult Index(ContentReference contentLink) { var model = new MarketViewModel { Markets = _marketService.GetAllMarkets().Where(x => x.IsEnabled).OrderBy(x => x.MarketName) .Select(x => new SelectListItem { Selected = false, Text = x.MarketName, Value = x.MarketId.Value }), MarketId = _currentMarket.GetCurrentMarket().MarketId.Value, ContentLink = contentLink }; return PartialView(model); }