public void MapCreateProjectV5RequestToEvent() { var expectedProjectType = CwsProjectType.AcceptsTagFiles; var request = CreateProjectV5Request.CreateACreateProjectV5Request("projectName", _boundaryLL, _businessCenterFile); var projectValidation = MapV5Models.MapCreateProjectV5RequestToProjectValidation(request, _customerUid); Assert.Null(projectValidation.ProjectUid); Guid.TryParse(projectValidation.CustomerUid.ToString(), out var customerUidOut); Assert.Equal(_customerUid, customerUidOut.ToString()); Assert.Equal(expectedProjectType, projectValidation.ProjectType); Assert.Equal(request.ProjectName, projectValidation.ProjectName); Assert.Equal(_checkBoundaryString, projectValidation.ProjectBoundaryWKT); Assert.Equal(_businessCenterFile.Name, projectValidation.CoordinateSystemFileName); }
public async Task CreateProjectV5TBCExecutor_HappyPath() { var request = CreateProjectV5Request.CreateACreateProjectV5Request ("projectName", _boundaryLL, _businessCenterFile); var projectValidation = MapV5Models.MapCreateProjectV5RequestToProjectValidation(request, _customerUid.ToString()); Assert.Equal(_checkBoundaryString, projectValidation.ProjectBoundaryWKT); var coordSystemFileContent = "Some dummy content"; projectValidation.CoordinateSystemFileContent = System.Text.Encoding.ASCII.GetBytes(coordSystemFileContent); var createProjectResponseModel = new CreateProjectResponseModel() { TRN = _projectTrn }; var project = CreateProjectDetailModel(_customerTrn, _projectTrn, request.ProjectName); var projectList = CreateProjectListModel(_customerTrn, _projectTrn); var cwsProjectClient = new Mock <ICwsProjectClient>(); cwsProjectClient.Setup(pr => pr.CreateProject(It.IsAny <CreateProjectRequestModel>(), _customHeaders)).ReturnsAsync(createProjectResponseModel); cwsProjectClient.Setup(ps => ps.GetProjectsForCustomer(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <bool>(), It.IsAny <CwsProjectType?>(), It.IsAny <ProjectStatus?>(), It.IsAny <bool>(), It.IsAny <IHeaderDictionary>())).ReturnsAsync(projectList); cwsProjectClient.Setup(ps => ps.GetMyProject(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <IHeaderDictionary>())).ReturnsAsync(project); var httpContextAccessor = new HttpContextAccessor { HttpContext = new DefaultHttpContext() }; httpContextAccessor.HttpContext.Request.Path = new PathString("/api/v5/projects"); var productivity3dV1ProxyCoord = new Mock <IProductivity3dV1ProxyCoord>(); productivity3dV1ProxyCoord.Setup(p => p.CoordinateSystemValidate(It.IsAny <byte[]>(), It.IsAny <string>(), It.IsAny <HeaderDictionary>())) .ReturnsAsync(new CoordinateSystemSettingsResult()); productivity3dV1ProxyCoord.Setup(p => p.CoordinateSystemPost(It.IsAny <Guid>(), It.IsAny <byte[]>(), It.IsAny <string>(), It.IsAny <HeaderDictionary>())) .ReturnsAsync(new CoordinateSystemSettingsResult()); var dataOceanClient = new Mock <IDataOceanClient>(); dataOceanClient.Setup(f => f.FolderExists(It.IsAny <string>(), It.IsAny <HeaderDictionary>())).ReturnsAsync(true); dataOceanClient.Setup(f => f.PutFile(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Stream>(), It.IsAny <HeaderDictionary>())).ReturnsAsync(true); var projectConfigurationModel = new ProjectConfigurationModel { FileName = "some coord sys file", FileDownloadLink = "some download link" }; var cwsProfileSettingsClient = new Mock <ICwsProfileSettingsClient>(); cwsProfileSettingsClient.Setup(ps => ps.GetProjectConfiguration(It.IsAny <Guid>(), ProjectConfigurationFileType.CALIBRATION, _customHeaders)) .ReturnsAsync((ProjectConfigurationModel)null); cwsProfileSettingsClient.Setup(ps => ps.SaveProjectConfiguration(It.IsAny <Guid>(), ProjectConfigurationFileType.CALIBRATION, It.IsAny <ProjectConfigurationFileRequestModel>(), _customHeaders)) .ReturnsAsync(projectConfigurationModel); var authn = new Mock <ITPaaSApplicationAuthentication>(); authn.Setup(a => a.GetApplicationBearerToken()).Returns("some token"); var executor = RequestExecutorContainerFactory.Build <CreateProjectTBCExecutor> (_loggerFactory, _configStore, ServiceExceptionHandler, _customerUid.ToString(), _userUid.ToString(), null, _customHeaders, productivity3dV1ProxyCoord.Object, httpContextAccessor: httpContextAccessor, dataOceanClient: dataOceanClient.Object, authn: authn.Object, cwsProjectClient: cwsProjectClient.Object, cwsProfileSettingsClient: cwsProfileSettingsClient.Object); var result = await executor.ProcessAsync(projectValidation) as ProjectV6DescriptorsSingleResult; Assert.NotNull(result); Assert.False(string.IsNullOrEmpty(result.ProjectDescriptor.ProjectUid)); Assert.True(result.ProjectDescriptor.ShortRaptorProjectId != 0); Assert.Equal(request.ProjectName, result.ProjectDescriptor.Name); }
public async Task <ReturnLongV5Result> CreateProjectTBC([FromBody] CreateProjectV5Request projectRequest) { if (projectRequest == null) { ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 81); } Logger.LogInformation($"{nameof(CreateProjectTBC)} projectRequest: {JsonConvert.SerializeObject(projectRequest)}"); var projectValidation = MapV5Models.MapCreateProjectV5RequestToProjectValidation(projectRequest, CustomerUid); projectRequest.CoordinateSystem = ProjectDataValidator.ValidateBusinessCentreFile(projectRequest.CoordinateSystem); // Read CoordSystem file from TCC as byte[]. projectValidation.CoordinateSystemFileContent = await TccHelper .GetFileContentFromTcc(projectRequest.CoordinateSystem, Logger, ServiceExceptionHandler, FileRepo).ConfigureAwait(false); try { var resultPolygonWkt = PolygonUtils.MakeCounterClockwise(projectValidation.ProjectBoundaryWKT, out var hasBeenReversed); if (hasBeenReversed) { Logger.LogInformation($"{nameof(CreateProjectTBC)} Boundary has been reversed to: {projectValidation.ProjectBoundaryWKT}"); projectValidation.ProjectBoundaryWKT = resultPolygonWkt; } } catch (Exception e) { Logger.LogError(e, $"{nameof(CreateProjectTBC)} Boundary orientation check threw exception: "); throw; } var validationResult = await WithServiceExceptionTryExecuteAsync(() => RequestExecutorContainerFactory .Build <ValidateProjectExecutor>(LoggerFactory, ConfigStore, ServiceExceptionHandler, CustomerUid, UserId, null, customHeaders, Productivity3dV1ProxyCoord, cwsProjectClient : CwsProjectClient) .ProcessAsync(projectValidation) ); if (validationResult.Code != ContractExecutionStatesEnum.ExecutedSuccessfully) { ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, validationResult.Code); } var result = (await WithServiceExceptionTryExecuteAsync(() => RequestExecutorContainerFactory .Build <CreateProjectTBCExecutor>(LoggerFactory, ConfigStore, ServiceExceptionHandler, CustomerUid, UserId, null, customHeaders, Productivity3dV1ProxyCoord, dataOceanClient: DataOceanClient, authn: Authorization, cwsProjectClient: CwsProjectClient, cwsDeviceClient: CwsDeviceClient, cwsProfileSettingsClient: CwsProfileSettingsClient) .ProcessAsync(projectValidation)) as ProjectV6DescriptorsSingleResult ); Logger.LogInformation($"{nameof(CreateProjectTBC)}: completed successfully. ShortProjectId {result.ProjectDescriptor.ShortRaptorProjectId}"); return(ReturnLongV5Result.CreateLongV5Result(HttpStatusCode.Created, result.ProjectDescriptor.ShortRaptorProjectId)); }