public void cannot_add_null_fields() { Should.Throw <ArgumentNullException>(() => headers.Add("key", null)); Should.Throw <ArgumentNullException>(() => headers.Add(null, "value")); Should.Throw <ArgumentNullException>(() => headers.Add(null, null)); Should.Throw <ArgumentNullException>(() => headers.ContainsKey(null)); }
private void WriteBlock(string transferId, long blockNumber, Stream input) { //get meta information from headers VfsHttpHeaders headerNames = VfsHttpHeaders.Default; HttpHeaderDictionary headers = Request.Headers; var blockLength = Convert.ToInt32(headers[headerNames.BlockLength]); var isLastBlock = headers.ContainsKey(headerNames.IsLastBlock) ? Convert.ToBoolean(headers[headerNames.IsLastBlock]) : false; var offset = Convert.ToInt64(headers[headerNames.BlockOffset]); StreamedDataBlock block = new StreamedDataBlock { TransferTokenId = transferId, BlockNumber = blockNumber, IsLastBlock = isLastBlock, BlockLength = blockLength, Offset = offset, Data = new NonSeekableStream(input) }; FileSystem.UploadTransfers.WriteBlockStreamed(block); }
public static void ShouldHaveHeaderValues(this HttpHeaderDictionary headers, string fieldName, params string[] fieldValue) { var combinedFieldValues = string.Join(",", fieldValue); // indexer headers[fieldName].ShouldBe(combinedFieldValues); // singular headers.TryGetValue(fieldName, out var singular).ShouldBeTrue(); singular.ShouldBe(combinedFieldValues); // multi headers.TryGetValues(fieldName, out var all).ShouldBeTrue(); all.ShouldBe(fieldValue); // keys contain headers.Keys.ShouldContain(fieldName); headers.ContainsKey(fieldName).ShouldBeTrue(); // values contain (why again, why?) headers.Values.ShouldContain(combinedFieldValues); foreach (var val in fieldValue) { headers.Contains(new KeyValuePair <string, string>(fieldName, val)).ShouldBeTrue(); } // convert to dictionary new Dictionary <string, string>(headers)[fieldName].ShouldBe(combinedFieldValues); // copy to array (why why why?) var array = new KeyValuePair <string, string> [10]; headers.CopyTo(array, 0); array.Any(item => item.Key == fieldName && item.Value == combinedFieldValues).ShouldBeTrue(); }