Example #1
0
        public void ShouldReturnJson_WhenCalledWithValidDataSourceRequest()
        {
            // Arrange
            var postsServiceMock = new Mock <IPostService>();

            postsServiceMock
            .Setup(m => m.GetById(It.IsAny <Guid>()))
            .Returns(new Post());
            postsServiceMock
            .Setup(m => m.HardDelete(It.IsAny <Post>()));
            var context = new Mock <HttpContextBase>();

            context.Setup(c => c.Cache)
            .Returns(new Cache());
            PostAdminController postAdminController = new PostAdminController(postsServiceMock.Object);

            postAdminController.ControllerContext = new ControllerContext(context.Object, new RouteData(), postAdminController);
            var postDetailsViewModel = new PostGridViewModel()
            {
                Id = "00000000-0000-0000-0000-000000000000"
            };

            // Act & Assert
            postAdminController
            .WithCallTo(c => c.HardDeletePost(postDetailsViewModel))
            .ShouldReturnJson();
        }
Example #2
0
        public void RenderDefaultView_WhenCalled()
        {
            // Arrange
            var postsServiceMock = new Mock <IPostService>();
            PostAdminController postAdminController = new PostAdminController(postsServiceMock.Object);

            // Act & Assert
            postAdminController
            .WithCallTo(c => c.Index())
            .ShouldRenderDefaultView();
        }
Example #3
0
        public void ShouldReturnJson_WhenCalledWithValidDataSourceRequest()
        {
            // Arrange
            var postDetailsViewModel = new PostGridViewModel();
            var mapperServiceMock    = new Mock <IMappingService>();

            mapperServiceMock.Setup(x => x.Map <PostGridViewModel>(It.IsAny <Post>())).Returns(postDetailsViewModel);
            MappingService.Provider = mapperServiceMock.Object;
            var postEnumerable = new List <Post>()
            {
                new Post()
            }.AsEnumerable <Post>();
            var postsServiceMock = new Mock <IPostService>();

            postsServiceMock.Setup(m => m.AllIncludingDeleted())
            .Returns(postEnumerable);
            PostAdminController postAdminController = new PostAdminController(postsServiceMock.Object);

            // Act & Assert
            postAdminController
            .WithCallTo(c => c.ReadPosts(new DataSourceRequest()))
            .ShouldReturnJson();
        }
Example #4
0
        public void ShouldReturnJson_WhenCalledWithValidDataSourceRequest()
        {
            // Arrange
            var postsServiceMock = new Mock <IPostService>();

            postsServiceMock
            .Setup(m => m.AddNewPost(
                       It.IsAny <string>(),
                       It.IsAny <string>(),
                       It.IsAny <string>(),
                       It.IsAny <string>()))
            .Returns(new Post());
            PostAdminController postAdminController = new PostAdminController(postsServiceMock.Object);
            var contextMock = new Mock <ControllerContext>();

            contextMock
            .SetupGet(p => p.HttpContext.User.Identity.Name)
            .Returns("username");
            postAdminController.ControllerContext = contextMock.Object;
            var postDetailsViewModel = new PostGridViewModel()
            {
                Title       = string.Empty,
                Description = string.Empty,
                Content     = string.Empty
            };
            var mapperServiceMock = new Mock <IMappingService>();

            mapperServiceMock
            .Setup(x => x.Map <PostGridViewModel>(It.IsAny <Post>()))
            .Returns(postDetailsViewModel);
            MappingService.Provider = mapperServiceMock.Object;

            // Act & Assert
            postAdminController
            .WithCallTo(c => c.CreatePost(postDetailsViewModel))
            .ShouldReturnJson();
        }
Example #5
0
        public void ShouldReturnJson_WhenCalledWithValidViewModelData()
        {
            // Arrange
            var postsServiceMock = new Mock <IPostService>();

            postsServiceMock
            .Setup(m => m.GetById(It.IsAny <Guid>()))
            .Returns(new Post());
            postsServiceMock
            .Setup(m => m.Update(It.IsAny <Post>()));
            PostAdminController postAdminController = new PostAdminController(postsServiceMock.Object);
            var postDetailsViewModel = new PostGridViewModel()
            {
                Id          = "00000000-0000-0000-0000-000000000000",
                Title       = string.Empty,
                Description = string.Empty,
                Content     = string.Empty
            };

            // Act & Assert
            postAdminController
            .WithCallTo(c => c.UpdatePost(postDetailsViewModel))
            .ShouldReturnJson();
        }