public void ExecuteQuerySendsResultToUI()
        {
            ExecuteInUI eiu = new ExecuteInUI();
            IList objectGraph = new ArrayList();
            DataSet ds = new DataSet();
            Expect.On(prj).Call(prj.RunHql(query,parameters)).Return(objectGraph);
            Expect.On(prj).Call(prj.RunHqlAsRawSql(query,parameters)).Return(ds);
            view.ExecuteInUIThread(null);
            LastCall.On(view).Callback(new ExecuteInUI.ExecuteInUIDelegate(eiu.ExecuteInUIThread));
            view.DisplayDataSet(ds);
            view.DisplayObjectGraph(objectGraph);
            view.ShowObjectGraph();
            view.EndWait("Finished executing query");

            mocks.ReplayAll();
            command.Execute();
        }
        public void ExceptionInQuery_DoesNotThrowButReportsException()
        {
            ExecuteInUI eiu = new ExecuteInUI();
            SetupCallbackEnqueCommandAndExecuteInUI(eiu);
            SetupParameters(new Hashtable(),badHqlQuery);
            queryView.StartWait("Executing query",100,1000);
            queryView.EndWait("An exception occured executing query");
            queryView.AddException(null);
            LastCall.On(queryView).
                Constraints(
                    Is.TypeOf(typeof(QueryException)) &
                    Property.Value("Message",badQueryExceptionMessage));
            mocks.ReplayAll();
            presenter.ExecuteQuery();

            Assert.IsTrue(eiu.ExecuteCommandCalled);
            Assert.IsTrue(eiu.ExecuteInUICalled);
        }
        public void ExecuteQueryReportsFailure()
        {
            string errorMsg = "Database connection closed";
            DataException exception = new DataException(errorMsg);
            ExecuteInUI eiu = new ExecuteInUI();
            IList objectGraph = new ArrayList();
            Expect.On(prj).Call(prj.RunHql(query,parameters)).Return(objectGraph);
            Expect.On(prj).Call(prj.RunHqlAsRawSql(query,parameters)).Throw(exception);

            view.ExecuteInUIThread(null);
            LastCall.On(view).Callback(new ExecuteInUI.ExecuteInUIDelegate(eiu.ExecuteInUIThread));
            view.AddException(exception);

            view.EndWait("An exception occured executing query");

            mocks.ReplayAll();
            command.Execute();
        }
 private void SetupCallbackEnqueCommandAndExecuteInUI(ExecuteInUI eiu)
 {
     mainPresenter.EnqueueCommand(null);
     LastCall.On(mainPresenter).
         Callback(new ExecuteInUI.ExecuteCommandDelegate(eiu.ExecuteCommand));
     queryView.ExecuteInUIThread(null);
     LastCall.On(queryView).
         Callback(new ExecuteInUI.ExecuteInUIDelegate(eiu.ExecuteInUIThread));
 }
        public void ExecuteQuery_WithParameter()
        {
            ExecuteInUI eiu = new ExecuteInUI();
            SetupMockParameter();
            SetupCallbackEnqueCommandAndExecuteInUI(eiu);
            SetupResult.On(queryView).Call(queryView.HqlQueryText).Return(parametrizedOne);
            queryView.StartWait("Executing query",100,1000);
            SetupCallbackForCheckingObjectGraphAndDataSet();
            queryView.ShowObjectGraph();
            queryView.EndWait("Finished executing query");

            mocks.ReplayAll();
            presenter.ExecuteQuery();

            Assert.IsTrue(eiu.ExecuteCommandCalled);
            Assert.IsTrue(eiu.ExecuteInUICalled);
        }
        public void ExecuteQuery_NoParameters()
        {
            ExecuteInUI eiu = new ExecuteInUI();
            SetupCallbackEnqueCommandAndExecuteInUI(eiu);
            SetupParameters(new Hashtable(),nonParametrized);
            queryView.StartWait("Executing query",100,1000);
            SetupCallbackForCheckingObjectGraphAndDataSet();
            queryView.ShowObjectGraph();
            queryView.EndWait("Finished executing query");

            mocks.ReplayAll();
            presenter.ExecuteQuery();
            Assert.IsTrue(eiu.ExecuteCommandCalled);
            Assert.IsTrue(eiu.ExecuteInUICalled);
        }
        public void ExceptionThatIsNotQuerExceptionDoesNotThrowButReports()
        {
            ExecuteInUI eiu = new ExecuteInUI();
            SetupCallbackEnqueCommandAndExecuteInUI(eiu);
            SetupParameters(new Hashtable(),"from NotExists");
            queryView.StartWait("Executing query",100,1000);
            queryView.EndWait("An exception occured executing query");
            queryView.AddException(null);
            LastCall.On(queryView).
                Constraints(
                Is.TypeOf(typeof(QueryException)) &
                Property.Value("Message","in expected: <end-of-text> (possibly an invalid or unmapped class name was used in the query) [from NotExists]"));
            mocks.ReplayAll();
            presenter.ExecuteQuery();

            Assert.IsTrue(eiu.ExecuteCommandCalled);
            Assert.IsTrue(eiu.ExecuteInUICalled);
        }