public async Task GetAllProjectsInAuthFlow_GoodFlow([ProjectDataSource(50)] IEnumerable <Project> projects) { // Arrange dataSourceMock.As <IAuthorizedDataSourceAdaptee>().Setup(_ => _.GetAllProjects(It.IsAny <string>())) .ReturnsAsync(projects); // Act Action act = () => service.GetAllProjects(It.IsAny <string>(), It.IsAny <string>(), true); IEnumerable <Project> retrievedProjects = await service.GetAllProjects(It.IsAny <string>(), It.IsAny <string>(), true); // Assert act.Should().NotThrow(); retrievedProjects.Should().BeEquivalentTo(projects); }
public async Task <IActionResult> GetProjectsFromExternalDataSource( [FromQuery] string dataSourceGuid, [FromQuery] string token, [FromQuery] bool needsAuth) { if (!Guid.TryParse(dataSourceGuid, out Guid _)) { ProblemDetails problem = new ProblemDetails { Title = "Specified guid is not valid.", Detail = "The specified guid is not a real or valid guid.", Instance = "D84D3112-855D-480A-BCDE-7CADAC2C6C55" }; return(BadRequest(problem)); } if (!dataProviderService.IsExistingDataSourceGuid(dataSourceGuid)) { ProblemDetails problem = new ProblemDetails { Title = "Data source not found.", Detail = "Data source could not be found with specified data source guid.", Instance = "4FB90F9A-8499-40F1-B7F3-3C2838BDB1D4" }; return(NotFound(problem)); } try { IEnumerable <Project> projects = await dataProviderService.GetAllProjects(dataSourceGuid, token, needsAuth); return(Ok(mapper.Map <IEnumerable <Project>, IEnumerable <WizardProjectResourceResult> >(projects))); } catch (NotSupportedByExternalApiException e) { ProblemDetails problem = new ProblemDetails { Title = "External API does not support the functionality from the method.", Detail = e.Message, Instance = "8492B945-7C09-425B-9D1D-77869CE67146" }; return(BadRequest(problem)); } catch (ExternalException e) { ProblemDetails problem = new ProblemDetails { Title = "An problem encountered while using the external API.", Detail = e.Message, Instance = "DE7A6BFD-2A72-46CC-AB6E-1D8568F2EB19" }; return(BadRequest(problem)); } catch (NotSupportedException e) { ProblemDetails problem = new ProblemDetails { Title = "The specified data source is not supported.", Detail = e.Message, Instance = "E1500627-AAF8-46E3-9B20-8A3C952CDBC3" }; return(BadRequest(problem)); } }