Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
740
xamChart.HitTest(e) NullReferenceException
posted

Hi,

I'm writing tests for the usual reason.  I have a XamChart where I've added a drag feature for the user.  The user can select a data point and move it up and down.  The backing custom class is updated which cascades the update to a XamDataGrid.  Everything works fine, but I'm running into problems during testing.  Specifically, this line throws an exception:

 var hitArgs = xamChart.HitTest(e);

Here is the exception:

System.NullReferenceException was unhandled by user code
  Message=Object reference not set to an instance of an object.
  Source=InfragisticsWPF3.Chart.v10.2
  StackTrace:
       at Infragistics.Windows.Chart.XamChart.HitTest(MouseEventArgs e)
       at Intel.Wolf.UI.WPFMVApp.Helpers.XamChartHelper.MouseLeftButtonDownHandler(Object sender, MouseButtonEventArgs e) in C:\<...>\Helpers\XamChartHelper.cs:line 95
  InnerException:

If I run the code in the Immediate Window I get this:

 

? xamChart == null

false

? e == null

false

xamChart.HitTest(e)

'xamChart.HitTest(e)' threw an exception of type 'System.NullReferenceException'

base {System.SystemException}: {"Object reference not set to an instance of an object."}

 

What 'Object'?  Neither xamChart or e are null. 

 

 

Complete method:

private static void MouseLeftButtonDownHandler(object sender, MouseButtonEventArgs e)
    {

      var xamChart = sender as XamChart;
      if (xamChart == null || e == null)
        return;

      var hitArgs = xamChart.HitTest(e);
      selectedDataPoint = hitArgs.SelectedObject as DataPoint;
      if (selectedDataPoint != null)
      {
        xamChart.Cursor = Cursors.SizeNS;
        started = true;
      }
      e.Handled = true;

    }

Here is my test:

    [TestMethod]
    public void MouseLeftButtonDownHandlerTest()
    {
      var chart = new XamChart();
      chart.Width = 300; // ??? Create a size to be selected ???

      chart.Height = 300;

      XamChartHelper.SetChartDragging(chart, true);

      var e = new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left);
      e.RoutedEvent = XamChart.MouseLeftButtonDownEvent;
      //chart.RaiseEvent(e);

      XamChartHelper_Accessor.MouseLeftButtonDownHandler(chart, e);

      // ToDo: Need more logic testing beyond "handled"
      Assert.IsTrue(e.Handled);
      
    }

 

VS 2010 Ultimate, Win7 x64, InfragisticsWPF3.Chart.v10.2

Can anyone point me in a direction?