Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The requirement is to call /GetAvailableBooks to get a list of books, and then for each available book, call /CheckoutBook

The strategy is to call /GetAvailableBooks, then create a Do...While loop around /CheckoutBook as shown below

...

The first step is to extract the list of all the books from the /GetAvailableBooks response into a list and store the list in the VU storage under the key ListOfBooks. We will create a component for that:

...

The next step is to create a scriptable variable, ReturnFirstBook, that will be used to parameterize /CheckoutBook request. We will create a scriptable variable that will read the VU storage for the list of available books, remove the first one, and return it.

...

Finally, we will add a scriptable variable that will return the number of available books remaining that have not yet been checked out.

Code Block
languagec#
firstline1
titleAny books left?
linenumberstrue
using System;
using StresStimulus.Extensibility;
using System.Data;
using System.Collections.Generic;
using System.Linq;

class NumberOfBooksLeft : IExternalVariable
{
    public NumberOfBooksLeft()
    {
        //Do not edit this section.
    }

    /// <summary>
    /// Return true if the variable will be evaluated once per VU iteration. Otherwise will be evaluated on every parameter.
    /// </summary>
    bool IExternalVariable.EvaluateOnIteration
    {
        get 
        {
            return false;
        }
    }

    /// <summary>
    /// Return a value for the given session context.
    /// </summary>
    /// <param name="session">The session context object of the request consuming the variable.</param>
    /// <returns>The source variable value.</returns>
    string IExternalVariable.GetValue(SessionContext context)
    {
        var listOfBooks = context.GetObject("ListOfBooks") as List<string>;
		
		return listOfBooks.Count.ToString();
    }
}

...