Implementing Test Record Logic

In this section, you implement the logic that records a SetValue(X) command when a ValueChanged event occurs, using an event handler function.

To implement the Test Record logic:

  1. In the TrackBarSrv class, locate an appropriate place to add a new method, OnValueChanged. For example, you might want to add it after other event handler methods, such as OnMessage, in the IRecord override Methods region.

  2. Add the new method with the following signature to the TrackBarSrv class:

    public void OnValueChanged(object sender, EventArgs e) { }
    

    Note: You can add the new method manually or use the wizard that Visual Studio provides for adding methods and functions to a class.

  3. Add the following implementation to the function you just added:

    public void OnValueChanged(object sender, EventArgs e)
    {
     System.Windows.Forms.TrackBar trackBar = (System.Windows.Forms.TrackBar)sender;
     // get the new value
     int newValue = trackBar.Value;
     // Record SetValue command to the test
     RecordFunction("SetValue", RecordingMode.RECORD_SEND_LINE, newValue);
    }
    
  4. Register the OnValueChanged event handler for the ValueChanged event, by adding the following code to the InitEventListener method:

    public override void InitEventListener()
    {
      Delegate e = new System.EventHandler(this.OnValueChanged);
      AddHandler("ValueChanged", e);
    }
    

To continue implementing the Custom Server, proceed to the next step: Implementing Test Run Logic.