예제 #1
0
        public async Task Init()
        {
            var mockFactory = new MockRepository(MockBehavior.Loose)
            {
                CallBase = true
            };
            var oaiPmhProjectImportManagerMock = mockFactory.Create <OaiPmhProjectImportManager>(new object[1]);

            oaiPmhProjectImportManagerMock.Setup(x => x.ImportFromResource(
                                                     It.IsAny <string>(),
                                                     It.IsAny <ITargetBlock <object> >(),
                                                     It.IsAny <RepositoryImportProgressInfo>(),
                                                     It.IsAny <DateTime?>(),
                                                     It.IsAny <CancellationToken>()))
            .Callback <string, ITargetBlock <object>, RepositoryImportProgressInfo, DateTime?, CancellationToken>(
                (config, target, progressInfo, dateTime, cancellationToken) =>
            {
                if (config == ThrowExc)
                {
                    throw new ImportFailedException("ImportFailed", "ImportFailed");
                }
                else if (config == ImportTwoRecords)
                {
                    target.Post(GetRecord(m_mockDataConstant.RecordOaiPmhMarc21JanHus));
                    target.Post(GetRecord(m_mockDataConstant.RecordOaiPmhMarc21JosefPekar));
                    progressInfo.TotalProjectsCount = 2;
                }
                else
                {
                    target.Post(GetRecord(config));
                    progressInfo.TotalProjectsCount = 1;
                }
            })
            .Returns(Task.CompletedTask);

            var permissionProviderMock = mockFactory.Create <IPermissionsProvider>();

            permissionProviderMock.Setup(x => x.GetRoleIdsByPermissionName(It.IsAny <string>())).Returns((IList <int>)null);

            var mockIoc = new MockIocContainer(true);

            mockIoc.ServiceCollection.Replace(new ServiceDescriptor(typeof(IProjectImportManager),
                                                                    oaiPmhProjectImportManagerMock.Object));
            mockIoc.ServiceCollection.Replace(new ServiceDescriptor(typeof(IPermissionsProvider), permissionProviderMock.Object));

            var serviceProvider = mockIoc.CreateServiceProvider();

            m_mainImportManager    = serviceProvider.GetRequiredService <MainImportManager>();
            m_importHistoryManager = serviceProvider.GetRequiredService <ImportHistoryManager>();
            m_mockDataConstant     = serviceProvider.GetRequiredService <MockDataConstant>();
            m_mockDataManager      = serviceProvider.GetRequiredService <MockDataManager>();
            m_projectRepository    = serviceProvider.GetRequiredService <ProjectRepository>();

            var backgroundService = serviceProvider.GetService <IHostedService>();
            await backgroundService.StartAsync(CancellationToken.None);
        }
예제 #2
0
        public void Init()
        {
            var mockIoc         = new MockIocContainer(true);
            var serviceProvider = mockIoc.CreateServiceProvider();

            m_mockDataManager                = serviceProvider.GetRequiredService <MockDataManager>();
            m_projectRepository              = serviceProvider.GetRequiredService <ProjectRepository>();
            m_metadataRepository             = serviceProvider.GetRequiredService <MetadataRepository>();
            m_personRepository               = serviceProvider.GetRequiredService <PersonRepository>();
            m_permissionRepository           = serviceProvider.GetRequiredService <PermissionRepository>();
            m_catalogValueRepository         = serviceProvider.GetRequiredService <CatalogValueRepository>();
            m_externalRepositoryRepository   = serviceProvider.GetRequiredService <ExternalRepositoryRepository>();
            m_importedProjectMetadataManager = serviceProvider.GetRequiredService <ImportedProjectMetadataManager>();

            m_importedRecord = new ImportedRecord
            {
                IsNew           = true,
                IsFailed        = false,
                IsDeleted       = false,
                ImportedProject = new ImportedProject
                {
                    Id = "1",
                    ProjectMetadata = new ProjectMetadata
                    {
                        Title         = "Title",
                        PublisherText = "PublisherText",
                        PublishDate   = "PublishDate",
                        PublishPlace  = "PublishPlace",
                    },
                    Authors = new HashSet <Author> {
                        new Author("Jan", "Hus")
                    },
                    Keywords = new List <string> {
                        "Keyword"
                    },
                    LiteraryGenres = new List <string> {
                        "LiteraryGenre"
                    }
                },
                ExternalId = "Ext1"
            };
        }