public async Task <ProjectSettingsResult> UpsertProjectSettings([FromBody] ProjectSettingsRequest request) { if (string.IsNullOrEmpty(request?.projectUid)) { ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 68); } LogCustomerDetails("UpsertProjectSettings", request?.projectUid); Logger.LogDebug($"UpsertProjectSettings: {JsonConvert.SerializeObject(request)}"); request.ProjectSettingsType = ProjectSettingsType.Targets; var projectSettingsRequest = _requestFactory.Create <ProjectSettingsRequestHelper>(r => r .CustomerUid(CustomerUid)) .CreateProjectSettingsRequest(request.projectUid, request.Settings, request.ProjectSettingsType); projectSettingsRequest.Validate(); var result = (await WithServiceExceptionTryExecuteAsync(() => RequestExecutorContainerFactory .Build <UpsertProjectSettingsExecutor>(LoggerFactory, ConfigStore, ServiceExceptionHandler, CustomerUid, UserId, headers: customHeaders, productivity3dV2ProxyCompaction: Productivity3dV2ProxyCompaction, projectRepo: ProjectRepo, cwsProjectClient: CwsProjectClient) .ProcessAsync(projectSettingsRequest) )) as ProjectSettingsResult; await NotifyChanges(UserId, request.projectUid); Logger.LogResult(this.ToString(), JsonConvert.SerializeObject(request), result); return(result); }
public async Task GetProjectSettingsExecutor_ProjectCustomerValidationFails() { var projectRepo = new Mock <IProjectRepository>(); projectRepo.Setup(ps => ps.GetProjectSettings(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <ProjectSettingsType>())).ReturnsAsync((ProjectSettings)null); var cwsProjectClient = new Mock <ICwsProjectClient>(); 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(new ProjectDetailListResponseModel()); var configStore = ServiceProvider.GetRequiredService <IConfigurationStore>(); var logger = ServiceProvider.GetRequiredService <ILoggerFactory>(); var serviceExceptionHandler = ServiceProvider.GetRequiredService <IServiceExceptionHandler>(); var projectErrorCodesProvider = ServiceProvider.GetRequiredService <IErrorCodesProvider>(); var projectSettingsRequest = ProjectSettingsRequest.CreateProjectSettingsRequest(_projectUid.ToString(), string.Empty, ProjectSettingsType.Targets); var executor = RequestExecutorContainerFactory.Build <GetProjectSettingsExecutor> (logger, configStore, serviceExceptionHandler, _customerUid.ToString(), _userUid.ToString(), projectRepo: projectRepo.Object, cwsProjectClient: cwsProjectClient.Object); var ex = await Assert.ThrowsAsync <ServiceException>(async() => await executor.ProcessAsync(projectSettingsRequest)); Assert.NotEqual(-1, ex.GetContent.IndexOf(projectErrorCodesProvider.FirstNameWithOffset(1))); }
public async Task UpsertProjectSettingsExecutor_InvalidCustomerProjectRelationship(ProjectSettingsType settingsType) { var customerUidOfProject = Guid.NewGuid().ToString(); var customerUidSomeOther = Guid.NewGuid().ToString(); var userId = Guid.NewGuid().ToString(); var userEmailAddress = "*****@*****.**"; var settings = "blah"; var settingsUpdated = "blah Is Updated"; var project = await ExecutorTestFixture.CreateCustomerProject(customerUidOfProject); Assert.NotNull(project); var isCreatedOk = ExecutorTestFixture.CreateProjectSettings(project.Id, userId, settings, settingsType); Assert.True(isCreatedOk, "created projectSettings"); var projectSettingsRequest = ProjectSettingsRequest.CreateProjectSettingsRequest(project.Id, settingsUpdated, settingsType); var executor = RequestExecutorContainerFactory.Build <UpsertProjectSettingsExecutor> (ExecutorTestFixture.Logger, ExecutorTestFixture.ConfigStore, ExecutorTestFixture.ServiceExceptionHandler, customerUidSomeOther, userId, userEmailAddress, ExecutorTestFixture.CustomHeaders(customerUidOfProject), productivity3dV2ProxyCompaction: ExecutorTestFixture.Productivity3dV2ProxyCompaction, projectRepo: ExecutorTestFixture.ProjectRepo, cwsProjectClient: ExecutorTestFixture.CwsProjectClient); var ex = await Assert.ThrowsAsync <ServiceException>(async() => await executor.ProcessAsync(projectSettingsRequest)).ConfigureAwait(false); Assert.NotEqual(-1, ex.GetContent.IndexOf("2001", StringComparison.Ordinal)); Assert.NotEqual(-1, ex.GetContent.IndexOf("No access to the project for a customer or the project does not exist.", StringComparison.Ordinal)); }
public async Task GetProjectSettingsExecutor_NoSettingsExists(ProjectSettingsType settingsType) { var customerUid = Guid.NewGuid().ToString(); var userId = Guid.NewGuid().ToString(); var userEmailAddress = "*****@*****.**"; var project = await ExecutorTestFixture.CreateCustomerProject(customerUid); Assert.NotNull(project); var settings = string.Empty; var projectSettingsRequest = ProjectSettingsRequest.CreateProjectSettingsRequest(project.Id, settings, settingsType); var executor = RequestExecutorContainerFactory.Build <GetProjectSettingsExecutor> (ExecutorTestFixture.Logger, ExecutorTestFixture.ConfigStore, ExecutorTestFixture.ServiceExceptionHandler, customerUid, userId, userEmailAddress, ExecutorTestFixture.CustomHeaders(customerUid), projectRepo: ExecutorTestFixture.ProjectRepo, cwsProjectClient: ExecutorTestFixture.CwsProjectClient); var projectSettingsResult = await executor.ProcessAsync(projectSettingsRequest) as ProjectSettingsResult; Assert.NotNull(projectSettingsResult); Assert.Equal(project.Id, projectSettingsResult.ProjectUid); Assert.Null(projectSettingsResult.Settings); Assert.Equal(settingsType, projectSettingsResult.ProjectSettingsType); }
public async Task GetProjectSettingsExecutor_DataExists(ProjectSettingsType settingsType) { var settings = string.Empty; var projectRepo = new Mock <IProjectRepository>(); var projectSettings = new ProjectSettings { ProjectUid = _projectUid.ToString(), Settings = settings, ProjectSettingsType = settingsType, UserID = _userUid.ToString() }; projectRepo.Setup(ps => ps.GetProjectSettings(It.IsAny <string>(), _userUid.ToString(), settingsType)).ReturnsAsync(projectSettings); var projectList = CreateProjectListModel(_customerTrn, _projectTrn); var cwsProjectClient = new Mock <ICwsProjectClient>(); 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); var configStore = ServiceProvider.GetRequiredService <IConfigurationStore>(); var logger = ServiceProvider.GetRequiredService <ILoggerFactory>(); var serviceExceptionHandler = ServiceProvider.GetRequiredService <IServiceExceptionHandler>(); var projectSettingsRequest = ProjectSettingsRequest.CreateProjectSettingsRequest(_projectUid.ToString(), settings, settingsType); var executor = RequestExecutorContainerFactory.Build <GetProjectSettingsExecutor> (logger, configStore, serviceExceptionHandler, _customerUid.ToString(), _userUid.ToString(), projectRepo: projectRepo.Object, cwsProjectClient: cwsProjectClient.Object); var result = await executor.ProcessAsync(projectSettingsRequest) as ProjectSettingsResult; Assert.NotNull(result); Assert.Equal(_projectUid.ToString(), result.ProjectUid); Assert.Null(result.Settings); Assert.Equal(settingsType, result.ProjectSettingsType); }
private async Task RaptorValidateProjectSettings(ProjectSettingsRequest request) { BaseMasterDataResult result = null; try { result = await productivity3dV2ProxyCompaction .ValidateProjectSettings(request, customHeaders) .ConfigureAwait(false); } catch (Exception e) { log.LogError(e, $"RaptorValidateProjectSettings: RaptorServices failed with exception. projectUid:{request.projectUid} settings:{request.Settings}"); serviceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 70, "productivity3dV2ProxyCompaction.ValidateProjectSettings", e.Message); } log.LogDebug( $"RaptorValidateProjectSettings: projectUid: {request.projectUid} settings: {request.Settings}. RaptorServices returned code: {result?.Code ?? -1} Message {result?.Message ?? "result == null"}."); if (result != null && result.Code != 0) { log.LogError( $"RaptorValidateProjectSettings: RaptorServices failed. projectUid:{request.projectUid} settings:{request.Settings}. Reason: {result?.Code ?? -1} {result?.Message ?? "null"}. "); serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 67, result.Code.ToString(), result.Message); } }
public async Task UpsertProjectSettingsExecutor(ProjectSettingsType settingsType) { var settings = settingsType != ProjectSettingsType.ImportedFiles ? @"{firstValue: 10, lastValue: 20}" : @"[{firstValue: 10, lastValue: 20}, {firstValue: 20, lastValue: 40}]"; var projectRepo = new Mock <IProjectRepository>(); var projectSettings = new ProjectSettings { ProjectUid = _projectUid.ToString(), Settings = settings, ProjectSettingsType = settingsType, UserID = _userUid.ToString() }; projectRepo.Setup(ps => ps.GetProjectSettings(It.IsAny <string>(), _userUid.ToString(), settingsType)).ReturnsAsync(projectSettings); projectRepo.Setup(ps => ps.StoreEvent(It.IsAny <UpdateProjectSettingsEvent>())).ReturnsAsync(1); var projectList = CreateProjectListModel(_customerTrn, _projectTrn); var cwsProjectClient = new Mock <ICwsProjectClient>(); 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); var configStore = ServiceProvider.GetRequiredService <IConfigurationStore>(); var logger = ServiceProvider.GetRequiredService <ILoggerFactory>(); var serviceExceptionHandler = ServiceProvider.GetRequiredService <IServiceExceptionHandler>(); var productivity3dV2ProxyCompaction = new Mock <IProductivity3dV2ProxyCompaction>(); productivity3dV2ProxyCompaction.Setup(r => r.ValidateProjectSettings(It.IsAny <ProjectSettingsRequest>(), It.IsAny <HeaderDictionary>())).ReturnsAsync(new BaseMasterDataResult()); var executor = RequestExecutorContainerFactory.Build <UpsertProjectSettingsExecutor> (logger, configStore, serviceExceptionHandler, _customerUid.ToString(), _userUid.ToString(), null, null, productivity3dV2ProxyCompaction: productivity3dV2ProxyCompaction.Object, projectRepo: projectRepo.Object, cwsProjectClient: cwsProjectClient.Object); var projectSettingsRequest = ProjectSettingsRequest.CreateProjectSettingsRequest(_projectUid.ToString(), settings, settingsType); var result = await executor.ProcessAsync(projectSettingsRequest) as ProjectSettingsResult; Assert.NotNull(result); Assert.Equal(_projectUid.ToString(), result.ProjectUid); Assert.NotNull(result.Settings); Assert.Equal(settingsType, result.ProjectSettingsType); if (settingsType == ProjectSettingsType.Targets || settingsType == ProjectSettingsType.Colors) { var tempSettings = JsonConvert.DeserializeObject <JObject>(settings); Assert.Equal(tempSettings["firstValue"], result.Settings["firstValue"]); Assert.Equal(tempSettings["lastValue"], result.Settings["lastValue"]); } else { var tempObj = JsonConvert.DeserializeObject <JArray>(settings); var tempJObject = new JObject { ["importedFiles"] = tempObj }; Assert.Equal(tempJObject["importedFiles"][0]["firstValue"], result.Settings["importedFiles"][0]["firstValue"]); Assert.Equal(tempJObject["importedFiles"][0]["lastValue"], result.Settings["importedFiles"][0]["lastValue"]); Assert.Equal(tempJObject["importedFiles"][1]["firstValue"], result.Settings["importedFiles"][1]["firstValue"]); Assert.Equal(tempJObject["importedFiles"][1]["lastValue"], result.Settings["importedFiles"][1]["lastValue"]); } }
public BaseDataResult DummyValidateProjectSettingsPost([FromBody] ProjectSettingsRequest request) { var res = new BaseDataResult(); var message = $"DummyValidateProjectSettingsGet: res {res}. projectSettings {request.Settings}"; Logger.LogInformation(message); return(res); }
public void ProjectSettingsRequestShouldNotSerializeType() { var settings = "blah"; var request = ProjectSettingsRequest.CreateProjectSettingsRequest(_projectUid.ToString(), settings, ProjectSettingsType.Targets); var json = JsonConvert.SerializeObject(request); Assert.DoesNotContain("ProjectSettingsType", json); }
public ContractExecutionResult ValidateProjectSettings([FromBody] ProjectSettingsRequest request, [FromServices] IServiceExceptionHandler serviceExceptionHandler) { log.LogDebug($"UpsertProjectSettings: {JsonConvert.SerializeObject(request)}"); request.Validate(); return(ValidateProjectSettingsEx(request.projectUid, request.Settings, request.ProjectSettingsType, serviceExceptionHandler)); }
public void UpsertProjectSettingsExecutor_InvalidProjectSettings(ProjectSettingsType settingsType) { var projectUid = Guid.NewGuid().ToString(); var projectSettingsRequest = ProjectSettingsRequest.CreateProjectSettingsRequest(projectUid, null, settingsType); var ex = Assert.Throws <ServiceException>(() => projectSettingsRequest.Validate()); Assert.NotEqual(-1, ex.GetContent.IndexOf("2073", StringComparison.Ordinal)); Assert.NotEqual(-1, ex.GetContent.IndexOf("ProjectSettings cannot be null.", StringComparison.Ordinal)); }
public void GetProjectSettingsExecutor_InvalidProjectUid(ProjectSettingsType settingsType) { var projectUid = string.Empty; var settings = string.Empty; var projectSettingsRequest = ProjectSettingsRequest.CreateProjectSettingsRequest(projectUid, settings, settingsType); var ex = Assert.Throws <ServiceException>(() => projectSettingsRequest.Validate()); Assert.NotEqual(-1, ex.GetContent.IndexOf("2005", StringComparison.Ordinal)); Assert.NotEqual(-1, ex.GetContent.IndexOf("Missing ProjectUID.", StringComparison.Ordinal)); }
public async Task UpsertProjectSettingsExecutor_Exists(ProjectSettingsType settingsType) { var customerUid = Guid.NewGuid().ToString(); var userId = Guid.NewGuid().ToString(); var userEmailAddress = "*****@*****.**"; var settings = "blah"; var settingsUpdated = settingsType != ProjectSettingsType.ImportedFiles ? @"{firstValue: 10, lastValue: 20}" : @"[{firstValue: 10, lastValue: 20}, {firstValue: 20, lastValue: 40}]"; var project = await ExecutorTestFixture.CreateCustomerProject(customerUid); Assert.NotNull(project); var isCreatedOk = ExecutorTestFixture.CreateProjectSettings(project.Id, userId, settings, settingsType); Assert.True(isCreatedOk, "created projectSettings"); var projectSettingsRequest = ProjectSettingsRequest.CreateProjectSettingsRequest(project.Id, settingsUpdated, settingsType); var executor = RequestExecutorContainerFactory.Build <UpsertProjectSettingsExecutor> (ExecutorTestFixture.Logger, ExecutorTestFixture.ConfigStore, ExecutorTestFixture.ServiceExceptionHandler, customerUid, userId, userEmailAddress, ExecutorTestFixture.CustomHeaders(customerUid), productivity3dV2ProxyCompaction: ExecutorTestFixture.Productivity3dV2ProxyCompaction, projectRepo: ExecutorTestFixture.ProjectRepo, cwsProjectClient: ExecutorTestFixture.CwsProjectClient); var result = await executor.ProcessAsync(projectSettingsRequest) as ProjectSettingsResult; Assert.NotNull(result); Assert.Equal(project.Id, result.ProjectUid); Assert.Equal(settingsType, result.ProjectSettingsType); if (settingsType == ProjectSettingsType.Targets || settingsType == ProjectSettingsType.Colors) { var tempSettings = JsonConvert.DeserializeObject <JObject>(settingsUpdated); Assert.Equal(tempSettings["firstValue"], result.Settings["firstValue"]); Assert.Equal(tempSettings["lastValue"], result.Settings["lastValue"]); } else { var tempObj = JsonConvert.DeserializeObject <JArray>(settingsUpdated); var tempJObject = new JObject { ["importedFiles"] = tempObj }; Assert.Equal(tempJObject["importedFiles"][0]["firstValue"], result.Settings["importedFiles"][0]["firstValue"]); Assert.Equal(tempJObject["importedFiles"][0]["lastValue"], result.Settings["importedFiles"][0]["lastValue"]); Assert.Equal(tempJObject["importedFiles"][1]["firstValue"], result.Settings["importedFiles"][1]["firstValue"]); Assert.Equal(tempJObject["importedFiles"][1]["lastValue"], result.Settings["importedFiles"][1]["lastValue"]); } }
public async Task AddProjectSettingsThenUpdateThem() { const string testText = "Project settings test 4"; Msg.Title(testText, "Add project settings for a project monitoring project"); var ts = new TestSupport(); var customerUid = Guid.NewGuid(); var createProjectResponse = ExecutorTestFixture.CreateCustomerProject(customerUid.ToString(), testText, Boundaries.Boundary1); ts.ProjectUid = new Guid(createProjectResponse.Result.Id); // Now create the settings var projectSettings = "{useMachineTargetPassCount: false,customTargetPassCountMinimum: 5}"; projectSettings = projectSettings.Replace(" ", string.Empty); var projSettings = ProjectSettingsRequest.CreateProjectSettingsRequest(ts.ProjectUid.ToString(), projectSettings, ProjectSettingsType.Targets); var configJson = JsonConvert.SerializeObject(projSettings, new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Unspecified }); await ts.CallProjectWebApi("api/v4/projectsettings", HttpMethod.Put, configJson, customerUid.ToString()); var projectSettings1 = "{customTargetPassCountMaximum: 7,useMachineTargetTemperature: false,customTargetTemperatureMinimum: 75}"; projectSettings1 = projectSettings1.Replace(" ", string.Empty); var projSettings1 = ProjectSettingsRequest.CreateProjectSettingsRequest(ts.ProjectUid.ToString(), projectSettings1, ProjectSettingsType.Targets); var configJson2 = JsonConvert.SerializeObject(projSettings1, new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Unspecified }); var response1 = await ts.CallProjectWebApi("api/v4/projectsettings", HttpMethod.Put, configJson2, customerUid.ToString()); var objresp = JsonConvert.DeserializeObject <ProjectSettingsResult>(response1); var tempSettings = JsonConvert.SerializeObject(objresp.Settings).Replace("\"", string.Empty); Assert.Equal(projectSettings1, tempSettings); Assert.Equal(ts.ProjectUid.ToString(), objresp.ProjectUid); // get call var response2 = await ts.CallProjectWebApi($"api/v4/projectsettings/{ts.ProjectUid}", HttpMethod.Get, null, customerUid.ToString()); var objresp1 = JsonConvert.DeserializeObject <ProjectSettingsResult>(response2); tempSettings = JsonConvert.SerializeObject(objresp1.Settings).Replace("\"", string.Empty); Assert.Equal(projectSettings1, tempSettings); Assert.Equal(ts.ProjectUid.ToString(), objresp1.ProjectUid); }
/// <summary> /// Validates the Settings for the project. /// </summary> public async Task <BaseMasterDataResult> ValidateProjectSettings(ProjectSettingsRequest request, IHeaderDictionary customHeaders = null) { log.LogDebug($"{nameof(ValidateProjectSettings)} 3) projectUid: {request.projectUid}"); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(request)))) { var result = await SendMasterDataItemServiceDiscoveryNoCache <BaseMasterDataResult>("/validatesettings", customHeaders, HttpMethod.Post, payload : ms); if (result.Code == 0) { return(result); } } log.LogDebug($"{nameof(ValidateProjectSettings)} Failed to post request"); return(null); }
public async Task GetProjectSettingsExecutor_MultipleSettings() { var settings1 = string.Empty; var settings2 = @"{firstValue: 10, lastValue: 20}"; var settingsType1 = ProjectSettingsType.ImportedFiles; var settingsType2 = ProjectSettingsType.Targets; var projectRepo = new Mock <IProjectRepository>(); var projectSettings1 = new ProjectSettings { ProjectUid = _projectUid.ToString(), Settings = settings1, ProjectSettingsType = settingsType1, UserID = _userUid.ToString() }; projectRepo.Setup(ps => ps.GetProjectSettings(It.IsAny <string>(), _userUid.ToString(), settingsType1)).ReturnsAsync(projectSettings1); var projectSettings2 = new ProjectSettings { ProjectUid = _projectUid.ToString(), Settings = settings2, ProjectSettingsType = settingsType2, UserID = _userUid.ToString() }; projectRepo.Setup(ps => ps.GetProjectSettings(It.IsAny <string>(), _userUid.ToString(), settingsType2)).ReturnsAsync(projectSettings2); var projectList = CreateProjectListModel(_customerTrn, _projectTrn); var cwsProjectClient = new Mock <ICwsProjectClient>(); 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); var configStore = ServiceProvider.GetRequiredService <IConfigurationStore>(); var logger = ServiceProvider.GetRequiredService <ILoggerFactory>(); var serviceExceptionHandler = ServiceProvider.GetRequiredService <IServiceExceptionHandler>(); var projectSettingsRequest = ProjectSettingsRequest.CreateProjectSettingsRequest(_projectUid.ToString(), settings2, settingsType2); var executor = RequestExecutorContainerFactory.Build <GetProjectSettingsExecutor> (logger, configStore, serviceExceptionHandler, _customerUid.ToString(), _userUid.ToString(), projectRepo: projectRepo.Object, cwsProjectClient: cwsProjectClient.Object); var result = await executor.ProcessAsync(projectSettingsRequest) as ProjectSettingsResult; var tempSettings = JsonConvert.DeserializeObject <JObject>(settings2); Assert.NotNull(result); Assert.Equal(_projectUid.ToString(), result.ProjectUid); Assert.NotNull(result.Settings); Assert.Equal(tempSettings["firstValue"], result.Settings["firstValue"]); Assert.Equal(tempSettings["lastValue"], result.Settings["lastValue"]); Assert.Equal(settingsType2, result.ProjectSettingsType); }
public async Task AddInvalidProjectSettings() { const string testText = "Project settings test 2"; Msg.Title(testText, "Add project settings for a standard project with invalid project UID"); var ts = new TestSupport(); var projectUid = Guid.NewGuid().ToString(); var customerUid = Guid.NewGuid(); var projectSettings = "{ Invalid project UID }"; var projSettings = ProjectSettingsRequest.CreateProjectSettingsRequest(projectUid, projectSettings, ProjectSettingsType.Targets); var configJson = JsonConvert.SerializeObject(projSettings, new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Unspecified }); var response = await ts.CallProjectWebApi("api/v4/projectsettings", HttpMethod.Put, configJson, customerUid.ToString(), statusCode : HttpStatusCode.BadRequest); Assert.True(response == "{\"code\":2001,\"message\":\"No access to the project for a customer or the project does not exist.\"}", "Actual response different to expected"); // Try to get the project that doesn't exist var response1 = await ts.CallProjectWebApi($"api/v4/projectsettings/{projectUid}", HttpMethod.Get, null, customerUid.ToString(), statusCode : HttpStatusCode.BadRequest); Assert.True(response1 == "{\"code\":2001,\"message\":\"No access to the project for a customer or the project does not exist.\"}", "Actual response different to expected"); }
public async Task AddEmptyProjectSettings() { const string testText = "Project settings test 3"; Msg.Title(testText, "Add project settings for a project monitoring project"); var ts = new TestSupport(); var customerUid = Guid.NewGuid(); var createProjectResponse = ExecutorTestFixture.CreateCustomerProject(customerUid.ToString(), testText, Boundaries.Boundary1); ts.ProjectUid = new Guid(createProjectResponse.Result.Id); // Now create the settings var projectSettings = string.Empty; var projSettings = ProjectSettingsRequest.CreateProjectSettingsRequest(ts.ProjectUid.ToString(), projectSettings, ProjectSettingsType.Targets); var configJson = JsonConvert.SerializeObject(projSettings, new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Unspecified }); var response = await ts.CallProjectWebApi("api/v4/projectsettings", HttpMethod.Put, configJson, customerUid.ToString()); var objresp = JsonConvert.DeserializeObject <ProjectSettingsResult>(response); var tempSettings = objresp.Settings == null ? string.Empty : JsonConvert.SerializeObject(objresp.Settings).Replace("\"", string.Empty); Assert.Equal(projectSettings, tempSettings); //Assert.Equal(ts.ProjectUid, objresp.projectUid); // get call var response1 = await ts.CallProjectWebApi($"api/v4/projectsettings/{ts.ProjectUid}", HttpMethod.Get, null, customerUid.ToString()); var objresp1 = JsonConvert.DeserializeObject <ProjectSettingsResult>(response1); tempSettings = objresp1.Settings == null ? string.Empty : JsonConvert.SerializeObject(objresp1.Settings).Replace("\"", string.Empty); Assert.Equal(projectSettings, tempSettings); //Assert.Equal(ts.ProjectUid, objresp1.projectUid); }
public async Task AddProjectSettingsGoodPath() { const string testText = "Project settings test 1"; Msg.Title(testText, "Add project settings for a standard project"); var ts = new TestSupport(); var customerUid = Guid.NewGuid(); var response = ExecutorTestFixture.CreateCustomerProject(customerUid.ToString(), testText, Boundaries.Boundary1); ts.ProjectUid = new Guid(response.Result.Id); // Now create the settings var projectSettings1 = "{ useMachineTargetPassCount: false,customTargetPassCountMinimum: 5,customTargetPassCountMaximum: 7,useMachineTargetTemperature: false,customTargetTemperatureMinimum: 75," + "customTargetTemperatureMaximum: 150,useMachineTargetCmv: false,customTargetCmv: 77,useMachineTargetMdp: false,customTargetMdp: 88,useDefaultTargetRangeCmvPercent: false," + "customTargetCmvPercentMinimum: 75,customTargetCmvPercentMaximum: 105,useDefaultTargetRangeMdpPercent: false,customTargetMdpPercentMinimum: 85,customTargetMdpPercentMaximum: 115," + "useDefaultTargetRangeSpeed: false,customTargetSpeedMinimum: 10,customTargetSpeedMaximum: 30,useDefaultCutFillTolerances: false,customCutFillTolerances: [3, 2, 1, 0, -1, -2, -3]," + "useDefaultVolumeShrinkageBulking: false, customShrinkagePercent: 5, customBulkingPercent: 7.5}"; projectSettings1 = projectSettings1.Replace(" ", string.Empty); var projSettings1 = ProjectSettingsRequest.CreateProjectSettingsRequest(ts.ProjectUid.ToString(), projectSettings1, ProjectSettingsType.Targets); var configJson1 = JsonConvert.SerializeObject(projSettings1, new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Unspecified }); var putresponse1 = await ts.CallProjectWebApi("api/v4/projectsettings", HttpMethod.Put, configJson1, customerUid.ToString()); var putobjresp1 = JsonConvert.DeserializeObject <ProjectSettingsResult>(putresponse1); var tempSettings = JsonConvert.SerializeObject(putobjresp1.Settings).Replace("\"", string.Empty); //Assert.Equal(projectSettings1, putobjresp1.settings, "Actual project settings 1 do not match expected"); Assert.Equal(projectSettings1, tempSettings); Assert.Equal(ts.ProjectUid.ToString(), putobjresp1.ProjectUid); // create settings for a second user for same project var projectSettings2 = "{ useMachineTargetPassCount: false,customTargetPassCountMinimum: 6,customTargetPassCountMaximum: 6,useMachineTargetTemperature: false,customTargetTemperatureMinimum: 70," + "customTargetTemperatureMaximum: 140,useMachineTargetCmv: false,customTargetCmv: 71,useMachineTargetMdp: false,customTargetMdp: 81,useDefaultTargetRangeCmvPercent: false," + "customTargetCmvPercentMinimum: 80,customTargetCmvPercentMaximum: 100,useDefaultTargetRangeMdpPercent: false,customTargetMdpPercentMinimum: 80,customTargetMdpPercentMaximum: 100," + "useDefaultTargetRangeSpeed: false,customTargetSpeedMinimum: 12,customTargetSpeedMaximum: 27,useDefaultCutFillTolerances: false,customCutFillTolerances: [3, 2, 1, 0, -1, -2, -3]," + "useDefaultVolumeShrinkageBulking: false, customShrinkagePercent: 6, customBulkingPercent: 5.2}"; projectSettings2 = projectSettings2.Replace(" ", string.Empty); var projSettings2 = ProjectSettingsRequest.CreateProjectSettingsRequest(ts.ProjectUid.ToString(), projectSettings2, ProjectSettingsType.Targets); var configJson2 = JsonConvert.SerializeObject(projSettings2, new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Unspecified }); var putresponse2 = await ts.CallProjectWebApi("api/v4/projectsettings", HttpMethod.Put, configJson2, customerUid.ToString(), RestClient.ANOTHER_JWT); var putobjresp2 = JsonConvert.DeserializeObject <ProjectSettingsResult>(putresponse2); tempSettings = JsonConvert.SerializeObject(putobjresp2.Settings).Replace("\"", string.Empty); //Assert.Equal(projectSettings2, putobjresp2.setting); Assert.Equal(projectSettings2, tempSettings); Assert.Equal(ts.ProjectUid.ToString(), putobjresp2.ProjectUid); // get call var getresponse1 = await ts.CallProjectWebApi($"api/v4/projectsettings/{ts.ProjectUid}", HttpMethod.Get, null, customerUid.ToString()); var getobjresp1 = JsonConvert.DeserializeObject <ProjectSettingsResult>(getresponse1); tempSettings = JsonConvert.SerializeObject(getobjresp1.Settings).Replace("\"", string.Empty); //Assert.Equal(projectSettings1, getobjresp1.settings); Assert.Equal(projectSettings1, tempSettings); Assert.Equal(ts.ProjectUid.ToString(), getobjresp1.ProjectUid); }
/// <summary> /// Creates an instance of the ProjectSettingsRequest class and populate it. /// </summary> /// <param name="projectUid"></param> /// <param name="settings"></param> /// <param name="projectSettingsType"></param> /// <returns>An instance of the ProjectSettingsRequest class.</returns> public ProjectSettingsRequest CreateProjectSettingsRequest(string projectUid, string settings, ProjectSettingsType projectSettingsType) { return(ProjectSettingsRequest.CreateProjectSettingsRequest(projectUid, settings, projectSettingsType)); }