public ActionResult <Boolean> Get([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) { // 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); // Manage any aliases for the results table ManagedApiHelper.HandleAliases(results, authResult.ApiDefinition.Aliases); // Format the data table as Json return(ManagedApiHelper.ToJson(results)); } else { return(StatusCode((Int32)HttpStatusCode.InternalServerError, "Could not connect to the data source")); } } else { return(StatusCode((Int32)authResult.StatusCode, authResult.StatusDescription)); } }
public void Json_From_DataTable() { // Arrange fixture.Initialise(); // Act JsonResult jsonResult = ManagedApiHelper.ToJson(fixture.Data); var result = JsonConvert.SerializeObject(jsonResult.Value, jsonResult.SerializerSettings); // Assert Assert.DoesNotContain("\"RowError\":", result); // Standard DataTable Tags Should Be Stripped Out Assert.DoesNotContain("\"RowState\":", result); // Standard DataTable Tags Should Be Stripped Out Assert.DoesNotContain("\"Table\":", result); // Standard DataTable Tags Should Be Stripped Out Assert.DoesNotContain("\"HasErrors\":", result); // Standard DataTable Tags Should Be Stripped Out Assert.Contains($"\"StringData\": \"{fixture.StringToTest}\"", result); // Element Exists Assert.Contains($"\"BooleanData\": true", result); // Element Exists Assert.Contains($"\"DateData\": \"{fixture.DateToTest.ToString("yyyy")}", result); // Element Exists (We only care about the first part of the date here) Assert.Contains($"\"NumericData\": {fixture.NumberToTest.ToString()}", result); // Element Exists }