Esempio n. 1
0
 public void BytesNullTest()
 {
     // Setup: Create a mock file stream wrapper
     using (MemoryStream stream = new MemoryStream(new byte[8192]))
     {
         // If:
         // ... I write null as a string to the writer
         using (ServiceBufferFileStreamWriter writer = new ServiceBufferFileStreamWriter(stream, new QueryExecutionSettings()))
         {
             // Then:
             // ... I should get an argument null exception
             Assert.Throws <ArgumentNullException>(() => writer.WriteBytes(null));
         }
     }
 }
Esempio n. 2
0
        private static string VerifyReadWrite <T>(int valueLength, T value,
                                                  Func <ServiceBufferFileStreamWriter, T, int> writeFunc,
                                                  Func <ServiceBufferFileStreamReader, long, FileStreamReadResult> readFunc,
                                                  QueryExecutionSettings overrideSettings = null)
        {
            // Setup: Create a mock file stream
            byte[] storage = new byte[8192];
            overrideSettings = overrideSettings ?? new QueryExecutionSettings();
            const long rowId = 100;

            // If:
            // ... I write a type T to the writer
            using (ServiceBufferFileStreamWriter writer = new ServiceBufferFileStreamWriter(new MemoryStream(storage), overrideSettings))
            {
                int writtenBytes = writeFunc(writer, value);
                Assert.Equal(valueLength, writtenBytes);
            }

            // ... And read the type T back
            FileStreamReadResult outValue;

            using (ServiceBufferFileStreamReader reader = new ServiceBufferFileStreamReader(new MemoryStream(storage), overrideSettings))
            {
                outValue = readFunc(reader, rowId);
            }

            // Then:
            Assert.Equal(value, outValue.Value.RawObject);
            Assert.Equal(valueLength, outValue.TotalLength);
            Assert.NotNull(outValue.Value);

            // ... The id we set should be stored in the returned db cell value
            Assert.Equal(rowId, outValue.Value.RowId);

            return(outValue.Value.DisplayValue);
        }