Example #1
0
        public SearchResultVM GetSearchResultVM(SearchBM bind)
        {
            IEnumerable <LostPet>  lostPets  = this.Context.LostPets;
            IEnumerable <FoundPet> foundPets = this.Context.FoundPets;

            IEnumerable <SearchedLostPetVM>  lostVM  = Mapper.Map <IEnumerable <LostPet>, IEnumerable <SearchedLostPetVM> >(lostPets);
            IEnumerable <SearchedFoundPetVM> foundVM = Mapper.Map <IEnumerable <FoundPet>, IEnumerable <SearchedFoundPetVM> >(foundPets);

            foreach (var lostPet in lostVM)
            {
                lostPet.SearchScore = GetLostPetSearchScore(lostPet, bind.SearchContent.ToLower());
            }

            foreach (var foundPet in foundVM)
            {
                foundPet.SearchScore = GetFoundPetSearchScore(foundPet, bind.SearchContent.ToLower());
            }

            lostVM  = lostVM.Where(p => p.SearchScore > 0).OrderByDescending(p => p.SearchScore);
            foundVM = foundVM.Where(p => p.SearchScore > 0).OrderByDescending(p => p.SearchScore);

            SearchResultVM vm = new SearchResultVM
            {
                FoundPets = foundVM,
                LostPets  = lostVM
            };

            return(vm);
        }
Example #2
0
        public void Search_ShouldFindResults()
        {
            SearchBM bm = new SearchBM()
            {
                SearchContent = "South Park"
            };

            this._controller.WithCallTo(c => c.Search(bm)).ShouldRenderDefaultView()
            .WithModel <SearchResultVM>(r => (r.FoundPets.Count() > 0) || (r.LostPets.Count() > 0));
        }
Example #3
0
        public void Search_ShouldReturnRightVm()
        {
            SearchBM bm = new SearchBM()
            {
                SearchContent = "South Park"
            };

            this._controller.WithCallTo(c => c.Search(bm)).ShouldRenderDefaultView()
            .WithModel <SearchResultVM>();
        }
Example #4
0
        public ActionResult Search(SearchBM bind)
        {
            SearchResultVM vm = this.service.GetSearchResultVM(bind);

            return(View(vm));
        }