private static void GetPutTestAssert(byte expectedValue, int expectedIndex, FileWithHeader target) { int nextIndexBefore = target.GetNextIndex(); target.Put(expectedIndex, expectedValue); if (expectedIndex >= nextIndexBefore) { Assert.AreEqual(expectedIndex + 1, target.GetNextIndex()); } Assert.AreEqual(expectedValue, target.Get(expectedIndex)); }
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(); } }