public async Task WhenHasPreviousCompleteCategoryRedirectsToRoles() { var category = "testcategory"; var assessmentResponse = new GetAssessmentResponse() { IsFilterAssessment = true, MaxQuestionsCount = 2, RecordedAnswersCount = 2, }; A.CallTo(() => sessionService.HasValidSession()).Returns(true); A.CallTo(() => assessmentService.GetAssessment()).Returns(assessmentResponse); var resultsResponse = new GetResultsResponse() { JobCategories = GetJobCategories(category) }; A.CallTo(() => resultsService.GetResults()).Returns(resultsResponse); var actionResponse = await controller.Index().ConfigureAwait(false); Assert.IsType <RedirectResult>(actionResponse); var redirectResult = actionResponse as RedirectResult; Assert.Equal($"~/{RouteName.Prefix}/results/roles/{category}", redirectResult.Url); }
public async Task GetResultsTest() { OpenvasApi api = new OpenvasApi(Address); GetResultsResponse results = await api.GetResults(new GetResultsRequest { TaskId = "f0a098e5-f8a4-43de-8176-bb823f7c0c06" }); Assert.IsNotNull(results.Results); string j = JsonConvert.SerializeObject(results); }
public override Task <GetResultsResponse> GetResults(Empty request, ServerCallContext context) { var results = raceLogic.GetResults(); var result = new GetResultsResponse(); result.Results.AddRange(results.Select(Utils.ToProto)); return(Task.FromResult(result)); }
private GetResultsResponse AddInCategoryJobProfileCount(GetResultsResponse resultsResponse) { foreach (var c in resultsResponse.JobCategories) { c.NumberOfMatchedJobProfile = resultsResponse.JobProfiles.Count(p => p.JobCategory == c.JobFamilyUrl); } return(resultsResponse); }
protected override async Task <object> Run_Internal(IObserver observer, string asset, IScanRepository repository, object args) { if (String.IsNullOrEmpty(asset) || args == null) { return(null); } string address = args?.ToString(); OpenvasApi api = new OpenvasApi(address); string taskId = asset; var r = await api.StartTask(taskId); if (r?.Status == "202") { while (true) { await Task.Delay(1000); GetTasksResponse tasks = await api.GetTasks(new GetTasksRequest { TaskId = taskId }); var first = tasks.Tasks.FirstOrDefault(); if (null != first) { if (first.Status == "Running" || first.Status == "Requested") { if (first.Progress is JObject jo) { observer.Notify("Openvas_" + taskId, "Progress: " + jo["_"], null); } else if (first.Progress is string progress) { observer.Notify("Openvas_" + taskId, "Progress: " + progress, null); } continue; } else { observer.Notify("Openvas_" + taskId, "Done at : " + DateTime.Now, null); } } else { observer.Notify("Openvas_" + taskId, "couldn't get the task info, operation cancelled", null); } break; } } GetResultsResponse results = await api.GetResults(new GetResultsRequest { TaskId = taskId }); return(results?.Results); }
public override async Task <GetResultsResponse> getResults(GetStartRequest request, ServerCallContext context) { var start = await dbContext.Starts.Include(s => s.Race).FirstOrDefaultAsync(s => s.Id == request.StartId); if (start == null) { throw new Exception($"No start with Id: {request.StartId}"); } var res = new GetResultsResponse { Start = ToProtoStart(start) }; var result = await dbContext.Results.Where(r => r.StartId == request.StartId).ToArrayAsync(); res.Results.AddRange(result.Select(Utils.ToProto)); return(res); }
public async Task GetResultsByCategory(bool hasMatchedProfile, int expectedNumberOfcalls) { //Arrange var category = "ACategory"; var resultsResponse = new GetResultsResponse() { SessionId = sessionId }; if (hasMatchedProfile) { List <JobProfileResult> profiles = new List <JobProfileResult> { new JobProfileResult() { UrlName = "Cname1", JobCategory = category } }; resultsResponse.JobProfiles = profiles; List <JobCategoryResult> categories = new List <JobCategoryResult> { new JobCategoryResult() { JobFamilyName = category, JobFamilyUrl = category } }; resultsResponse.JobCategories = categories; } A.CallTo(() => resultsApiService.GetResults(sessionId, A <string> .Ignored)).Returns(resultsResponse); A.CallTo(() => jPOverviewAPIService.GetOverviewsForProfilesAsync(A <IEnumerable <string> > .Ignored)).Returns(A.CollectionOfDummy <JobProfileOverView>(2)); //Act var results = await resultsService.GetResultsByCategory(category); //Assert A.CallTo(() => resultsApiService.GetResults(sessionId, category)).MustHaveHappenedOnceExactly(); A.CallTo(() => jPOverviewAPIService.GetOverviewsForProfilesAsync(A <IEnumerable <string> > .Ignored)).MustHaveHappened(expectedNumberOfcalls, Times.Exactly); results.SessionId.Should().Be(sessionId); }
public GetResultsResponse GetResults(string runnerName, string from, string to, string interval) { RunResultsForRunner results = null; DateTime fromDate = DateTime.MinValue; DateTime toDate = DateTime.MinValue; ExtractParameters(from, to, interval, out fromDate, out toDate); results = _db.GetRunResults(runnerName, fromDate, toDate); var @return = new GetResultsResponse() { Title = results.Title, YAxisLegend = results.YAxisLegend, Entries = results.Entries.Select(x => new dynamic[] { x.RanAt.ToString("hh:mm:ss"), Math.Round(x.TimeTaken, 2) } ).ToArray() }; return @return; }
public async Task GetResults() { //Arrange var category = "ACategory"; var resultsResponse = new GetResultsResponse() { SessionId = sessionId }; List <JobProfileResult> profiles = new List <JobProfileResult> { new JobProfileResult() { UrlName = category, JobCategory = category } }; resultsResponse.JobProfiles = profiles; List <JobCategoryResult> categories = new List <JobCategoryResult> { new JobCategoryResult() { JobFamilyName = category, JobFamilyUrl = category } }; resultsResponse.JobCategories = categories; A.CallTo(() => resultsApiService.GetResults(sessionId, A <string> .Ignored)).Returns(resultsResponse); //Act var results = await resultsService.GetResults(); //Assert A.CallTo(() => resultsApiService.GetResults(sessionId, A <string> .Ignored)).MustHaveHappenedOnceExactly(); results.SessionId.Should().Be(sessionId); results.JobCategories.FirstOrDefault().NumberOfMatchedJobProfile.Should().Be(1); }