private static void VerifyReadWrite <T>(int valueLength, T value, Func <ServiceBufferFileStreamWriter, T, int> writeFunc, Func <ServiceBufferFileStreamReader, FileStreamReadResult> readFunc) { // Setup: Create a mock file stream wrapper Common.InMemoryWrapper mockWrapper = new Common.InMemoryWrapper(); try { // If: // ... I write a type T to the writer using (ServiceBufferFileStreamWriter writer = new ServiceBufferFileStreamWriter(mockWrapper, "abc", 10, 10)) { int writtenBytes = writeFunc(writer, value); Assert.Equal(valueLength, writtenBytes); } // ... And read the type T back FileStreamReadResult outValue; using (ServiceBufferFileStreamReader reader = new ServiceBufferFileStreamReader(mockWrapper, "abc")) { outValue = readFunc(reader); } // Then: Assert.Equal(value, outValue.Value.RawObject); Assert.Equal(valueLength, outValue.TotalLength); Assert.NotNull(outValue.Value); } finally { // Cleanup: Close the wrapper mockWrapper.Close(); } }
public void BytesNullTest() { // Setup: Create a mock file stream wrapper Common.InMemoryWrapper mockWrapper = new Common.InMemoryWrapper(); // If: // ... I write null as a string to the writer using (ServiceBufferFileStreamWriter writer = new ServiceBufferFileStreamWriter(mockWrapper, "abc", 10, 10)) { // Then: // ... I should get an argument null exception Assert.Throws <ArgumentNullException>(() => writer.WriteBytes(null)); } }