Share via


LoadTestUserContext Class

Encapsulates information about the user context in which a test is running, in a load test.

Inheritance Hierarchy

Object
  MarshalByRefObject
    Microsoft.VisualStudio.TestTools.LoadTesting.LoadTestUserContext

Namespace:  Microsoft.VisualStudio.TestTools.LoadTesting
Assembly:  Microsoft.VisualStudio.QualityTools.LoadTestFramework (in Microsoft.VisualStudio.QualityTools.LoadTestFramework.dll)

Syntax

'Declaration
<SerializableAttribute> _
Public Class LoadTestUserContext _
    Inherits MarshalByRefObject _
    Implements IDictionary(Of String, Object),  _
    ICollection(Of KeyValuePair(Of String, Object)), IEnumerable(Of KeyValuePair(Of String, Object)),  _
    IEnumerable
[SerializableAttribute]
public class LoadTestUserContext : MarshalByRefObject, 
    IDictionary<string, Object>, ICollection<KeyValuePair<string, Object>>, 
    IEnumerable<KeyValuePair<string, Object>>, IEnumerable
[SerializableAttribute]
public ref class LoadTestUserContext : public MarshalByRefObject, 
    IDictionary<String^, Object^>, ICollection<KeyValuePair<String^, Object^>>, 
    IEnumerable<KeyValuePair<String^, Object^>>, IEnumerable
[<SerializableAttribute>]
type LoadTestUserContext =  
    class 
        inherit MarshalByRefObject 
        interface IDictionary<string, Object>
        interface ICollection<KeyValuePair<string, Object>>
        interface IEnumerable<KeyValuePair<string, Object>>
        interface IEnumerable 
    end
public class LoadTestUserContext extends MarshalByRefObject implements IDictionary<String, Object>, ICollection<KeyValuePair<String, Object>>, IEnumerable<KeyValuePair<String, Object>>, IEnumerable

The LoadTestUserContext type exposes the following members.

Properties

  Name Description
Public property CompletedTestCount Gets or sets the number of tests that have been completed by the virtual user that is represented by the LoadTestUserContext object since the start of the load test.
Public property Count Gets the number of elements that are contained in the LoadTestUserContext object.
Public property InitializeTestContext Gets or sets the state of the user context at the time InitializeTest was completed for the virtual user that is associated with the LoadTestUserContext object.
Public property IsNewUser Gets a value that indicates whether a newly created virtual user is running the current test.
Public property IsReadOnly Gets a value that indicates whether LoadTestUserContext is read-only.
Public property Item Gets or sets a LoadTestUserContext element that has the specified key.
Public property Keys Gets an ICollection that contains the keys of the LoadTestUserContext elements.
Public property ScenarioName Gets or sets the name of the load test scenario that created the virtual user that is represented by this LoadTestUserContext.
Public property UserId Gets the UserId of the user in the load test scenario.
Public property Values Gets an ICollection that contains the values in the LoadTestUserContext elements.

Top

Methods

  Name Description
Public method Add(KeyValuePair<String, Object>) Adds a KeyValuePair item to the LoadTestUserContext.
Public method Add(String, Object) Adds an element that has the provided key and value to the LoadTestUserContext.
Public method Clear Removes all items from the LoadTestUserContext.
Public method Contains Determines whether the LoadTestUserContext contains a specific value.
Public method ContainsKey Indicates whether the LoadTestUserContext contains an element that has the specified key.
Public method CopyTo Copies the elements of the LoadTestUserContext to an Array, starting at a particular Array index.
Public method CreateObjRef Security Critical. Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public method Equals Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetEnumerator Returns an enumerator that iterates through the LoadTestUserContext.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetLifetimeService Security Critical. Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method InitializeLifetimeService Security Critical. Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method MemberwiseClone(Boolean) Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public method Remove(KeyValuePair<String, Object>) Removes the first occurrence of a specific object from the LoadTestUserContext.
Public method Remove(String) Returns a value that indicates whether the first occurrence of a specific object must be moved from the LoadTestUserContext object.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Public method TryGetValue Gets the value that is associated with the specified key.

Top

Fields

  Name Description
Public fieldStatic member LoadTestUserContextKey Represents a key in LoadTestUserContext.

Top

Explicit Interface Implementations

  Name Description
Explicit interface implemetationPrivate method IEnumerable.GetEnumerator Returns an enumerator that iterates through a collection of LoadTestUserContext elements.

Top

Remarks

LoadTestUserContext encapsulates information about the user context in which a test is running in a load test.

Examples

The code for a unit test that runs in the context of a load test can obtain a reference to the LoadTestUserContext for the virtual user that runs the unit test by using the key "$LoadTestUserContext" when the user accesses the TestContext properties.

For example:

    LoadTestUserContext loadTestUserContext = 
        this.TestContext.Properties["$LoadTestUserContext"] 
        as LoadTestUserContext;

Similarly, a coded Web test can access the LoadTestUserContext as follows:

    LoadTestUserContext loadTestUserContext = 
        this.Context["$LoadTestUserContext"] as LoadTestUserContext;

When the unit test or Web test runs outside the context of a load test, the LoadTestUserContext that is returned by the preceding code is nulla null reference (Nothing in Visual Basic).

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Microsoft.VisualStudio.TestTools.LoadTesting Namespace