/// <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)); }
public async Task GetDataSourceByGuid_GoodFlow() { // Arrange returnedTypesFromAssembly = new Type[] { typeof(GithubDataSourceAdaptee) }; assemblyHelperMock.Setup(_ => _.RetrieveTypesFromExecutingAssemblyFolderFolderByInterface(It.IsAny <Type>())) .Returns(returnedTypesFromAssembly); string guid = "de38e528-1d6d-40e7-83b9-4334c51c19be"; returnedTypeFromLoader = new Mock <IDataSourceAdaptee>().As <IDataSourceAdaptee>(); returnedTypeFromLoader.Setup(_ => _.Guid) .Returns(guid); 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.GetDataSourceByGuid(guid); IDataSourceAdaptee retrievedDataSource = await loader.GetDataSourceByGuid(guid); // Assert act.Should().NotThrow(); retrievedDataSource.Should().NotBeNull(); retrievedDataSource.Guid.Should().Be(guid); scopeMock.Verify(_ => _.ServiceProvider.GetService(It.IsAny <Type>()), Times.Exactly(2)); }