public void Reset() { //reset the checks too so as not to leave old check results kicking about memoryCheckNotifier = new ToMemoryCheckNotifier(); _state = CheckResult.Success; _exception = null; }
public void DllFileDuplication_Ignored() { // Setup 2 directories that will contain duplicate copies of the same dll var badDir1 = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "Bad1")); var badDir2 = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "Bad2")); if (badDir1.Exists) { badDir1.Delete(true); } badDir1.Create(); if (badDir2.Exists) { badDir2.Delete(true); } badDir2.Create(); var dllToCopy = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "Rdmp.Core.dll")); // copy the dll to both folders File.Copy(dllToCopy.FullName, Path.Combine(badDir1.FullName, "Rdmp.Core.dll")); File.Copy(dllToCopy.FullName, Path.Combine(badDir2.FullName, "Rdmp.Core.dll")); var tomem = new ToMemoryCheckNotifier(); var sdc = new SafeDirectoryCatalog(tomem, badDir1.FullName, badDir2.FullName); Assert.AreEqual(sdc.DuplicateDllsIgnored, 1); badDir1.Delete(true); badDir2.Delete(true); }
private void btnCreate_Click(object sender, EventArgs e) { var preview = new SQLPreviewWindow("Confirm happiness with SQL", "The following SQL is about to be executed:", _createSql); MasterDatabaseScriptExecutor executor = null; if (string.IsNullOrWhiteSpace(tbDatabase.Text) || string.IsNullOrWhiteSpace(tbServer.Text)) { MessageBox.Show("You must specify both a Server and a Database"); return; } else { executor = new MasterDatabaseScriptExecutor(tbServer.Text, tbDatabase.Text, tbUsername.Text, tbPassword.Text); } if (_completed) { MessageBox.Show("Setup completed already, review progress messages then close Form"); return; } if (_tCreateDatabase != null && _tCreateDatabase.IsAlive) { MessageBox.Show("Setup already underaway, Thread State is:" + _tCreateDatabase.ThreadState); return; } if (preview.ShowDialog() == DialogResult.OK) { _tCreateDatabase = new Thread( () => { var memory = new ToMemoryCheckNotifier(checksUI1); if (executor.CreateDatabase(_createSql, _initialVersionNumber, memory)) { _completed = executor.PatchDatabase(_patches, memory, silentlyApplyPatchCallback); GenerateConnectionStringThenCopy(); var worst = memory.GetWorst(); if (worst == CheckResult.Success || worst == CheckResult.Warning) { if (MessageBox.Show("Succesfully created database, close form?", "Success", MessageBoxButtons.YesNo) == DialogResult.Yes) { _programaticClose = true; Invoke(new MethodInvoker(Close)); } } } else { _completed = false; //failed to create database } } ); _tCreateDatabase.Start(); } }
public void CheckCheckables() { if (checkingTask != null && !checkingTask.IsCompleted) { MessageBox.Show("Checking is already happening"); return; } //reset the dictionary lock (ocheckResultsDictionaryLock) { checkResultsDictionary = new Dictionary <ICheckable, CheckResult>(); } checkingTask = new Task(() => { //only check the items that are visible int he listview foreach (var checkable in GetCheckables())//make copy to prevent synchronization issues { var notifier = new ToMemoryCheckNotifier(); checkable.Check(notifier); lock (ocheckResultsDictionaryLock) checkResultsDictionary.Add(checkable, notifier.GetWorst()); } }); checkingTask.ContinueWith( //now load images to UI (t) => _tree.RebuildColumns(), TaskScheduler.FromCurrentSynchronizationContext()); checkingTask.Start(); }
public TestActivateItems(UITests uiTests, MemoryDataExportRepository repo) { _uiTests = uiTests; Results = new TestActivateItemsResults(); GlobalErrorCheckNotifier = new ToMemoryCheckNotifier(); RepositoryLocator = new RepositoryProvider(repo); RefreshBus = new RefreshBus(); //don't load the comment store for every single test if (_commentStore == null) { _commentStore = new CommentStore(); _commentStore.ReadComments(TestContext.CurrentContext.TestDirectory); } CommentStore = _commentStore; CoreChildProvider = new DataExportChildProvider(RepositoryLocator, null, Results); CoreIconProvider = new DataExportIconProvider(RepositoryLocator, null); FavouritesProvider = new FavouritesProvider(this, repo.CatalogueRepository); _problemProviders = new List <IProblemProvider>(new IProblemProvider[] { new CatalogueProblemProvider(), new DataExportProblemProvider() }); PluginUserInterfaces = new List <IPluginUserInterface>(); }
public void SupportsValidation_GoodButNoDataLoadRunID() { CatalogueConstraintReport report = new CatalogueConstraintReport(_catalogue, SpecialFieldNames.DataLoadRunID); _catalogue.ValidatorXML = validColumnXML; //set the time periodicity field var toBeTimePeriodicityCol = _catalogue.GetAllExtractionInformation(ExtractionCategory.Any).Single(e => e.GetRuntimeName().Equals("PrivateID")); _catalogue.TimeCoverage_ExtractionInformation_ID = toBeTimePeriodicityCol.ID; var notifier = new ToMemoryCheckNotifier(); report.Check(notifier); Assert.AreEqual(CheckResult.Warning, notifier.GetWorst()); Assert.Contains("Found column in query builder columns which matches TargetProperty Name", notifier.Messages.Select(m => m.Message).ToArray()); Assert.IsTrue(report.CatalogueSupportsReport(_catalogue)); var ex = Assert.Throws <Exception>(() => report.Check(new ThrowImmediatelyCheckNotifier() { ThrowOnWarning = true })); Assert.IsTrue(ex.Message == "Did not find ExtractionInformation for a column called hic_dataLoadRunID, this will prevent you from viewing the resulting report subdivided by data load batch (make sure you have this column and that it is marked as extractable)"); }
public void ConfigurationFrozen_RemnantsWithFiles() { DirectoryInfo dir; ExtractionConfiguration config; var p = GetProjectWithConfigDirectory(out config, out dir); //create remnant directory (empty) var remnantDir = dir.CreateSubdirectory("Extr_" + config.ID + "20011225"); //with empty subdirectories var lookupDir = remnantDir.CreateSubdirectory("DMPTestCatalogue").CreateSubdirectory("Lookups"); //this time put a file in File.AppendAllLines(Path.Combine(lookupDir.FullName, "Text.txt"), new string[] { "Amagad" }); config.IsReleased = true;//make environment think config is released config.SaveToDatabase(); try { var notifier = new ToMemoryCheckNotifier(); RunTestWithCleanup(p, config, notifier); Assert.IsTrue(notifier.Messages.Any( m => m.Result == CheckResult.Fail && Regex.IsMatch(m.Message, @"Found non-empty folder .* which is left over extracted folder after data release \(First file found was '.*[/\\]DMPTestCatalogue[/\\]Lookups[/\\]Text.txt' but there may be others\)"))); } finally { remnantDir.Delete(true); } }
/// <summary> /// Starts up service and begins listening with the <see cref="Consumer"/> /// </summary> public override void Start() { FansiImplementations.Load(); IRDMPPlatformRepositoryServiceLocator repositoryLocator = Globals.RDMPOptions.GetRepositoryProvider(); var startup = new Startup(new EnvironmentInfo("netcoreapp2.2"), repositoryLocator); var toMemory = new ToMemoryCheckNotifier(); startup.DoStartup(toMemory); foreach (CheckEventArgs args in toMemory.Messages.Where(m => m.Result == CheckResult.Fail)) { Logger.Log(LogLevel.Warn, args.Ex, args.Message); } _fileMessageProducer = RabbitMqAdapter.SetupProducer(Globals.CohortExtractorOptions.ExtractFilesProducerOptions, isBatch: true); IProducerModel fileMessageInfoProducer = RabbitMqAdapter.SetupProducer(Globals.CohortExtractorOptions.ExtractFilesInfoProducerOptions, isBatch: false); InitializeExtractionSources(repositoryLocator); Consumer = new ExtractionRequestQueueConsumer(Globals.CohortExtractorOptions, _fulfiller, _auditor, _pathResolver, _fileMessageProducer, fileMessageInfoProducer); RabbitMqAdapter.StartConsumer(_consumerOptions, Consumer, isSolo: false); }
public void Synchronization_ExtraParameter() { string expectedMessage = "MyAwesomeFunction is a Table Valued Function, in the Catalogue it has a parameter called @fish but this parameter no longer appears in the underlying database"; var excessParameter = new AnyTableSqlParameter(CatalogueRepository, _function.TableInfoCreated, "DECLARE @fish as int"); var checker = new ToMemoryCheckNotifier(); _function.TableInfoCreated.Check(checker); Assert.IsTrue(checker.Messages.Any(m => m.Result == CheckResult.Fail && m.Message.Contains(expectedMessage))); var syncer = new TableInfoSynchronizer(_function.TableInfoCreated); var ex = Assert.Throws <Exception>(() => syncer.Synchronize(new ThrowImmediatelyCheckNotifier())); Assert.IsTrue(ex.Message.Contains(expectedMessage)); //no changes yet Assert.IsTrue(excessParameter.HasLocalChanges().Evaluation == ChangeDescription.NoChanges); //sync should have proposed to drop the excess parameter (see above), accept the change Assert.IsTrue(syncer.Synchronize(new AcceptAllCheckNotifier())); //now parameter shouldnt be there Assert.IsTrue(excessParameter.HasLocalChanges().Evaluation == ChangeDescription.DatabaseCopyWasDeleted); }
public void ConnectToServer() { var hicProjDir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "MDFAttacherTest", true); var db = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase("MyImaginaryDB_RAW"); Assert.IsFalse(db.Exists()); var mdf = new MDFAttacher(); mdf.Initialize(hicProjDir, db); try { var memory = new ToMemoryCheckNotifier(new ThrowImmediatelyCheckNotifier()); mdf.Check(memory); Assert.IsTrue(memory.Messages.Any(m => m.Message.Contains("Found server DATA folder") && m.Result == CheckResult.Success)); } catch (Exception e) { if (!e.Message.Contains("Proposed server DATA folder (that we will copy mdf/ldf files to) was not found"))//this message is allowed too if the SQL server is remote and not localhost then it is quite likely that the DATA path is inaccessible from the unit test server { throw; } } var memory2 = new ToMemoryCheckNotifier(new ThrowImmediatelyCheckNotifier()); mdf.OverrideMDFFileCopyDestination = TestContext.CurrentContext.WorkDirectory; mdf.Check(memory2); Assert.IsTrue(memory2.Messages.Any(m => Regex.IsMatch(m.Message, @"Found server DATA folder .*" + Regex.Escape(TestContext.CurrentContext.WorkDirectory)) && m.Result == CheckResult.Success)); hicProjDir.RootPath.Delete(true); }
public void FileDuplication() { var badDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "Bad")); if (badDir.Exists) { badDir.Delete(true); } badDir.Create(); var dllToCopy = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "Rdmp.Core.dll")); File.Copy(dllToCopy.FullName, Path.Combine(badDir.FullName, "Rdmp.Core.dll")); var tomem = new ToMemoryCheckNotifier(); new SafeDirectoryCatalog(tomem, TestContext.CurrentContext.TestDirectory); var warnings = tomem.Messages.Where(m => m.Result == CheckResult.Success).ToArray(); Assert.GreaterOrEqual(warnings.Count(m => m.Message.StartsWith("Found 2 copies of Rdmp.Core.dll")), 1); badDir.Delete(true); }
private void AssertFailWithFix(string expectedMessage, string expectedFix, ToMemoryCheckNotifier toMem) { var msg = toMem.Messages.Where(m => m.Result == CheckResult.Fail).First(); Assert.AreEqual(expectedMessage, msg.Message, "Expected error message was wrong"); Assert.AreEqual(expectedFix, msg.ProposedFix, "Expected proposed fix was wrong"); }
public void Test_MissingLoggingServer_UseDefault() { var lmd = WhenIHaveA <LoadMetadata>(); var cata1 = lmd.GetAllCatalogues().Single(); var cata2 = WhenIHaveA <Catalogue>(); var eds = WhenIHaveA <ExternalDatabaseServer>(); eds.Name = "My Logging Server"; eds.SaveToDatabase(); cata2.LoadMetadata_ID = lmd.ID; cata1.LoggingDataTask = "OMG YEAGH"; cata1.LiveLoggingServer_ID = null; cata2.LoggingDataTask = "OMG YEAGH"; cata2.LiveLoggingServer_ID = null; var defaults = RepositoryLocator.CatalogueRepository.GetServerDefaults(); defaults.SetDefault(PermissableDefaults.LiveLoggingServer_ID, eds); Assert.AreEqual(2, lmd.GetAllCatalogues().Count()); var checks = new MetadataLoggingConfigurationChecks(lmd); var toMem = new ToMemoryCheckNotifier(); checks.Check(toMem); AssertFailWithFix("Some catalogues have NULL LiveLoggingServer_ID", $"Set LiveLoggingServer_ID to 'My Logging Server' (the default)", toMem); }
public void CatalogueCheck_FetchData(DatabaseType databaseType) { DataTable dt = new DataTable(); dt.Columns.Add("Name"); dt.Rows.Add("Frank"); dt.Rows.Add("Peter"); var database = GetCleanedServer(databaseType); var tbl = database.CreateTable("CatalogueCheck_CanReadText", dt); var cata = Import(tbl); //shouldn't be any errors var tomemory = new ToMemoryCheckNotifier(); cata.Check(tomemory); Assert.AreEqual(CheckResult.Success, tomemory.GetWorst()); //delete all the records in the table tbl.Truncate(); cata.Check(tomemory); //now it should warn us that it is empty Assert.AreEqual(CheckResult.Warning, tomemory.GetWorst()); tbl.Drop(); cata.Check(tomemory); //now it should fail checks Assert.AreEqual(CheckResult.Fail, tomemory.GetWorst()); }
public void ServerDatabaseIsPresentAndCorrect(bool alreadyExists) { var server = new ExternalDatabaseServer(CatalogueRepository, "Fiction", null); server.Server = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.Name; //server.Database = "FictionalDatabase"; Ignored by the extractor! try { var destination = new ExecuteFullExtractionToDatabaseMSSql(); destination.PreInitialize(_projectStub, new ThrowImmediatelyDataLoadEventListener()); destination.PreInitialize(_commandStub, new ThrowImmediatelyDataLoadEventListener()); destination.TargetDatabaseServer = server; destination.TableNamingPattern = "$d"; if (alreadyExists) { destination.DatabaseNamingPattern = Database.GetRuntimeName(); //database that exists } else { destination.DatabaseNamingPattern = "Fictional$nDatabase"; //database does not exist (but server does) } var tomemory = new ToMemoryCheckNotifier(new ThrowImmediatelyCheckNotifier()); destination.Check(tomemory); Assert.AreEqual(alreadyExists? CheckResult.Warning: CheckResult.Success, tomemory.GetWorst()); } finally { server.DeleteInDatabase(); } }
public void ServerDatabaseIsPresentAndCorrectButHasTablesInIt() { var server = new ExternalDatabaseServer(CatalogueRepository, "Fiction", null); server.Server = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.Name; //server.Database = "FictionalDatabase"; Ignored by the extractor! using (var con = Database.Server.GetConnection()) { con.Open(); Database.Server.GetCommand("CREATE TABLE Bob(name varchar(10))", con).ExecuteNonQuery(); } try { var destination = new ExecuteFullExtractionToDatabaseMSSql(); destination.PreInitialize(_projectStub, new ThrowImmediatelyDataLoadEventListener()); destination.PreInitialize(_commandStub, new ThrowImmediatelyDataLoadEventListener()); destination.TargetDatabaseServer = server; destination.TableNamingPattern = "$d"; destination.DatabaseNamingPattern = "FictionalDatabase"; var tomemory = new ToMemoryCheckNotifier(new ThrowImmediatelyCheckNotifier()); destination.Check(tomemory); Assert.AreEqual(CheckResult.Warning, tomemory.GetWorst()); Database.ExpectTable("Bob").Drop(); } finally { server.DeleteInDatabase(); } }
private void AssertFailedCheck(ToMemoryCheckNotifier checkResults, string expectedContainsText) { //there must have been something checked that failed with the provided message Assert.IsTrue(checkResults.Messages.Any(m => m.Message.Contains(expectedContainsText) || (m.Ex != null && m.Ex.Message.Contains(expectedContainsText)) && m.Result == CheckResult.Fail)); }
protected void ClearResults() { if (_itemActivator != null) { _itemActivator.Results.Clear(); } _checkResults = null; LastUserInterfaceLaunched = null; }
public virtual bool CatalogueSupportsReport(ICatalogue c) { _catalogue = c; ToMemoryCheckNotifier checkNotifier = new ToMemoryCheckNotifier(); Check(checkNotifier); return(checkNotifier.GetWorst() <= CheckResult.Warning); }
public void NoServer() { var destination = new ExecuteFullExtractionToDatabaseMSSql(); var tomemory = new ToMemoryCheckNotifier(); destination.Check(tomemory); Assert.AreEqual(CheckResult.Fail, tomemory.Messages[0].Result); Assert.IsTrue(tomemory.Messages[0].Message.StartsWith("Target database server property has not been set")); }
private void Check(IRunner runner, ToMemoryCheckNotifier toMemory) { try { runner.Run(Activator.RepositoryLocator, new FromCheckNotifierToDataLoadEventListener(toMemory), toMemory, new GracefulCancellationToken()); } catch (Exception e) { toMemory.OnCheckPerformed(new CheckEventArgs("Entire process crashed", CheckResult.Fail, e)); } }
void checker_AllChecksFinished(ToMemoryCheckNotifier listener) { _results.Add(new CheckEventArgs("All Checks Complete", CheckResult.Success)); outOfDate = true; CheckingInProgress = false; if (AllChecksComplete != null) { AllChecksComplete(this, new AllChecksCompleteHandlerArgs(listener)); } }
protected override void OnClick(EventArgs e) { if (_events.Messages.Any()) { var popup = new PopupChecksUI("Exceptions", false); popup.Check(new ReplayCheckable(_events)); popup.FormClosed += (s, ea) => { _events = new ToMemoryCheckNotifier(); Enabled = false; Invalidate(); }; } }
public void Reset() { if (_host.InvokeRequired) { _host.Invoke(new MethodInvoker(Reset)); return; } //reset the checks too so as not to leave old check results kicking about memoryCheckNotifier = new ToMemoryCheckNotifier(); Tag = null; _worst = CheckResult.Success; Image = _green; Enabled = false; }
private void btnRunChecks_Click(object sender, EventArgs e) { IRunner runner; try { var command = CommandGetter(CommandLineActivity.check); runner = _factory.CreateRunner(Activator, command); } catch (Exception ex) { ragChecks.Fatal(ex); return; } CurrentRunner = runner; btnRunChecks.Enabled = false; //reset the visualisations ragChecks.Reset(); checksUI1.Clear(); //ensure the checks are visible over the load loadProgressUI1.Visible = false; checksUI1.Visible = true; //create a to memory that passes the events to checksui since that's the only one that can respond to proposed fixes var toMemory = new ToMemoryCheckNotifier(checksUI1); Task.Factory.StartNew(() => Check(runner, toMemory)).ContinueWith( t => { //once Thread completes do this on the main UI Thread //find the worst check state var worst = toMemory.GetWorst(); //update the rag smiley to reflect whether it has passed ragChecks.OnCheckPerformed(new CheckEventArgs("Checks resulted in " + worst, worst)); //update the bit flag ChecksPassed = worst <= CheckResult.Warning; //enable other buttons now based on the new state SetButtonStates(); }, TaskScheduler.FromCurrentSynchronizationContext()); _runningTask = null; ChecksPassed = true; }
public void MEFCompatibleType_Passes() { var projDir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "DelMeProjDir", true); try { _lmd.LocationOfFlatFiles = projDir.RootPath.FullName; _task.ProcessTaskType = ProcessTaskType.Attacher; _task.LoadStage = LoadStage.Mounting; _task.Path = typeof(AnySeparatorFileAttacher).FullName; _task.SaveToDatabase(); //create the arguments var args = ProcessTaskArgument.CreateArgumentsForClassIfNotExists <AnySeparatorFileAttacher>(_task); var tblName = (ProcessTaskArgument)args.Single(a => a.Name.Equals("TableName")); tblName.Value = "MyExcitingTable"; tblName.SaveToDatabase(); var filePattern = (ProcessTaskArgument)args.Single(a => a.Name.Equals("FilePattern")); filePattern.Value = "*.csv"; filePattern.SaveToDatabase(); var separator = (ProcessTaskArgument)args.Single(a => a.Name.Equals("Separator")); separator.Value = ","; separator.SaveToDatabase(); var results = new ToMemoryCheckNotifier(); _checker.Check(results); foreach (var msg in results.Messages) { Console.WriteLine("(" + msg.Result + ")" + msg.Message); if (msg.Ex != null) { Console.WriteLine(ExceptionHelper.ExceptionToListOfInnerMessages(msg.Ex)); } } Assert.AreEqual(CheckResult.Success, results.GetWorst()); } finally { //delete everything for real projDir.RootPath.Delete(true); } }
private void CommonFunctionalityOnBeforeChecking(object sender, EventArgs eventArgs) { //intercept checking and replace with our own in memory checks var e = (BeforeCheckingEventArgs)eventArgs; _checkResults = new ToMemoryCheckNotifier(); try { e.Checkable.Check(_checkResults); } catch (Exception ex) { _checkResults.OnCheckPerformed(new CheckEventArgs("Checks threw exception", CheckResult.Fail, ex)); } e.Cancel = true; }
public void Test_NoLoggingTask() { var lmd = WhenIHaveA <LoadMetadata>(); var cata1 = lmd.GetAllCatalogues().Single(); var cata2 = WhenIHaveA <Catalogue>(); cata2.LoadMetadata_ID = lmd.ID; Assert.AreEqual(2, lmd.GetAllCatalogues().Count()); var checks = new MetadataLoggingConfigurationChecks(lmd); var toMem = new ToMemoryCheckNotifier(); checks.Check(toMem); AssertFailWithFix("Catalogues Mycata,Mycata do not have a logging task specified", "Create a new Logging Task called 'MyLoad'?", toMem); }
void checker_AllChecksFinished(ToMemoryCheckNotifier listener) { if (InvokeRequired && !IsDisposed) { Invoke(new MethodInvoker(() => checker_AllChecksFinished(listener))); return; } olvChecks.AddObject(new CheckEventArgs("All Checks Complete", CheckResult.Success)); CheckingInProgress = false; if (AllChecksComplete != null) { AllChecksComplete(this, new AllChecksCompleteHandlerArgs(listener)); } }
public void Reset() { if (InvokeRequired) { Invoke(new MethodInvoker(Reset)); return; } //reset the checks too so as not to leave old check results kicking about memoryCheckNotifier = new ToMemoryCheckNotifier(); pbGreen.Visible = true; pbYellow.Visible = false; pbYellow.Tag = null; pbRed.Visible = false; pbRed.Tag = null; SetCorrectCursor(); }