Пример #1
0
        public void IndexTest()
        {
            var             mockS           = new Mock <IGuestService>();
            GuestController guestController = new GuestController(mockS.Object);

            var result = guestController.Index().Result as ViewResult;

            Assert.IsTrue(result.ViewData.ContainsKey("Succes"));
        }
        public void Index_ReturnsModelAndModelNotNull()
        {
            //Arrange
            var serCreatMoq = new Mock<IServiceCreator>();
            var commentServMoq = new Mock<ICommentsSerice>();
            serCreatMoq.Setup(m => m.CreateCommentService()).Returns(commentServMoq.Object);
            commentServMoq.Setup(m => m.GetComments()).Returns(GetComments());
            var controller = new GuestController(serCreatMoq.Object);

            //Act
            var result = controller.Index() as ViewResult;

            //Assert
            Assert.IsNotNull(result.Model);
        }
        public void Index_IsNotNull_ViewResultIsNotNull()
        {
            // arrange
            int             pageNumber   = 1;
            string          searchString = "";
            var             filter       = new GuestFilter();
            var             mock         = new Mock <IGuestService>();
            GuestController controller   = new GuestController(mock.Object);
            // act
            var result = controller.Index(searchString, pageNumber, filter);
            //assert
            var res = result as ViewResult;

            Assert.IsNotNull(res);
        }
        public void IndexPost_ReturnsModelAndModelNotNull()
        {
            //Arrange
            var serCreatMoq = new Mock<IServiceCreator>();
            var commentServMoq = new Mock<ICommentsSerice>();
            serCreatMoq.Setup(m => m.CreateCommentService()).Returns(commentServMoq.Object);
            commentServMoq.Setup(m => m.GetComments()).Returns(GetComments());
            var controller = new GuestController(serCreatMoq.Object);
            var newComment = new CommentsViewModel { NewCommentAuthor = "author1", NewCommentText = "test1" };

            //Act
            var result = controller.Index(newComment) as PartialViewResult;

            //Assert
            Assert.IsNotNull(result.Model);
        }
        public void IndexPost_CallAddCommentInCommentService()
        {
            //Arrange
            var serCreatMoq = new Mock<IServiceCreator>();
            var commentServMoq = new Mock<ICommentsSerice>();
            serCreatMoq.Setup(m => m.CreateCommentService()).Returns(commentServMoq.Object);
            commentServMoq.Setup(m => m.GetComments()).Returns(GetComments());
            var controller = new GuestController(serCreatMoq.Object);
            var newComment = new CommentsViewModel { NewCommentAuthor = "author1", NewCommentText = "test1" };

            //Act
            controller.Index(newComment);

            //Assert
            commentServMoq.Verify(m => m.AddComment(It.Is<CommentDTO>(c =>
                                c.Author == newComment.NewCommentAuthor &&
                                c.Text == newComment.NewCommentText)));
        }
        public void Index_CallsReadGuestService_WithFilter()
        {
            //Arrange
            var filter = new GuestFilter()
            {
                Name = "abc",
                Take = 1,
                Skip = 1
            };
            var guests       = GetTestsGuests();
            var guestService = new Mock <IGuestService>();

            guestService.Setup(s => s.ReadGuests(It.Is <GuestFilter>(f => f.Name == filter.Name && f.Take == filter.Take && f.Skip == filter.Skip)))
            .Returns((guests, guests.Count));
            var controller = new GuestController(guestService.Object);

            // Act
            var result = controller.Index("", null, filter);

            //Assert

            guestService.Verify(s => s.ReadGuests(filter), Times.Once);
        }