Пример #1
0
        public void ConstructorShould_SetPassedDataCorrectlly_WhenDataIsNotNull()
        {
            var serviceMock = new Mock <ISearchService>();

            var controller = new Web.Controllers.SearchController(serviceMock.Object);

            Assert.IsNotNull(controller);
        }
Пример #2
0
        public void GetSearchShould_CallSearchServiceMethodFindAll(string category,
                                                                   string searchBy, string pattern)
        {
            var serviceMock = new Mock <ISearchService>();

            InitializeMapper();

            var controller = new Web.Controllers.SearchController(serviceMock.Object);

            controller.Search(category, searchBy, pattern);

            serviceMock.Verify(s => s.FindBy(category, searchBy, pattern), Times.Once);
        }
Пример #3
0
        public void PostSearchShould_RedirectToGetSearchWithCorrectParameters(string category,
                                                                              string searchBy, string pattern)
        {
            var serviceMock = new Mock <ISearchService>();
            var controller  = new Web.Controllers.SearchController(serviceMock.Object);
            var viewModel   = new SearchViewModel()
            {
                Category = category,
                SearchBy = searchBy,
                Pattern  = pattern
            };

            controller.WithCallTo(c => c.Search(viewModel))
            .ShouldRedirectTo((Web.Controllers.SearchController c) => c.Search(viewModel.Category,
                                                                               viewModel.SearchBy, viewModel.Pattern, 10, 1));
        }
Пример #4
0
        public void GetSearchShould_ReturnCorrectView(string category,
                                                      string searchBy, string pattern)
        {
            var serviceMock = new Mock <ISearchService>();

            InitializeMapper();

            var list = new List <Place>()
            {
                new Place()
                {
                    Name = "Pesho's restaurant",
                    Type = "Restaurant"
                }
            };
            var expectedModel = new List <PlaceShortViewModel>()
            {
                new PlaceShortViewModel()
                {
                    Name = "Pesho's restaurant"
                }
            }.ToPagedList(1, 1);


            serviceMock.Setup(s => s.FindBy(category, searchBy, pattern))
            .Returns(list.AsQueryable());

            var controller = new Web.Controllers.SearchController(serviceMock.Object);

            controller
            .WithCallTo(c => c.Search(category, searchBy, pattern, 1, 1))
            .ShouldRenderView("List");
            //.WithModel<PagedList.IPagedList<FindAndBook.Web.Models.Places.PlaceShortViewModel>>(m =>
            //{
            //    CollectionAssert.AreEqual(expectedModel, m);
            //});
        }