public void DataTable_From_MultipleRecords_Json() { // Arrange String json = GetResourceString(TestFile_MultipleRecords); // Act DataTable dataTable = ManagedApiHelper.ToDataTable( "application/json", json, fixture.ApiDefinition, fixture.Definition); // Assert Assert.Equal(fixture.ExpectedRowCount, dataTable.Rows.Count); }
public ActionResult <Boolean> Post([FromRoute] Guid packageId, [FromRoute] String objectType) { // Do the authentication process with the given request and helpers // to determine the result ApiAuthenticationResult authResult = WebAuthHelper.AuthenticateApiRequest( packageId, objectType, SessionHandler.PackageRepository, Request ); // Everything work ok? Then continue to the important bits if (authResult.StatusCode != HttpStatusCode.OK) { return(StatusCode((Int32)authResult.StatusCode, authResult.StatusDescription)); } // Get the body of the request from the stream String body = HttpRequestHelper.GetBody(Request); if (body == String.Empty) { return(StatusCode((Int32)HttpStatusCode.BadRequest, "Request body contained no data")); } // Translate the body try { DataTable data = null; // Parse the body to a queryable Json Object (bad formatting will fail it) data = ManagedApiHelper.ToDataTable( Request.ContentType.Trim().ToLower(), body, authResult.ApiDefinition, authResult.DataDefinition); // Did we get some data from the conversion (depending on the type format) if (data != null) { // Use the api definition to get the data connection and // definition from the package and then try to connect IDataProvider provider = providerFactory.Get( authResult.Package, authResult.Package.DataConnection(authResult.ApiDefinition.DataConnection), authResult.Package.DataDefinition(authResult.ApiDefinition.DataDefinition), true); // Are we connected? if (provider.Connected) { // Return the data with the appropriate filter // DataTable results = provider.Read(authResult.Permissions.Filter); if (provider.Write(data, "")) { } else { return(StatusCode((Int32)HttpStatusCode.InternalServerError, "Could not write the data")); } } else { return(StatusCode((Int32)HttpStatusCode.InternalServerError, "Could not connect to the data source")); } } else { return(StatusCode((Int32)HttpStatusCode.BadRequest, "Request body contained no valid data or the format was incorrect")); } } catch (Exception ex) { return(StatusCode((Int32)HttpStatusCode.BadRequest, $"Malformed body content in request ({ex.Message})")); } // Got to the end so must be ok return(StatusCode((Int32)HttpStatusCode.OK, "")); }