コード例 #1
0
        public void ReturnViewWithModelWithCorrectCollection()
        {
            // Arrange
            var mockedMappingService       = new Mock <IMappingService>();
            var mockedPictureService       = new Mock <IPictureService>();
            IEnumerable <Picture> pictures = new List <Picture>()
            {
                new Picture()
            };
            IEnumerable <PictureViewModel> viewModelPictures = new List <PictureViewModel>()
            {
                new PictureViewModel()
            };

            mockedPictureService.Setup(x => x.GetAllPictures()).Returns(pictures);
            mockedMappingService.Setup(x => x.Map <IEnumerable <PictureViewModel> >(It.IsAny <IEnumerable <Picture> >())).Returns(viewModelPictures);

            var controller = new PicturesController(mockedMappingService.Object, mockedPictureService.Object);

            // Act & Assert
            controller.WithCallTo(x => x.Index())
            .ShouldRenderDefaultView()
            .WithModel(viewModelPictures);
        }