DataCollectorTests ClassDelta Engine Documentation
Inheritance Hierarchy

System Object
  DeltaEngine.Networking.Tests.Tcp DataCollectorTests

Namespace: DeltaEngine.Networking.Tests.Tcp
Assembly: DeltaEngine.Networking.Tests (in DeltaEngine.Networking.Tests.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public class DataCollectorTests

The DataCollectorTests type exposes the following members.

Constructors

  NameDescription
Public methodDataCollectorTests
Initializes a new instance of the DataCollectorTests class
Top
Methods

  NameDescription
Public methodCollectData
Public methodCollectDataWithIncompleteMessage
Public methodCollectTonsOfDataInOneChunk
Public methodCollectTonsOfDataInTwoChunks
Public methodDisposeObjectsList
Public methodStatic memberGetTestBytesWithLengthHeader
Public methodInitializeObjectsList
Top
Examples

[Test]
public void CollectData()
{
    var dataCollector = new DataCollector();
    dataCollector.ObjectFinished += container => collectedDataObjects.Add(container);
    Assert.IsEmpty(collectedDataObjects);
    var bytePackages = SplitDataStream(CreateByteList(), 7, 7, 8, 3, 1);
    foreach (byte[] package in bytePackages)
        dataCollector.ReadBytes(package, 0, package.Length);
    Assert.AreEqual(3, collectedDataObjects.Count);
}
[Test]
public void CollectTonsOfDataInOneChunk()
{
    var dataCollector = new DataCollector();
    dataCollector.ObjectFinished += container => collectedDataObjects.Add(container);
    Assert.IsEmpty(collectedDataObjects);
    var hugeByteArray = GetTestBytesWithLengthHeader(9348);
    dataCollector.ReadBytes(hugeByteArray, 0, hugeByteArray.Length);
    Assert.AreEqual(1, collectedDataObjects.Count);
}
[Test]
public void CollectTonsOfDataInTwoChunks()
{
    var dataCollector = new DataCollector();
    dataCollector.ObjectFinished += container => collectedDataObjects.Add(container);
    Assert.IsEmpty(collectedDataObjects);
    var hugeByteArray = GetTestBytesWithLengthHeader(9348);
    dataCollector.ReadBytes(hugeByteArray, 0, 3);
    dataCollector.ReadBytes(hugeByteArray, 3, hugeByteArray.Length - 3);
    Assert.AreEqual(1, collectedDataObjects.Count);
}
[Test]
public void CollectDataWithIncompleteMessage()
{
    var dataCollector = new DataCollector();
    dataCollector.ObjectFinished += container => collectedDataObjects.Add(container);
    var byteArray = GetTestBytesWithLengthHeader(1);
    dataCollector.ReadBytes(byteArray, 0, 0);
    dataCollector.ReadBytes(byteArray, 0, byteArray.Length - 1);
    dataCollector.ReadBytes(byteArray, byteArray.Length - 1, 1);
    Assert.AreEqual(1, collectedDataObjects.Count);
    Assert.AreEqual(1, collectedDataObjects[0].Data.Length);
    Assert.AreEqual(100, collectedDataObjects[0].Data[0]);
}
See Also