public void CloseTest() { FileWithHeader fwh = InitFWH("FWHCloseTest", 5); try { fwh.Close(); fwh = InitFWH("FWHCloseTest", 3); } finally { fwh.Close(); } }
private void GetUserHeaderSizeTestAssert(int expected) { FileWithHeader target = InitFWH("GetFWHUserHeaderSizeTest", expected); try { int actual = target.GetUserHeaderSize(); Assert.AreEqual(expected, actual); } finally { target.Close(); } }
private void GetNextIndexTestAssert(int expected) { FileWithHeader target = InitFWH("GetFWHNextIndexTest", 16); try { target.Put(expected - 1, 0); int actual = target.GetNextIndex(); Assert.AreEqual(expected, actual); } finally { target.Close(); } }
private void GetPutUserHeaderTest(byte[] uHeader) { FileWithHeader target = InitFWH("GetPutUserHeaderTest", 16); try { target.PutUserHeader(uHeader); byte[] actual = target.GetUserHeader(); TestHelper.AssertByteArraysAreSame(uHeader, actual); } finally { target.Close(); } }
public void GetRangeTest() { FileWithHeader fwh = InitFWH("FWHGetRangeTest", 5); try { GetRangeTestAssert(new byte[] { 1, 2, 3, 4 }, 0, fwh); GetRangeTestAssert(new byte[] { }, 6, fwh); GetRangeTestAssert(new byte[] { 0 }, 8, fwh); GetRangeTestAssert(new byte[] { byte.MaxValue, byte.MaxValue, byte.MaxValue }, 10, fwh); GetRangeTestAssert(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }, 20, fwh); } finally { fwh.Close(); } }
public void GetPutTest() { FileWithHeader target = InitFWH("GetPutFWHTest", 5); try { GetPutTestAssert(8, 44, target); GetPutTestAssert(0, 44, target); GetPutTestAssert(99, 0, target); GetPutTestAssert(20, byte.MaxValue, target); GetPutTestAssert(4, 4, target); } finally { target.Close(); } }
public void PutGetAmountTest() { FileWithHeader fwh = InitFWH("FWHPutGetAmountTest", 5); try { GetPutArrayTestAssert(fwh, 9, new byte[] { }); GetPutArrayTestAssert(fwh, 3, new byte[] { byte.MaxValue, byte.MinValue }); GetPutArrayTestAssert(fwh, 50, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }); GetPutArrayTestAssert(fwh, 10, new byte[] { 7, 7, 7 }); GetPutArrayTestAssert(fwh, 30, new byte[] { 12, 34, 56, 78, 90 }); GetPutArrayTestAssert(fwh, 25, new byte[] { 0, 0, 0, 0, 0, 0, 0 }); } finally { fwh.Close(); } }
public void FileAlreadyExistsTest() { string fileName = "AlreadyExists"; FileWithHeader fwh = InitFWH(fileName, 5); FileWithHeader fwh2 = null; try { fwh2 = new FileWithHeader(fileName, 5); Assert.Fail("Should throw exception"); } catch (FileNameConflictException) { } finally { fwh.Close(); if (fwh2 != null) //if for some reason it actuall worked, { fwh2.Close(); // still close the file } } }
public void ReopenTest() { string fileName = "ReopenFileWithHeaderTest"; FileWithHeader fwh = InitFWH(fileName, 5); try { //write values int expectedIndex1 = 0; byte expectedValue1 = 6; fwh.Put(expectedIndex1, expectedValue1); int expectedIndex2 = 55; byte expectedValue2 = 200; fwh.Put(expectedIndex2, expectedValue2); //get next index int expectedNextIndex = fwh.GetNextIndex(); byte[] expectedUserHeader = new byte[5] { 1, 2, 3, 4, 5 }; fwh.PutUserHeader(expectedUserHeader); fwh.Close(); fwh = new FileWithHeader(fileName); Assert.AreEqual(expectedValue1, fwh.Get(expectedIndex1)); Assert.AreEqual(expectedValue2, fwh.Get(expectedIndex2)); Assert.AreEqual(expectedNextIndex, fwh.GetNextIndex()); TestHelper.AssertByteArraysAreSame(expectedUserHeader, fwh.GetUserHeader()); } finally { fwh.Close(); } }
public void Close() { _fileWithHeader.Close(); }
public void Close() { _file.Close(); }