public void Creates_A_New_Database_If_No_Database_Has_Been_Previously_Loaded()
        {
            IDatabaseForm form  = MockRepository.GenerateMock <IDatabaseForm>();
            IMainPanel    panel = MockRepository.GenerateMock <IMainPanel>();

            DatabasePresenter presenter = new DatabasePresenter(panel, form);

            AutoResetEvent arEvent = new AutoResetEvent(false);

            presenter.NewDatabaseCreated += (sender, e) => arEvent.Set();

            Assert.That(presenter.Database, Is.Null);

            form.Stub(t => t.SelectedDatabaseType).Return(DatabaseTypes.SQLCE);
            form.Stub(t => t.SelectedDatabase).Return("1Table3Columns.sdf");

            var raiser = form.GetEventRaiser(t => t.RefreshSchema += null);

            raiser.Raise(form, null);

            Assert.That(arEvent.WaitOne(10000, true), "The test timed out waiting for the NewDatabaseCreated event to be triggered");

            Assert.That(presenter.Database, Is.Not.Null);
            Assert.That(presenter.Database.Name, Is.EqualTo("1Table3Columns"));
        }
        public void A_SQLCEDatabaseLoader_Is_Returned()
        {
            IDatabaseForm form  = MockRepository.GenerateMock <IDatabaseForm>();
            IMainPanel    panel = MockRepository.GenerateMock <IMainPanel>();

            DatabasePresenter presenter = new DatabasePresenter(panel, form);

            form.Stub(t => t.SelectedDatabaseType).Return(DatabaseTypes.SQLCE);
            form.Stub(t => t.SelectedDatabase).Return("1Table3Columns.sdf");

            IDatabaseLoader loader = presenter.CreateDatabaseLoader();

            Assert.That(loader, Is.Not.Null);
            Assert.That(loader, Is.TypeOf(typeof(SQLCEDatabaseLoader)));

            // Will throw an error if the database connection could not be established.
            loader.TestConnection();

            IDatabase db = loader.LoadDatabase();

            Assert.That(db.Name, Is.EqualTo("1Table3Columns"));
            Assert.That(db.Tables, Has.Count(1));             // Basic check to see if we got the correct database back.
        }
        public void A_SQLServer2005DatabaseLoader_Is_Returned()
        {
            IDatabaseForm form  = MockRepository.GenerateMock <IDatabaseForm>();
            IMainPanel    panel = MockRepository.GenerateMock <IMainPanel>();

            DatabasePresenter presenter = new DatabasePresenter(panel, form);

            form.Stub(t => t.SelectedDatabaseType).Return(DatabaseTypes.SQLServer2005);
            form.Stub(t => t.ConnectionStringHelper).Return(new ConnectionStringHelper
            {
                CurrentDbType         = DatabaseTypes.SQLServer2005,
                DatabaseName          = "TestDatabase",
                Password              = "******",
                ServerName            = ".",
                UseFileName           = false,
                UseIntegratedSecurity = false,
                UserName              = "******"
            });

            IDatabaseLoader loader = presenter.CreateDatabaseLoader();

            Assert.That(loader, Is.Not.Null);
            Assert.That(loader, Is.TypeOf(typeof(SQLServer2005DatabaseLoader)));
        }