コード例 #1
0
        public void Test_ReportOk_Single( )
        {
            ImportRun         importRun = new ImportRun( );
            ImportRunReporter reporter  = new ImportRunReporter(importRun);

            reporter.ReportOk( );
            reporter.ReportOk(2);
            reporter.Flush( );

            Assert.That(importRun.ImportRecordsFailed, Is.EqualTo(0));
            Assert.That(importRun.ImportRecordsSucceeded, Is.EqualTo(3));
            Assert.That(importRun.ImportMessages, Is.Null);
        }
コード例 #2
0
        public void Test_ReportError(string location, string expectedMessage)
        {
            ImportRun         importRun = new ImportRun( );
            ImportRunReporter reporter  = new ImportRunReporter(importRun);

            Mock <IObjectReader> mockObject = new Mock <IObjectReader>( );

            mockObject.Setup(obj => obj.GetLocation( )).Returns(location);
            reporter.ReportError(mockObject.Object, "Message");
            reporter.Flush( );

            Assert.That(importRun.ImportRecordsFailed, Is.EqualTo(1));
            Assert.That(importRun.ImportRecordsSucceeded, Is.EqualTo(0));
            Assert.That(importRun.ImportMessages, Is.EqualTo(expectedMessage));
        }
コード例 #3
0
        public void Test_MessageReordering( )
        {
            ImportRun         importRun = new ImportRun( );
            ImportRunReporter reporter  = new ImportRunReporter(importRun);

            Mock <IObjectReader> mockObject  = new Mock <IObjectReader>( );
            Mock <IObjectReader> mockObject2 = new Mock <IObjectReader>( );

            mockObject.Setup(obj => obj.GetLocation( )).Returns(() => "Line 10");
            mockObject2.Setup(obj => obj.GetLocation( )).Returns(() => "Line 2");
            reporter.ReportError(mockObject.Object, "Message");
            reporter.ReportError(mockObject2.Object, "Message");
            reporter.ReportError(mockObject.Object, "Message");
            reporter.ReportError(mockObject2.Object, "Message");
            reporter.Flush( );

            Assert.That(importRun.ImportMessages, Is.EqualTo("Line 2: Message\r\nLine 2: Message\r\nLine 10: Message\r\nLine 10: Message\r\n"));
        }
コード例 #4
0
        public void Test_Calls_DontAccumulateForSameRecord( )
        {
            ImportRun         importRun = new ImportRun( );
            ImportRunReporter reporter  = new ImportRunReporter(importRun);

            Mock <IObjectReader> mockObject = new Mock <IObjectReader>( );

            mockObject.Setup(obj => obj.GetLocation( )).Returns(() => "Line 1");
            reporter.ReportError(mockObject.Object, "Message");
            reporter.ReportError(mockObject.Object, "Message");
            reporter.ReportOk( );
            reporter.Flush( );
            reporter.ReportOk(2);
            reporter.Flush( );

            Assert.That(importRun.ImportRecordsFailed, Is.EqualTo(1));
            Assert.That(importRun.ImportRecordsSucceeded, Is.EqualTo(3));
            Assert.That(importRun.ImportMessages, Is.EqualTo("Line 1: Message\r\nLine 1: Message\r\n"));
        }
コード例 #5
0
        /// <summary>
        /// Start processing an import run, after checking has been performed.
        /// </summary>
        /// <param name="importRun">A writable import run entity. Caller will save.</param>
        internal void StartImportSafe(ImportRun importRun)
        {
            ImportConfig importConfig = importRun.ImportConfigUsed;

            if (importConfig == null)
            {
                throw new ConnectorConfigException("Import configuration could not be loaded.");
            }
            if (importConfig.ImportConfigMapping == null)
            {
                throw new ConnectorConfigException("Import configuration has no mapping.");
            }

            IObjectsReader         recordsReader = null;
            IReaderToEntityAdapter entityAdapter;
            IImportReporter        importRunReporter;
            IRecordImporter        recordImporter;
            ICancellationWatcher   cancellationWatcher;
            BatchRunner            batchRunner;

            try
            {
                // Reads records out of the file to count
                recordsReader = GetRecordsReader(importRun, importConfig);
                importRun.ImportRecordsTotal = recordsReader.GetObjects( ).Count( );
                importRun.Save( );

                // Re-reads records out of the file for importing
                recordsReader = GetRecordsReader(importRun, importConfig);

                // Writes records into entities
                entityAdapter = GetEntityAdapter(importConfig);

                // Create a reporter to process progress notifications
                importRunReporter = new ImportRunReporter(importRun);

                // Create a reporter to process progress notifications
                cancellationWatcher = new ImportRunCancellationWatcher(importRun);

                // Activate record impoter
                bool testRun = importRun.ImportTestRun == true;
                recordImporter = _recordImporterActivator(entityAdapter, importRunReporter, importConfig.ImportConfigMapping, testRun);
                if (recordImporter == null)
                {
                    throw new Exception("recordImporter failed to activate.");
                }

                // Connects the reader to the writer
                batchRunner = new BatchRunner
                {
                    ObjectsReader       = recordsReader,
                    RecordImporter      = recordImporter,
                    CancellationWatcher = cancellationWatcher
                };

                // Go! Run as user
                using (new SecurityBypassContext(false))
                {
                    batchRunner.ProcessAll( );
                }
            }
            finally
            {
                recordsReader?.Dispose( );
            }
        }