none
Test Data Generator API from server side in .Net Core RRS feed

  • Question

  • Is there a way to consume the Test Data Generator api from server side in a .Net Core console app? I know in the docs it is limited to the V8 Web Controls (javascript) but I need it with C#. Specifically want the "Create locations within bounds" service.

    Thanks

    Wednesday, May 10, 2017 8:52 PM

Answers

  • No, you can't consume the Test Data Generator from a C# application, at least not without a lot of work. However, if you want to generate random locations within a bounding box, this is fairly easy to do. 

    /// <summary>
    /// Generates a random location inside a bounding box.
    /// </summary>
    /// <param name="north">North latitude value of bounding box</param>
    /// <param name="south">South latitude value of bounding box</param>
    /// <param name="east">East longitude value of bounding box</param>
    /// <param name="west">West longitude value of bounding box</param>
    /// <param name="latitude">Generated random latitude coordinate in bounding box.</param>
    /// <param name="longitude">Generated random longitude coordinate in bounding box.</param>
    private void GetRandomLocation(double north, double south, double east, double west, out double latitude, out double longitude)
    {
        var rand = new Random();
    
        var height = north - south;
        var width = east - west;
    
        latitude = rand.NextDouble() * height + south;
        longitude = rand.NextDouble() * width + west;
    }


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Monday, May 15, 2017 4:42 PM
    • Marked as answer by Velair Monday, May 15, 2017 7:21 PM
    Monday, May 15, 2017 4:41 PM

All replies

  • No, you can't consume the Test Data Generator from a C# application, at least not without a lot of work. However, if you want to generate random locations within a bounding box, this is fairly easy to do. 

    /// <summary>
    /// Generates a random location inside a bounding box.
    /// </summary>
    /// <param name="north">North latitude value of bounding box</param>
    /// <param name="south">South latitude value of bounding box</param>
    /// <param name="east">East longitude value of bounding box</param>
    /// <param name="west">West longitude value of bounding box</param>
    /// <param name="latitude">Generated random latitude coordinate in bounding box.</param>
    /// <param name="longitude">Generated random longitude coordinate in bounding box.</param>
    private void GetRandomLocation(double north, double south, double east, double west, out double latitude, out double longitude)
    {
        var rand = new Random();
    
        var height = north - south;
        var width = east - west;
    
        latitude = rand.NextDouble() * height + south;
        longitude = rand.NextDouble() * width + west;
    }


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Monday, May 15, 2017 4:42 PM
    • Marked as answer by Velair Monday, May 15, 2017 7:21 PM
    Monday, May 15, 2017 4:41 PM
  • Hi Ricky,

    Thanks a lot for the answer, but the general idea is to wrap the V8 API inside a .Net Core web app as to be consumed like a service without UI or user interaction, just like the Bing REST API. You said its a lot of work, but could you point me in the right direction? I have thought about two options:

     - Installing NodeServices package to run the scripts with Node server-side. The problem is that it seems the Api relies a lot on DOM and rendered objects.

     - With every request, render a view, call the V8 Api, post the response to my app, and somehow return the result to the original request.

    Any ideas? Thanks

    Monday, May 15, 2017 7:18 PM