Exemplo n.º 1
0
 private void AddMappings(AbstractMapping mapping)
 {
     foreach (var mappingMetaData in mapping.MappingInfo.MappingMetaDataCollection)
     {
         _sqlBulkCopy.ColumnMappings.Add(mappingMetaData.SourceColumn, mappingMetaData.DestinationColumn);
     }
 }
Exemplo n.º 2
0
 public void MapColumns(AbstractMapping mapping, string[] propertyNames)
 {
     if (mapping != null)
     {
         AddMappings(mapping);
     }
     else
     {
         AddDefaultMappings(propertyNames);
     }
 }
Exemplo n.º 3
0
    public async Task TestNoParametersGETWorksCorrectly()
    {
        Server.RegisterEndpoints();
        Server.Start(TEST_PORT);
        await WaitForServerStart();

        MappingInfo <AbstractMapping> testMapping = AbstractMapping.FindPath("/test", SSMethod.GET, null);

        Assert.AreEqual(0, testMapping.RequiredParams.Count);
        Assert.AreEqual(null, testMapping.RequiredRequestBody);
        HttpClient client   = new HttpClient();
        var        response = await client.GetAsync($"http://localhost:{TEST_PORT}/test");

        Assert.AreEqual(200, (int)response.StatusCode);
        var stringResponse = await response.Content.ReadAsStringAsync();

        Assert.AreEqual($"\"{ControllerTest.TEST_GET_MESSAGE}\"", stringResponse);
        Assert.AreEqual(MediaTypes.ApplicationJson, response.Content.Headers.ContentType.ToString());
        var byteLength = new ResponseEntity(ControllerTest.TEST_GET_MESSAGE).GetDataAsBytes().Length;

        Assert.AreEqual(byteLength, response.Content.Headers.ContentLength);
        Server.Stop();
        await WaitForServerStop();
    }
Exemplo n.º 4
0
        public static void RunWith(HttpListenerContext context)
        {
            string path       = context.Request.Url.PathAndQuery;
            string httpMethod = context.Request.HttpMethod;

            try
            {
                HttpMethod method = (HttpMethod)Enum.Parse(typeof(HttpMethod), httpMethod, true);
                switch (method)
                {
                case HttpMethod.GET:
                    GetResponse(GetMapping.FindPath(path, method, context), context);
                    break;

                case HttpMethod.POST:
                    GetResponse(PostMapping.FindPath(path, method, context), context);
                    break;

                case HttpMethod.DELETE:
                    GetResponse(DeleteMapping.FindPath(path, method, context), context);
                    break;

                case HttpMethod.PUT:
                    GetResponse(PutMapping.FindPath(path, method, context), context);
                    break;

                case HttpMethod.PATCH:
                    GetResponse(PatchMapping.FindPath(path, method, context), context);
                    break;

                case HttpMethod.OPTIONS:
                    var requestedMethod  = Enum.Parse <HttpMethod>(context.Request.Headers.Get("Access-Control-Request-Method"));
                    var requestedHeaders = context.Request.Headers.Get("Access-Control-Request-Headers");
                    var response         = AbstractMapping.HandleOptionsRequest(path, requestedMethod, requestedHeaders);
                    SendResponse(response, context);
                    break;

                default:
                    throw new ServerRequestMethodNotSupportedException($"{httpMethod} is not supported", context);
                }
            }
            catch (ServerRequestMethodNotSupportedException ex)
            {
                ExceptionHandler.HandleException(ex, context);
            }
            catch (ServerEndpointNotValidException ex)
            {
                ExceptionHandler.HandleException(ex, context);
            }
            catch (Exception ex)
            {
                try
                {
                    throw new InternalServerErrorException(ex.Message, context, ex);
                }
                catch (InternalServerErrorException e)
                {
                    ExceptionHandler.HandleException(e, context);
                }
            }
        }