/// <summary> /// Verifies that the resulting stream buffer is in the expected state. /// </summary> /// <param name="assert">The assertion handler.</param> /// <param name="streamBuffer">The stream buffer whose state to verify.</param> /// <param name="testCaseDebugDescription">A textual description of the test case to make debugging easier.</param> public virtual void VerifyResult(AssertionHandler assert, BatchReaderStreamBufferWrapper streamBuffer, string testCaseDebugDescription) { Debug.Assert(assert != null, "assert != null"); Debug.Assert(streamBuffer != null, "streamBuffer != null"); if (this.ReadPositionInBuffer.HasValue) { assert.AreEqual( this.ReadPositionInBuffer.Value, streamBuffer.CurrentReadPosition, string.Format("\r\n{0}:\r\nCurrent read position in the buffer '{1}' does not match expected read position '{2}'", testCaseDebugDescription, streamBuffer.CurrentReadPosition, this.ReadPositionInBuffer.Value)); } if (this.NumberOfBytesInBuffer.HasValue) { assert.AreEqual( this.NumberOfBytesInBuffer.Value, streamBuffer.NumberOfBytesInBuffer, string.Format("\r\n{0}:\r\nNumber of bytes in the buffer '{1}' does not match expected number '{2}'", testCaseDebugDescription, streamBuffer.NumberOfBytesInBuffer, this.NumberOfBytesInBuffer.Value)); } if (this.ExpectedBytesInBuffer != null) { foreach (KeyValuePair<int, byte> kvp in this.ExpectedBytesInBuffer) { assert.AreEqual( kvp.Value, streamBuffer.Bytes[kvp.Key], string.Format("\r\n{0}:\r\nExpected value '{1}' at position '{2}' in the buffer but found '{3}'", testCaseDebugDescription, kvp.Value, kvp.Key, streamBuffer.Bytes[kvp.Key])); } } }
/// <summary> /// Runs the test case. /// </summary> public override void Run() { BatchReaderStreamBufferWrapper streamBuffer = new BatchReaderStreamBufferWrapper(); MemoryStreamBatchPayloadBuilder payloadBuilder = new MemoryStreamBatchPayloadBuilder(this.Encoding, this.LineFeedChars); // If no explicit payload func was specified, use a default payload MemoryStream memoryStream; if (this.PayloadFunc == null) { memoryStream = payloadBuilder.FillBytes(BatchReaderStreamBufferWrapper.BufferLength).ResetMemoryStream(); } else { memoryStream = this.PayloadFunc(payloadBuilder); } // Create a message reader and then a batch reader for the message using (ODataMessageReader messageReader = this.CreateMessageReader(memoryStream)) { ODataBatchReader batchReader = messageReader.CreateODataBatchReader(); BatchReaderStreamWrapper streamWrapper = new BatchReaderStreamWrapper(batchReader); Exception exception = TestExceptionUtils.RunCatching(() => { this.RunTestAction(streamWrapper); }); this.VerifyException(exception); } }
/// <summary> /// Verifies that the resulting stream buffer is in the expected state. /// </summary> /// <param name="assert">The assertion handler.</param> /// <param name="streamBuffer">The stream buffer whose state to verify.</param> /// <param name="testCaseDebugDescription">A textual description of the test case to make debugging easier.</param> public virtual void VerifyResult(AssertionHandler assert, BatchReaderStreamBufferWrapper streamBuffer, string testCaseDebugDescription) { Debug.Assert(assert != null, "assert != null"); Debug.Assert(streamBuffer != null, "streamBuffer != null"); if (this.ReadPositionInBuffer.HasValue) { assert.AreEqual( this.ReadPositionInBuffer.Value, streamBuffer.CurrentReadPosition, string.Format("\r\n{0}:\r\nCurrent read position in the buffer '{1}' does not match expected read position '{2}'", testCaseDebugDescription, streamBuffer.CurrentReadPosition, this.ReadPositionInBuffer.Value)); } if (this.NumberOfBytesInBuffer.HasValue) { assert.AreEqual( this.NumberOfBytesInBuffer.Value, streamBuffer.NumberOfBytesInBuffer, string.Format("\r\n{0}:\r\nNumber of bytes in the buffer '{1}' does not match expected number '{2}'", testCaseDebugDescription, streamBuffer.NumberOfBytesInBuffer, this.NumberOfBytesInBuffer.Value)); } if (this.ExpectedBytesInBuffer != null) { foreach (KeyValuePair <int, byte> kvp in this.ExpectedBytesInBuffer) { assert.AreEqual( kvp.Value, streamBuffer.Bytes[kvp.Key], string.Format("\r\n{0}:\r\nExpected value '{1}' at position '{2}' in the buffer but found '{3}'", testCaseDebugDescription, kvp.Value, kvp.Key, streamBuffer.Bytes[kvp.Key])); } } }
/// <summary> /// Verifies that the resulting stream buffer is in the expected state. /// </summary> /// <param name="assert">The assertion handler.</param> /// <param name="streamBuffer">The stream buffer whose state to verify.</param> public virtual void VerifyResult(BatchReaderStreamBufferWrapper streamBuffer) { if (this.ExpectedBufferState != null) { this.ExpectedBufferState.VerifyResult(this.Assert, streamBuffer, this.DebugDescription); } }
/// <summary> /// Runs the test case. /// </summary> public override void Run() { BatchReaderStreamBufferWrapper streamBuffer = new BatchReaderStreamBufferWrapper(); MemoryStreamBatchPayloadBuilder payloadBuilder = new MemoryStreamBatchPayloadBuilder(this.Encoding, this.LineFeedChars); // If no explicit payload func was specified, use a default payload MemoryStream memoryStream; if (this.PayloadFunc == null) { memoryStream = payloadBuilder.FillBytes(BatchReaderStreamBufferWrapper.BufferLength).ResetMemoryStream(); } else { memoryStream = this.PayloadFunc(payloadBuilder); } Exception exception = TestExceptionUtils.RunCatching(() => { this.RunTestAction(streamBuffer, memoryStream); }); this.VerifyException(exception); }
/// <summary> /// Constructor. /// </summary> /// <param name="batchReader">The batch reader to get the batch stream from.</param> public BatchReaderStreamWrapper(ODataBatchReader batchReader) { this.batchStream = ReflectionUtils.GetField(batchReader, "batchStream"); this.batchStreamBuffer = new BatchReaderStreamBufferWrapper(this.batchStream); }
/// <summary> /// Runs the test action of this test after setting up the input memory stream. /// </summary> /// <param name="streamBuffer">The batch reader stream buffer to test.</param> /// <param name="memoryStream">The memory stream with the input payload.</param> protected abstract void RunTestAction(BatchReaderStreamBufferWrapper streamBuffer, MemoryStream memoryStream);
/// <summary> /// Runs the test action of this test after setting up the input memory stream. /// </summary> /// <param name="streamBuffer">The batch reader stream buffer to test.</param> /// <param name="memoryStream">The memory stream with the input payload.</param> protected override void RunTestAction(BatchReaderStreamBufferWrapper streamBuffer, MemoryStream memoryStream) { // fill the buffer streamBuffer.RefillFrom(memoryStream, BatchReaderStreamBufferWrapper.BufferLength); int boundaryStart, boundaryEnd; bool isEndBoundary, isParentBoundary; var scanResult = streamBuffer.ScanForBoundary( this.Boundaries, int.MaxValue, out boundaryStart, out boundaryEnd, out isEndBoundary, out isParentBoundary); this.VerifyResult(streamBuffer, scanResult, boundaryStart, boundaryEnd, isEndBoundary, isParentBoundary); }
/// <summary> /// Runs the test action of this test after setting up the input memory stream. /// </summary> /// <param name="streamBuffer">The batch reader stream buffer to test.</param> /// <param name="memoryStream">The memory stream with the input payload.</param> protected override void RunTestAction(BatchReaderStreamBufferWrapper streamBuffer, MemoryStream memoryStream) { // fill the buffer streamBuffer.RefillFrom(memoryStream, BatchReaderStreamBufferWrapper.BufferLength); int lineEndStart, lineEndEnd; var scanResult = streamBuffer.ScanForLineEnd(out lineEndStart, out lineEndEnd); this.VerifyResult(streamBuffer, scanResult, lineEndStart, lineEndEnd); }
/// <summary> /// Verifies that the resulting stream buffer is in the expected state. /// </summary> /// <param name="assert">The assertion handler.</param> /// <param name="streamBuffer">The stream buffer whose state to verify.</param> /// <param name="scanResult">The result of scanning the buffer.</param> /// <param name="startPos">The start position of the string we searched for.</param> /// <param name="endPos">The end position of the string we searched for.</param> public void VerifyResult(BatchReaderStreamBufferWrapper streamBuffer, BatchReaderStreamBufferWrapper.ODataBatchReaderStreamScanResult scanResult, int startPos, int endPos) { base.VerifyResult(streamBuffer); this.Assert.AreEqual(this.ExpectedScanResult, scanResult, string.Format("\r\n{0}:\r\nExpected scan result '{1}' does not match actual scan result '{2}'.", this.DebugDescription, this.ExpectedScanResult.ToString(), scanResult.ToString())); if (this.ExpectedStartPosition.HasValue) { this.Assert.AreEqual(this.ExpectedStartPosition.Value, startPos, string.Format("\r\n{0}:\r\nExpected start at position '{1}' but reported position is '{2}'.", this.DebugDescription, this.ExpectedStartPosition.Value, startPos)); } if (this.ExpectedEndPosition.HasValue) { this.Assert.AreEqual(this.ExpectedEndPosition.Value, endPos, string.Format("\r\n{0}:\r\nExpected end at position '{1}' but reported position is '{2}'.", this.DebugDescription, this.ExpectedEndPosition.Value, endPos)); } }
/// <summary> /// Runs the test action of this test after setting up the input memory stream. /// </summary> /// <param name="streamBuffer">The batch reader stream buffer to test.</param> /// <param name="memoryStream">The memory stream with the input payload.</param> protected override void RunTestAction(BatchReaderStreamBufferWrapper streamBuffer, MemoryStream memoryStream) { // fill the buffer streamBuffer.RefillFrom(memoryStream, BatchReaderStreamBufferWrapper.BufferLength); streamBuffer.SkipTo(this.SkipTo); this.VerifyResult(streamBuffer); }
protected override void RunTestAction(BatchReaderStreamBufferWrapper streamBuffer, MemoryStream memoryStream) { if (!this.RequireEmptyBuffer) { streamBuffer.RefillFrom(memoryStream, BatchReaderStreamBufferWrapper.BufferLength); } streamBuffer.RefillFrom(memoryStream, this.PreserveFrom); this.VerifyResult(streamBuffer); }
/// <summary> /// Verifies that the resulting stream buffer is in the expected state. /// </summary> /// <param name="assert">The assertion handler.</param> /// <param name="streamBuffer">The stream buffer whose state to verify.</param> /// <param name="scanResult">The result of scanning the buffer.</param> /// <param name="startPos">The start position of the string we searched for.</param> /// <param name="endPos">The end position of the string we searched for.</param> /// <param name="isEndBoundary">true if we detected an end boundary; otherwise false.</param> /// <param name="isParentBoundary">true if we detected a parent boundary; otherwise false.</param> public void VerifyResult( BatchReaderStreamBufferWrapper streamBuffer, BatchReaderStreamBufferWrapper.ODataBatchReaderStreamScanResult scanResult, int startPos, int endPos, bool isEndBoundary, bool isParentBoundary) { base.VerifyResult(streamBuffer, scanResult, startPos, endPos); if (this.ExpectedIsEndBoundary.HasValue) { this.Assert.AreEqual(this.ExpectedIsEndBoundary.Value, isEndBoundary, string.Format("\r\n{0}:\r\nExpected 'isEndBoundary' to be '{1}' but reported value is '{2}'.", this.DebugDescription, this.ExpectedIsEndBoundary.Value, isEndBoundary)); } if (this.ExpectedIsParentBoundary.HasValue) { this.Assert.AreEqual(this.ExpectedIsParentBoundary.Value, isParentBoundary, string.Format("\r\n{0}:\r\nExpected 'isParentBoundary' to be '{1}' but reported value is '{2}'.", this.DebugDescription, this.ExpectedIsParentBoundary.Value, isParentBoundary)); } }