This class helps unit testing of modules that depend on VcClient.VC stream related functions. Instead of streams on remote server it creates files in local directory and overrides default API to emulate Cosmos workflow. This class is not thread-safe.

Examples

General usage:
CopyC#
// Initialize stream manager (using is required to destroy cosmos local directory after test)
// You can also consider to create this object once for test class.
// 
using (VirtualStreamManager streamManager = new VirtualStreamManager())
{
    VC.Override.Attach(streamManager);

    try
    {
        // Run tested method here, like
        // 
        MyClass.CreateReportSteams();

        // Manipulate streams
        // 
        streamManager.Delete("/my/stream");

        // Run other tested method
        // 
        MyClass.VerifyReportStreamsExist();

        ...
    }
    finally
    {
        VC.Override.Clear();
    }

    Assert.AreEqual(0, streamManager.OpenedStreams.Count);
}

The VirtualStreamManager..::..ReadOnlyStream type exposes the following members.

Constructors

  NameDescription
Public methodVirtualStreamManager..::..ReadOnlyStream
Creates a read only file stream.

Methods

  NameDescription
Public methodBeginRead
Begins an asynchronous read.
(Overrides FileStreamBeginRead(array<Byte>[]()[][], Int32, Int32, AsyncCallback, Object).)
Public methodRead
Reads a block of bytes from the stream and writes the data in a given buffer.
(Overrides FileStreamRead(array<Byte>[]()[][], Int32, Int32).)
Public methodReadByte
Reads a byte from the file and advances the read position one byte.
(Overrides FileStreamReadByte()()()().)
Public methodSeek
Sets the current position of this stream to the given value.
(Overrides FileStreamSeek(Int64, SeekOrigin).)

Properties

  NameDescription
Public propertyLength
Length of stream. Same as passed on constructor.
(Overrides FileStreamLength()()()().)
Public propertyPosition
Current position of cursor in stream.
(Overrides FileStreamPosition()()()().)

See Also