예제 #1
0
        public async Task GetProjectFromUri_GoodFlow([ProjectDataSource] Project project)
        {
            // Arrange
            dataSourceMock.As <IPublicDataSourceAdaptee>()
            .Setup(_ => _.GetPublicProjectFromUri(It.IsAny <Uri>()))
            .ReturnsAsync(project);

            // Act
            Action  act = () => service.GetProjectFromUri(It.IsAny <string>(), "https://google.nl/test");
            Project retrievedProject =
                await service.GetProjectFromUri(It.IsAny <string>(), "https://google.nl/test");

            // Assert
            act.Should().NotThrow();
            retrievedProject.Should().Be(project);
        }
예제 #2
0
        public async Task <IActionResult> GetProjectByUriFromExternalDataSource(
            [FromQuery] string dataSourceGuid,
            string sourceUri)
        {
            if (sourceUri == null)
            {
                ProblemDetails problem = new ProblemDetails
                {
                    Title    = "Source uri is null or empty.",
                    Detail   = "The incoming source uri is not valid.",
                    Instance = "6D63D9FA-91D6-42D5-9ACB-461FBEB0D2ED"
                };
                return(BadRequest(problem));
            }

            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 = "9FAF4C56-5B09-46C2-9A52-902D82ADAFA6"
                };
                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 = "DA33EB64-13EF-46CC-B3E6-785E4027377A"
                };
                return(NotFound(problem));
            }

            try
            {
                Project project = await dataProviderService.GetProjectFromUri(dataSourceGuid, sourceUri);

                if (project == null)
                {
                    ProblemDetails problem = new ProblemDetails
                    {
                        Title  = "Project could not be found.",
                        Detail =
                            "The project could not be found with the specified source Uri and data source guid.",
                        Instance = "993252E8-61C4-422D-A547-EB9F56BA47B7"
                    };
                    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 = "DD815174-8711-4EF0-B01B-776709EDF485"
                };
                return(BadRequest(problem));
            } catch (ExternalException e)
            {
                ProblemDetails problem = new ProblemDetails
                {
                    Title    = "An problem encountered while using the external API.",
                    Detail   = e.Message,
                    Instance = "AA4FC30F-85F0-4120-A479-728DADABAB32"
                };
                return(BadRequest(problem));
            } catch (NotSupportedException e)
            {
                ProblemDetails problem = new ProblemDetails
                {
                    Title    = "The specified data source is not supported.",
                    Detail   = e.Message,
                    Instance = "E7834AC0-43D0-4D40-AB7C-E120A6EFCD5B"
                };
                return(BadRequest(problem));
            }
        }