public async Task <ActionResult> HandleForm(GoogleSearchRequest googlesearchrequest)
        {
            GoogleSearchAPIRequest obj_APIRequest = new GoogleSearchAPIRequest(googlesearchrequest.SearchTerms, 1);

            GoogleSearchResponse obj_Response = new GoogleSearchResponse(googlesearchrequest.UrlToFind);

            bool b_NoSearchError = true; // flag for any errors picked up during GoofgleSearchAPI requests.
            int  int_StartIndex  = 1;    // index in Google Search is 1-based not zero-based. So we start at 1 instead of zero.

            while (int_StartIndex <= 91 && b_NoSearchError)
            {
                await obj_APIRequest.FireAPISeachRequest();

                while (obj_APIRequest.RequestInProcess())
                {
                }

                if (obj_APIRequest.APIRequestState == GoogleSearchAPIRequest.GoogleSearchAPIRequestState.ResponseComplete) // if request returned successfully, process the result
                {
                    // Process the actual JSON string returned from the GoogleSearchAPI.
                    // Parse it into a custom object we can utitlise to access the results more easily.
                    obj_Response.AddResultsFromAPI_JSONResponse(obj_APIRequest.GetAPISearchResponse());
                }
                else
                {
                    b_NoSearchError = false;
                    //_lbl_ResponseAsText.Text = _obj_SearchRequest.GetAPISearchError();
                }

                int_StartIndex += obj_APIRequest.ResultsPerRequest;
            }

            return(View("Results", obj_Response));
        }
Пример #2
0
        public void RenderSearchResult(GoogleSearchResponse response)
        {
            ((JTemplatePlugin)JQueryFactory.JQuery(JQuerySelectors.SEARCH_RESULTS_PANEL))
            .SetTemplateElement(JTemplateElements.GOOGLE_TRACER)
            .ProcessTemplate(response);

            JQueryFactory.JQuery(JQuerySelectors.SHOW_MORE_RESULTS_BUTTON).Click(_showMoreResults);
        }
        public override void Execute()
        {
            base.Execute();

            MockGoogleTracerView mockView = new MockGoogleTracerView();

            Container.RegisterInstance(typeof(IGoogleTracerView), mockView);

            GoogleTracerController controller = new GoogleTracerController();

            QUnit.Test("Test get View", delegate
            {
                QUnit.Equals(mockView, controller.View);
            });

            QUnit.Test("Test Execute() & ShowMoreResults()", delegate
            {
                GoogleSearchResponse data = new GoogleSearchResponse();

                Mock mockAddShowMoreResults = new Mock(mockView, "add_showMoreResults");
                mockAddShowMoreResults.Modify().Args(Is.Anything).ReturnValue();
                Mock mockRenderSearchResult = new Mock(mockView, "renderSearchResult");
                mockRenderSearchResult.Modify().Args(data).ReturnValue();
                mockRenderSearchResult.Modify().Args(data).ReturnValue();
                Mock mockGetScript = new Mock(Script.Eval("jQuery"), "getScript");
                mockGetScript.Modify().Args(Is.Anything, Is.Anything).Callback(1, null).ReturnValue();
                mockGetScript.Modify().Args(Is.Anything, Is.Anything).Callback(1, null).ReturnValue();

                QUnit.Equals(0, mockView.SearchStart);
                ((Dictionary)(object)Window.Self)["_googlewebsearchresults"] = data;
                controller.Execute();
                ((Dictionary)(object)Window.Self)["_googlewebsearchresults"] = data;
                controller.ShowMoreResults();
                QUnit.Equals(4, mockView.SearchStart);

                mockAddShowMoreResults.Verify();
                mockAddShowMoreResults.Restore();
                mockRenderSearchResult.Verify();
                mockRenderSearchResult.Restore();
                mockGetScript.Verify();
                mockGetScript.Restore();
            });
        }