Example #1
0
        /// <summary>
        /// Sends a get file range request with the given parameters and validates both request and response.
        /// </summary>
        /// <param name="shareName">The file's share's name.</param>
        /// <param name="fileName">The file's name.</param>
        /// <param name="leaseId">The lease ID, or null if there is no lease.</param>
        /// <param name="content">The total contents of the file.</param>
        /// <param name="offset">The offset of the contents we will get.</param>
        /// <param name="count">The number of bytes we will get, or null to get the rest of the file.</param>
        /// <param name="expectedError">The error code we expect from this operation, or null if we expect it to succeed.</param>
        public async Task GetFileRangeScenarioTest(string shareName, string fileName, byte[] content, long offset, long?count, HttpStatusCode?expectedError)
        {
            HttpRequestMessage request = FileTests.GetFileRangeRequest(FileContext, shareName, fileName, offset, count, null);

            Assert.IsTrue(request != null, "Failed to create HttpRequestMessage");

            HttpResponseMessage response = await FileTestUtils.GetResponse(request, FileContext);

            try
            {
                long   endRange        = count.HasValue ? count.Value + offset - 1 : content.Length - 1;
                byte[] selectedContent = null;

                // Compute expected content only if call is expected to succeed.
                if (expectedError == null)
                {
                    selectedContent = new byte[endRange - offset + 1];
                    Array.Copy(content, offset, selectedContent, 0, selectedContent.Length);
                }

                FileTests.CheckFileRangeResponse(response, FileContext, selectedContent, offset, endRange, content.Length, expectedError);
            }
            finally
            {
                response.Dispose();
            }
        }