public async Task <IActionResult> GetDataSourceById(string guid) { if (!Guid.TryParse(guid, out Guid _)) { ProblemDetails problem = new ProblemDetails { Title = "Specified guid is not valid.", Detail = "The specified guid is not a real or valid guid.", Instance = "64052C41-FB93-4733-918F-056C765044AE" }; return(BadRequest(problem)); } IDataSourceAdaptee dataSource = await dataProviderService.RetrieveDataSourceByGuid(guid); if (dataSource == null) { ProblemDetails problem = new ProblemDetails { Title = "No data source with the specified guid found.", Detail = "The database does not contain an institution with that guid.", Instance = "3B2C12E3-CDE0-4853-A687-C1024E096479" }; return(NotFound(problem)); } DataSourceResourceResult dataSourceResourceResult = mapper.Map <IDataSourceAdaptee, DataSourceResourceResult>(dataSource); return(Ok(dataSourceResourceResult)); }
/// <summary> /// This method is responsible for retrieving a project by id. /// </summary> /// <param name="dataSourceGuid">The data source guid that specifies which data source should get used.</param> /// <param name="token">The token which is used for retrieving all the projects. This can be a username or Oauth tokens.</param> /// <param name="id">The id of the project which will get used for searching the correct project.</param> /// <param name="needsAuth">The needsAuth parameter specifies which flow should get used.</param> /// <returns>This method returns a project with the specified identifier.</returns> public async Task <Project> GetProjectById(string dataSourceGuid, string token, string id, bool needsAuth) { IDataSourceAdaptee adaptee = await dataProviderLoader.GetDataSourceByGuid(dataSourceGuid); dataProviderAdapter = new DataProviderAdapter(adaptee); return(await dataProviderAdapter.GetProjectByGuid(token, id, needsAuth)); }
/// <summary> /// This method is responsible for retrieving all projects from a data source. /// </summary> /// <param name="dataSourceGuid">The data source guid that specifies which data source should get used.</param> /// <param name="token">The token which is used for retrieving all the projects. This can be a username or Oauth tokens.</param> /// <param name="needsAuth">The needsAuth parameter specifies which flow should get used.</param> /// <returns>This method returns a collection of projects.</returns> public async Task <IEnumerable <Project> > GetAllProjects(string dataSourceGuid, string token, bool needsAuth) { IDataSourceAdaptee adaptee = await dataProviderLoader.GetDataSourceByGuid(dataSourceGuid); dataProviderAdapter = new DataProviderAdapter(adaptee); return(await dataProviderAdapter.GetAllProjects(token, needsAuth)); }
/// <summary> /// This method is responsible for retrieving a project by uri. /// </summary> /// <param name="dataSourceGuid">The data source guid that specifies which data source should get used.</param> /// <param name="sourceUri">The source uri of the project which will get used for retrieving the correct project.</param> /// <returns>This method returns a project from the specified uri.</returns> public async Task <Project> GetProjectFromUri(string dataSourceGuid, string sourceUri) { IDataSourceAdaptee adaptee = await dataProviderLoader.GetDataSourceByGuid(dataSourceGuid); dataProviderAdapter = new DataProviderAdapter(adaptee); sourceUri = sourceUri.Replace("%2F", "/"); if (sourceUri[^ 1] == '/')
public async Task RetrieveDataSourceByName_GoodFlow() { // Arrange // Act Action act = () => service.RetrieveDataSourceByName(It.IsAny <string>()); IDataSourceAdaptee retrievedAdaptee = await service.RetrieveDataSourceByName(It.IsAny <string>()); // Assert act.Should().NotThrow(); retrievedAdaptee.Should().NotBeNull(); retrievedAdaptee.Should().BeAssignableTo(typeof(IDataSourceAdaptee)); }
public async Task RetrieveDataSourceByName_NoDataSourceFound() { // Arrange loaderMock.Setup(_ => _.GetDataSourceByName(It.IsAny <string>())) .ReturnsAsync((IDataSourceAdaptee)null); // Act Action act = () => service.RetrieveDataSourceByName(It.IsAny <string>()); IDataSourceAdaptee retrievedAdaptee = await service.RetrieveDataSourceByName(It.IsAny <string>()); // Assert act.Should().NotThrow(); retrievedAdaptee.Should().BeNull(); }
private async Task <List <IDataSourceAdaptee> > UpdateModelsWithRepositoryValues(List <IDataSourceAdaptee> sources) { DataSource[] sourceModels = (await dataSourceModelRepository.GetAll()).ToArray(); foreach (DataSource sourceModel in sourceModels) { IDataSourceAdaptee source = sources.SingleOrDefault(s => s.Guid == sourceModel.Guid); if (source == null) { continue; } source.Title = sourceModel.Title; source.Description = sourceModel.Description; source.IsVisible = sourceModel.IsVisible; source.Icon = sourceModel.Icon; source.DataSourceWizardPages = sourceModel.DataSourceWizardPages.OrderBy(page => page.AuthFlow) .ThenBy(page => page.OrderIndex) .ToList(); } return(sources); }
public async Task GetDataSourceByName_NoDataSourceFound() { // Arrange assemblyHelperMock.Setup(_ => _.RetrieveTypesFromExecutingAssemblyFolderFolderByInterface(It.IsAny <Type>())) .Returns(new Type[0]); Mock <IServiceScope> scopeMock = new Mock <IServiceScope>(); scopeMock .Setup(_ => _.ServiceProvider.GetService(It.IsAny <Type>())) .Returns((IDataSourceAdaptee)null); factoryMock.Setup(_ => _.CreateScope()) .Returns(scopeMock.Object); // Act Action act = () => loader.GetDataSourceByName(It.IsAny <string>()); IDataSourceAdaptee retrievedDataSource = await loader.GetDataSourceByName(It.IsAny <string>()); // Assert act.Should().NotThrow(); retrievedDataSource.Should().BeNull(); scopeMock.Verify(_ => _.ServiceProvider.GetService(It.IsAny <Type>()), Times.Exactly(0)); }
public async Task GetDataSourceByName_GoodFlow() { // Arrange returnedTypesFromAssembly = new Type[] { typeof(GithubDataSourceAdaptee) }; assemblyHelperMock.Setup(_ => _.RetrieveTypesFromExecutingAssemblyFolderFolderByInterface(It.IsAny <Type>())) .Returns(returnedTypesFromAssembly); string name = "TestSource"; returnedTypeFromLoader = new Mock <IDataSourceAdaptee>().As <IDataSourceAdaptee>(); returnedTypeFromLoader.Setup(_ => _.Title) .Returns(name); Mock <IServiceScope> scopeMock = new Mock <IServiceScope>(); scopeMock .Setup(_ => _.ServiceProvider.GetService(It.IsAny <Type>())) .Returns(returnedTypeFromLoader.Object); factoryMock.Setup(_ => _.CreateScope()) .Returns(scopeMock.Object); // Act Action act = () => loader.GetDataSourceByName(name); IDataSourceAdaptee retrievedDataSource = await loader.GetDataSourceByName(name); // Assert act.Should().NotThrow(); retrievedDataSource.Should().NotBeNull(); retrievedDataSource.Title.Should().Be(name); scopeMock.Verify(_ => _.ServiceProvider.GetService(It.IsAny <Type>()), Times.Exactly(2)); }
public DataProviderAdapter(IDataSourceAdaptee adaptee) { this.adaptee = adaptee; }