public async Task GetProjectByIdInAuthFlow_GoodFlow([ProjectDataSource] Project project) { // Arrange dataSourceMock.As <IAuthorizedDataSourceAdaptee>().Setup(_ => _.GetProjectById(It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(project); // Act Action act = () => service.GetProjectById(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), true); Project retrievedProject = await service.GetProjectById(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), true); // Assert act.Should().NotThrow(); retrievedProject.Should().Be(project); }
public async Task <IActionResult> GetProjectByGuidFromExternalDataSource([FromQuery] string dataSourceGuid, [FromQuery] string token, string projectId, [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 = "019146D8-4162-43DD-8531-57DDD26E221C" }; 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 = "4E3837F4-9D35-40C4-AB7C-D325FBA225E6" }; return(NotFound(problem)); } try { Project project = await dataProviderService.GetProjectById(dataSourceGuid, token, projectId, needsAuth); if (project == null) { ProblemDetails problem = new ProblemDetails { Title = "Project not found.", Detail = "Project could not be found with specified project guid.", Instance = "0D96A77A-D35F-487C-B552-BF6D1C0CDD42" }; return(NotFound(problem)); } return(Ok(mapper.Map <Project, WizardProjectResourceResult>(project))); } catch (NotSupportedByExternalApiException e) { ProblemDetails problem = new ProblemDetails { Title = "External API does not support the functionality from the method.", Detail = e.Message, Instance = "F20B0D1F-D6B7-4BCE-9BC8-28B9E9618214" }; return(BadRequest(problem)); } catch (ExternalException e) { ProblemDetails problem = new ProblemDetails { Title = "An problem encountered while using the external API.", Detail = e.Message, Instance = "21D8A923-02CB-4F1B-86C0-88FDA002294D" }; return(BadRequest(problem)); } catch (NotSupportedException e) { ProblemDetails problem = new ProblemDetails { Title = "The specified data source is not supported.", Detail = e.Message, Instance = "0D02B0F5-71F8-427E-AB28-D4831B91639D" }; return(BadRequest(problem)); } }