示例#1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="entityRepository">Used to load/save the import run and config details.</param>
        /// <param name="fileRepository">Used to get file stream of file being imported.</param>
        /// <param name="recordImporterActivator">Used to create an importer of records.</param>
        /// <param name="readerActivator">Used to activate a file parser.</param>
        /// <param name="readerToEntityAdapterProvider">Creates an adapter that writes data into entities.</param>
        public ImportRunWorker(IEntityRepository entityRepository, [WithKey(FileRepositoryModule.TemporaryFileRepositoryName)] IFileRepository fileRepository, RecordImporter.Factory recordImporterActivator, Func <ImportFormat, IDataFileReaderService> readerActivator, IReaderToEntityAdapterProvider readerToEntityAdapterProvider)
        {
            if (entityRepository == null)
            {
                throw new ArgumentNullException(nameof(entityRepository));
            }
            if (fileRepository == null)
            {
                throw new ArgumentNullException(nameof(fileRepository));
            }
            if (recordImporterActivator == null)
            {
                throw new ArgumentNullException(nameof(recordImporterActivator));
            }
            if (readerActivator == null)
            {
                throw new ArgumentNullException(nameof(readerActivator));
            }
            if (readerToEntityAdapterProvider == null)
            {
                throw new ArgumentNullException(nameof(readerToEntityAdapterProvider));
            }

            _entityRepository              = entityRepository;
            FileRepository                 = fileRepository;
            _recordImporterActivator       = recordImporterActivator;
            _readerActivator               = readerActivator;
            _readerToEntityAdapterProvider = readerToEntityAdapterProvider;
        }
示例#2
0
        public void Test_SuppressWorkflow(bool suppressWorkflows)
        {
            bool called = false;

            using (var mock = GetMock( ))
            {
                var mockSaver = new Mock <IEntitySaver>(MockBehavior.Strict);
                RecordImporter.Factory factory = (readerToEntityAdapter, importReporter, resourceMapping, testRun) =>
                                                 new RecordImporter(
                    readerToEntityAdapter,
                    mockSaver.Object,
                    importReporter, resourceMapping, testRun);

                mock.Provide(factory);
                mock.Provide(mockSaver);

                mockSaver.Setup(m => m.SaveEntities(It.IsAny <IEnumerable <IEntity> >( )))
                .Callback(() =>
                {
                    called = true;
                    Assert.That(WorkflowRunContext.Current.DisableTriggers, Is.EqualTo(suppressWorkflows), "Suppress");
                }
                          );


                ImportRunWorker worker    = mock.Create <ImportRunWorker>( );
                var             importRun = GetImportRun(mock);
                importRun.ImportConfigUsed.ImportConfigMapping.MappingSuppressWorkflows = suppressWorkflows;
                importRun.Save( );

                worker.StartImport(MockRunId);

                Assert.That(called, Is.True, "Called");
            }
        }
示例#3
0
        public void Test_TestRun(bool testRun)
        {
            using (var mock = GetMock( ))
            {
                var mockSaver = new Mock <IEntitySaver>(MockBehavior.Strict);
                RecordImporter.Factory factory = (readerToEntityAdapter, importReporter, resourceMapping, testRun1) =>
                                                 new RecordImporter(
                    readerToEntityAdapter,
                    mockSaver.Object,
                    importReporter, resourceMapping, testRun1);

                mock.Provide(factory);
                mock.Provide(mockSaver);

                bool called = false;
                mockSaver.Setup(m => m.SaveEntities(It.IsAny <IEnumerable <IEntity> >( )))
                .Callback(() => { called = true; });

                ImportRunWorker worker    = mock.Create <ImportRunWorker>( );
                var             importRun = GetImportRun(mock);
                importRun.ImportTestRun = testRun;
                importRun.Save( );

                worker.StartImport(MockRunId);

                Assert.That(called, Is.EqualTo(!testRun));
            }
        }
示例#4
0
        public void RecordImporter_Factory( )
        {
            IReaderToEntityAdapter adapter  = new Mock <IReaderToEntityAdapter>( ).Object;
            IImportReporter        reporter = new Mock <IImportReporter>().Object;
            ApiResourceMapping     mapping  = new ApiResourceMapping( );

            RecordImporter.Factory recordImporterFactory = Factory.Current.Resolve <RecordImporter.Factory>( );
            IRecordImporter        recordImporter        = recordImporterFactory(adapter, reporter, mapping, true);

            Assert.That(recordImporter, Is.TypeOf <RecordImporter>( ));

            RecordImporter importer = (RecordImporter)recordImporter;

            Assert.That(importer.ReaderToEntityAdapter, Is.EqualTo(adapter));
            Assert.That(importer.Reporter, Is.EqualTo(reporter));
        }
示例#5
0
        public void Test_Constructor_Null_Argument(int arg)
        {
            IEntityRepository entityRepository = arg == 1 ? null : new Mock <IEntityRepository>( ).Object;
            IFileRepository   fileRepository   = arg == 2 ? null : new Mock <IFileRepository>( ).Object;

            RecordImporter.Factory recordImporterActivator = (readerToEntityAdapter, importReporter, mergeExisting, testRun) => new Mock <IRecordImporter>().Object;
            if (arg == 3)
            {
                recordImporterActivator = null;
            }
            Func <ImportFormat, IDataFileReaderService> readerActivator = arg == 4
                ? null
                : (Func <ImportFormat, IDataFileReaderService>)(impFormat => null);
            IReaderToEntityAdapterProvider readerToEntityAdapterProvider = arg == 5 ? null : new Mock <IReaderToEntityAdapterProvider>( ).Object;

            Assert.Throws <ArgumentNullException>(() => new ImportRunWorker(entityRepository, fileRepository, recordImporterActivator, readerActivator, readerToEntityAdapterProvider));
        }