Esempio n. 1
0
        public void Index()
        {
            // arrange
            var mockUserRep  = new Mock <IUserRepository>();
            var mockPhotoRep = new Mock <IPhotoRepository>();
            var mockLogger   = new Mock <INRAKOLogger>();
            var mockS3Amazon = new Mock <AmazonS3Tools>();
            var mockMutation = new Mock <IMutationActionFactorySelector>();

            mockUserRep.Setup(x => x.GetUser(null)).Returns((NRAKOUser)null);
            mockPhotoRep.Setup(x => x.GetPhotos()).Returns(GetPhotos());
            mockPhotoRep.Setup(x => x.PhotoDefaultIfEmpty()).Returns(new List <Photo>()
            {
                new Photo {
                    Size = 0, Width = 0, Height = 0
                }
            });

            var controller = new PhotosController(mockUserRep.Object, mockPhotoRep.Object, mockLogger.Object, mockS3Amazon.Object, mockMutation.Object);

            // act
            var result = controller.Index();
            // assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <List <PhotoViewModel> >(
                viewResult.ViewData.Model);

            Assert.Equal(2, model.Count);
        }
Esempio n. 2
0
        public void IndexReturnsView()
        {
            var options = CreateNewContextOptions();

            // Run the test against one instance of the context
            using (var context = new PhotoSharingContext(options))
            {
                using (PhotosController controller = new PhotosController(context))
                {
                    var result = (controller.Index()) as ViewResult;
                    Assert.Equal(nameof(controller.Index), result.ViewName);
                }
            }
        }