public async Task GetAsync(int id, string title)
        {
            var info = await IProblemInfo.GetAsync(id);

            Assert.Equal(id, info.Id);
            Assert.Equal(title, info.Title);
        }
Exemplo n.º 2
0
        public IActionResult GetSutInfo()
        {
            string connectionHeader = Request.Headers["Connection"];

            if (connectionHeader == null ||
                !connectionHeader.Equals("keep-alive", StringComparison.OrdinalIgnoreCase))
            {
                return(BadRequest(
                           WrappedResponseDto <string> .WithError("Requests should always contain a 'Connection: keep-alive'")));
            }

            AssertTrackRequestSource(Request.HttpContext.Connection);

            //TODO: uncomment after implementing VerifySqlConnection method
            // if (!_sutController.VerifySqlConnection ()) {
            //   string msg = "SQL drivers are misconfigured. You must use a 'p6spy' wrapper when you " +
            //     "run the SUT. For example, a database connection URL like 'jdbc:h2:mem:testdb' " +
            //     "should be changed into 'jdbc:p6spy:h2:mem:testdb'. " +
            //     "See documentation on how to configure P6Spy.";

            //   SimpleLogger.Error (msg);

            //   return StatusCode(StatusCodes.Status500InternalServerError, WrappedResponseDto<string>.WithError(msg));
            // }

            SutInfoDto dto = new SutInfoDto();

            dto.IsSutRunning          = _sutController.IsSutRunning();
            dto.BaseUrlOfSUT          = _baseUrlOfSut;
            dto.InfoForAuthentication = _sutController.GetInfoForAuthentication();
            //TODO: uncomment
            //dto.SqlSchemaDto = _sutController.GetSqlDatabaseSchema ();
            dto.DefaultOutputFormat = _sutController.GetPreferredOutputFormat();

            IProblemInfo info = _sutController.GetProblemInfo();

            if (info == null)
            {
                string msg = "Undefined problem type in the EM Controller";

                SimpleLogger.Error(msg);

                return(StatusCode(StatusCodes.Status500InternalServerError, WrappedResponseDto <string> .WithError(msg)));
            }
            else if (info is RestProblem)
            {
                RestProblem rp = (RestProblem)info;
                dto.RestProblem                 = new RestProblemDto();
                dto.RestProblem.OpenApiUrl      = rp.GetSwaggerJsonUrl();
                dto.RestProblem.EndpointsToSkip = rp.GetEndpointsToSkip();
            }
            else
            {
                string msg = "Unrecognized problem type: " + info.GetType().FullName;

                SimpleLogger.Error(msg);

                return(StatusCode(StatusCodes.Status500InternalServerError, WrappedResponseDto <string> .WithError(msg)));
            }

            dto.UnitsInfoDto = _sutController.GetUnitsInfoDto();
            if (dto.UnitsInfoDto == null)
            {
                string msg = "Failed to extract units info";

                SimpleLogger.Error(msg);

                return(StatusCode(StatusCodes.Status500InternalServerError, WrappedResponseDto <string> .WithError(msg)));
            }

            return(Ok(WrappedResponseDto <SutInfoDto> .WithData(dto)));
        }
 public async Task OnGetAsync()
 {
     Problems = await IProblemInfo.ListAsync();
 }
Exemplo n.º 4
0
 public async Task <IProblemInfo> GetProblemInfoAsync()
 {
     return(await IProblemInfo.GetAsync(ProblemId));
 }