public void Index_PassesOrderedListOfBrewersInViewResultModelAndStoresTotalTurnoverInViewData()
        {
            //aarange
            //  _brewerRepository.Setup(m => m.GetAll()).Returns(_dummyContext.Brewers);
            Brewer bavik = new Brewer("Bavik")
            {
                BrewerId = 1
            };
            Brewer moortgat = new Brewer("Duvel Moortgat")
            {
                BrewerId = 2
            };

            _brewerRepository.Setup(m => m.GetAll()).Returns(new List <Brewer>()
            {
                bavik, moortgat
            });

            //act
            //IActionResult result = _controller.Index();
            var result         = Assert.IsType <ViewResult>(_controller.Index());
            var brewersInModel = Assert.IsType <List <Brewer> >(result.Model);

            //assert

            Assert.Equal(2, brewersInModel.Count);
            Assert.Equal("Bavik", brewersInModel[0].Name);
            Assert.Equal("Duvel Moortgat", brewersInModel[1].Name);
            Assert.Equal(0, result.ViewData["TotalTurnover"]);
        }
Ejemplo n.º 2
0
        public void IndexMustPassOrderedListOfBrewersInViewResultModel()
        {
            _brewerRepository.Setup(m => m.GetAll()).Returns(_dummyContext.Brewers);
            IActionResult  actionresult   = _controller.Index();
            IList <Brewer> brewersInModel = (actionresult as ViewResult)?.Model as IList <Brewer>;

            Assert.Equal(3, brewersInModel?.Count);
            Assert.Equal("Bavik", brewersInModel?[0].Name);
            Assert.Equal("De Leeuw", brewersInModel?[1].Name);
            Assert.Equal("Duvel Moortgat", brewersInModel?[2].Name);
        }
        public void Index_PassesOrderedListOfBrewersInViewResultModelAndStoresTotalTurnoverInViewData()
        {
            _brewerRepository.Setup(m => m.GetAll()).Returns(_dummyContext.Brewers);
            var result         = Assert.IsType <ViewResult>(_controller.Index());
            var brewersInModel = Assert.IsType <List <Brewer> >(result.Model);

            Assert.Equal(3, brewersInModel.Count);
            Assert.Equal("Bavik", brewersInModel[0].Name);
            Assert.Equal("De Leeuw", brewersInModel[1].Name);
            Assert.Equal("Duvel Moortgat", brewersInModel[2].Name);
            Assert.Equal(20050000, result.ViewData["TotalTurnover"]);
        }