Esempio n. 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;
        }
Esempio n. 2
0
        public IEntity RunTest(string json, ApiResourceMapping mapping, ReaderToEntityAdapterSettings settings = null)
        {
            if (json != null)
            {
                json = json.Replace("'", @"""");
            }

            // Get dynamic object from JSON
            object raw = JilHelpers.Deserialize <object>(json);

            Assert.That(raw, Is.InstanceOf <IDynamicMetaObjectProvider>( ), "Dynamic object should be IDynamicMetaObjectProvider");
            IDynamicMetaObjectProvider dynamicProvider = ( IDynamicMetaObjectProvider )raw;

            // Get object reader
            IDynamicObjectReaderService objectReaderService = Factory.Current.Resolve <IDynamicObjectReaderService>( );
            IObjectReader reader = objectReaderService.GetObjectReader(dynamicProvider);

            // Settings
            ReaderToEntityAdapterSettings settingsToUse = settings ?? new ReaderToEntityAdapterSettings();

            // Run adapter provider
            IReaderToEntityAdapterProvider adapterProvider = Factory.Current.Resolve <IReaderToEntityAdapterProvider>( );
            IReaderToEntityAdapter         adapter         = adapterProvider.GetAdapter(mapping.Id, settingsToUse);

            IEntity entity = adapter.CreateEntity(reader, ConnectorRequestExceptionReporter.Instance);

            return(entity);
        }
        private IReaderToEntityAdapterProvider GetProvider( )
        {
            IReaderToEntityAdapterProvider provider = Factory.Current.Resolve <IReaderToEntityAdapterProvider>( );

            Assert.That(provider, Is.InstanceOf <ReaderToEntityAdapterProvider>( ));
            return(provider);
        }
Esempio n. 4
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));
        }
Esempio n. 5
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="readerToEntityAdapterProvider">The reader to entity adapter provider.</param>
        /// <param name="resourceResolverProvider">The resource resolver provider.</param>
        /// <param name="resourceUriGenerator">The resource URI generator.</param>
        /// <exception cref="System.ArgumentNullException">
        /// readerToEntityAdapterProvider
        /// or
        /// resourceResolverProvider
        /// or
        /// resourceUriGenerator
        /// </exception>
        public ResourceEndpoint(IReaderToEntityAdapterProvider readerToEntityAdapterProvider, IResourceResolverProvider resourceResolverProvider, IResourceUriGenerator resourceUriGenerator)
        {
            if (readerToEntityAdapterProvider == null)
            {
                throw new ArgumentNullException("readerToEntityAdapterProvider");
            }
            if (resourceResolverProvider == null)
            {
                throw new ArgumentNullException("resourceResolverProvider");
            }
            if (resourceUriGenerator == null)
            {
                throw new ArgumentNullException("resourceUriGenerator");
            }

            _readerToEntityAdapterProvider = readerToEntityAdapterProvider;
            _resourceResolverProvider      = resourceResolverProvider;
            _resourceUriGenerator          = resourceUriGenerator;
        }
Esempio n. 6
0
        public void IReaderToEntityAdapterProvider_Instance( )
        {
            IReaderToEntityAdapterProvider instance = Factory.Current.Resolve <IReaderToEntityAdapterProvider>( );

            Assert.That(instance, Is.TypeOf <ReaderToEntityAdapterProvider>( ));
        }