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();
            });
        }
Example #2
0
        public override void Execute()
        {
            base.Execute();

            CnblogsGoogleSearchTracerView view = new CnblogsGoogleSearchTracerView();

            QUnit.Test("Test SearchStart", delegate
            {
                QUnit.Equals(0, view.SearchStart);
                view.SearchStart = 1;
                QUnit.Equals(1, view.SearchStart);
                view.SearchStart = 2;
                QUnit.Equals(2, view.SearchStart);
            });

            QUnit.Test("Test GetSearchKeyword()", delegate
            {
                JQueryFactory.JQuery(JQuerySelectors.SEARCH_KEYWORD).Html("keyword1");
                QUnit.Equals("keyword1", view.GetSearchKeyword());
                JQueryFactory.JQuery(JQuerySelectors.SEARCH_KEYWORD).Html("keyword2");
                QUnit.Equals("keyword2", view.GetSearchKeyword());
            });

            QUnit.Test("Test RenderSearchResult()", delegate
            {
                jQuery pnlSearchResults   = JQueryFactory.JQuery(JQuerySelectors.SEARCH_RESULTS_PANEL);
                jQuery btnShowMoreResults = JQueryFactory.JQuery(JQuerySelectors.SHOW_MORE_RESULTS_BUTTON);

                Mock mockJQuery = new Mock(Window.Self, "jQuery");
                mockJQuery.Modify().Args(JQuerySelectors.SEARCH_RESULTS_PANEL).ReturnValue(pnlSearchResults);
                mockJQuery.Modify().Args(JQuerySelectors.SHOW_MORE_RESULTS_BUTTON).ReturnValue(btnShowMoreResults);
                Mock mockSetTemplateElement = new Mock(pnlSearchResults, "setTemplateElement");
                mockSetTemplateElement.Modify().Args(JTemplateElements.GOOGLE_TRACER).ReturnValue(pnlSearchResults);
                Mock mockProcessTemplate = new Mock(pnlSearchResults, "processTemplate");
                mockProcessTemplate.Modify().Args(Is.Anything).ReturnValue();
                Mock mockShowMoreResultsBindClick = new Mock(btnShowMoreResults, "click");
                mockShowMoreResultsBindClick.Modify().Args(Is.Anything).ReturnValue();

                view.RenderSearchResult(new GoogleSearchResponse());

                mockJQuery.Verify();
                mockJQuery.Restore();
                mockSetTemplateElement.Verify();
                mockSetTemplateElement.Restore();
                mockProcessTemplate.Verify();
                mockProcessTemplate.Restore();
                mockShowMoreResultsBindClick.Verify();
                mockShowMoreResultsBindClick.Restore();
            });

            QUnit.Test("Test ShowMoreResults Event", delegate
            {
                QUnit.Equals(false, _showMoreResultsClicked);

                view.ShowMoreResults += new System.DHTML.DOMEventHandler(view_ShowMoreResults);
                view.RenderSearchResult(new GoogleSearchResponse());
                JQueryFactory.JQuery(JQuerySelectors.SHOW_MORE_RESULTS_BUTTON).Click();

                QUnit.Equals(true, _showMoreResultsClicked);
            });
        }