Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

LoadTestUserContext Class

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

System.Object
  System.MarshalByRefObject
    Microsoft.VisualStudio.TestTools.LoadTesting.LoadTestUserContext

Namespace:  Microsoft.VisualStudio.TestTools.LoadTesting
Assembly:  Microsoft.VisualStudio.QualityTools.LoadTestFramework (in Microsoft.VisualStudio.QualityTools.LoadTestFramework.dll)
[SerializableAttribute]
public class LoadTestUserContext : MarshalByRefObject, 
	IDictionary<string, Object>, ICollection<KeyValuePair<string, Object>>, 
	IEnumerable<KeyValuePair<string, Object>>, IEnumerable

The LoadTestUserContext type exposes the following members.

  NameDescription
Public propertyCompletedTestCountGets 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 propertyCountGets the number of elements that are contained in the LoadTestUserContext object.
Public propertyInitializeTestContextGets 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 propertyIsNewUserGets a value that indicates whether a newly created virtual user is running the current test.
Public propertyIsReadOnlyGets a value that indicates whether LoadTestUserContext is read-only.
Public propertyItemGets or sets a LoadTestUserContext element that has the specified key.
Public propertyKeysGets an ICollection that contains the keys of the LoadTestUserContext elements.
Public propertyScenarioNameGets or sets the name of the load test scenario that created the virtual user that is represented by this LoadTestUserContext.
Public propertyUserIdGets the UserId of the user in the load test scenario.
Public propertyValuesGets an ICollection that contains the values in the LoadTestUserContext elements.
Top
  NameDescription
Public methodAdd(KeyValuePair<String, Object>)Adds a KeyValuePair<TKey, TValue> item to the LoadTestUserContext.
Public methodAdd(String, Object)Adds an element that has the provided key and value to the LoadTestUserContext.
Public methodClearRemoves all items from the LoadTestUserContext.
Public methodContainsDetermines whether the LoadTestUserContext contains a specific value.
Public methodContainsKeyIndicates whether the LoadTestUserContext contains an element that has the specified key.
Public methodCopyToCopies the elements of the LoadTestUserContext to an Array, starting at a particular Array index.
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodEqualsDetermines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetEnumeratorReturns an enumerator that iterates through the LoadTestUserContext.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public methodRemove(KeyValuePair<String, Object>)Removes the first occurrence of a specific object from the LoadTestUserContext.
Public methodRemove(String)Returns a value that indicates whether the first occurrence of a specific object must be moved from the LoadTestUserContext object.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodTryGetValueGets the value that is associated with the specified key.
Top
  NameDescription
Public fieldStatic memberLoadTestUserContextKeyRepresents a key in LoadTestUserContext.
Top
  NameDescription
Explicit interface implemetationPrivate methodIEnumerable.GetEnumeratorReturns an enumerator that iterates through a collection of LoadTestUserContext elements.
Top

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

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 null.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.