Pre loader

ChartModifier + GetCurrentCoordinateCalculator + UnitTests

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

0
0

I’m using in my geometryCursormodifier the function
var xCalc=this.XAxis.GetCurrentCoordinateCalculator();

This works under normal circumstances(Application Mode).

Now I was trying to test this features with Unit Test and xCalc is always null(this.XAxis isn’t null)?

  • You must to post comments
0
0

Hi Daniel,

The GetCurrentCoordinateCalculator() method returns a calculator only after the first render pass has occurred. It is possible to unit test it, but requires some setup. Here is an example test we have that tests Axis GetCurrentCoordinateCalculator.

    [Test]
    public void ShouldGetCoordinateAsXAxisAndReturnPixel()
    {
        var calculatorFactoryStub = MockRepository.GenerateStub<ICoordinateCalculatorFactory>();
        calculatorFactoryStub.Stub(x => x.New(Arg<AxisParams>.Is.Anything))
            .Do((Func<AxisParams, ICoordinateCalculator<double>>)(x =>
            {
                x.Offset = 0;
                return new CoordinateCalculatorFactory().New(x);
            }));

        // Mocks IServiceContainer, passed to AxisBase, required for OnBeginRenderPass to run
        _serviceContainer = new MockServiceContainerBuilder()
               .WithCoordinateCalculatorFactory(calculatorFactoryStub)
               .WithEventAggregator(MockRepository.GenerateStub<IEventAggregator>()).
               Build();

        var renderSurface = new MockRenderSurfaceBuilder().WithSize(new Size(400, 300)).Build();
        _axis.VisibleRange = new DoubleRange(0, 10);

        // Mocks ISciChartSurface
        _axis.ParentSurface = new MockSciChartSurfaceBuilder().WithRenderSurface(renderSurface).WithServiceContainer(_serviceContainer).Build();
        _axis.Orientation = Orientation.Horizontal;
        _axis.TextFormatting = "0.00";

        _axis.Width = 400;
        _axis.Height = 300;
        _axis.MeasureArrange();

        _axis.OnBeginRenderPass();

        var cc = _axis.GetCurrentCoordinateCalculator();
        Assert.That(cc, Is.Not.Null);

        double coord = _axis.GetCoordinate(5.0125313283208017d);
        Assert.That(coord, Is.EqualTo(200));
    }

Here is the definition of AxisBase.OnBeginRenderPass()

    /// <summary>
    /// Called internally immediately before a render pass begins
    /// </summary>
    public virtual void OnBeginRenderPass()
    {
        if (Services == null)
            return;

        _currentCoordinateCalculator = Services.GetService<ICoordinateCalculatorFactory>().New(GetAxisParams());

        _currentInteractivityHelper = new AxisInteractivityHelper(_currentCoordinateCalculator);
    }

As you can see it requires Services to be not null, and for ICoordinateCalculatorFactor to be registered. Then it can create a new coordinate calculator.

Let me know if you are able to make progress with this. It might be difficult without the source-code (since you need to look inside our code to see why test setup is / is not working).

Best regards,
Andrew

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies