コード例 #1
0
ファイル: HomeService.cs プロジェクト: Martinik/PetHome
        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);
        }
コード例 #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));
        }
コード例 #3
0
        public void Search_ShouldReturnRightVm()
        {
            SearchBM bm = new SearchBM()
            {
                SearchContent = "South Park"
            };

            this._controller.WithCallTo(c => c.Search(bm)).ShouldRenderDefaultView()
            .WithModel <SearchResultVM>();
        }
コード例 #4
0
ファイル: HomeController.cs プロジェクト: Martinik/PetHome
        public ActionResult Search(SearchBM bind)
        {
            SearchResultVM vm = this.service.GetSearchResultVM(bind);

            return(View(vm));
        }