public void DeleteUnusedKeyFlushesToDisk() { FileBasedDictionaryFileSystem fs = new FileBasedDictionaryFileSystem(); FileBasedDictionary <string, string> dut = CreateFileBasedDictionary(fs, TestEntry); dut.RemoveAndFlush("UnusedKey"); fs.ExpectedFiles[MockEntryFileName].ReadAsString().ShouldEqual(TestEntry); }
public void SetValueAndFlushWritesEntryToDisk() { FileBasedDictionaryFileSystem fs = new FileBasedDictionaryFileSystem(); FileBasedDictionary <string, string> dut = CreateFileBasedDictionary(fs, string.Empty); dut.SetValueAndFlush(TestKey, TestValue); fs.ExpectedFiles[MockEntryFileName].ReadAsString().ShouldEqual(TestEntry); }
public void SetValueAndFlushWritesEntryToDisk() { FileBasedDictionaryFileSystem fs = new FileBasedDictionaryFileSystem(); FileBasedDictionary <string, string> dut = CreateFileBasedDictionary(fs, string.Empty); dut.SetValueAndFlush(TestKey, TestValue); this.FileBasedDictionaryFileSystemShouldContain(fs, new[] { TestEntry }); }
public void SetValueAndFlushUpdatedEntryOnDisk() { FileBasedDictionaryFileSystem fs = new FileBasedDictionaryFileSystem(); FileBasedDictionary <string, string> dut = CreateFileBasedDictionary(fs, TestEntry); dut.SetValueAndFlush(TestKey, UpdatedTestValue); this.FileBasedDictionaryFileSystemShouldContain(fs, new[] { UpdatedTestEntry }); }
public void ParsesExistingDataCorrectly() { FileBasedDictionaryFileSystem fs = new FileBasedDictionaryFileSystem(); FileBasedDictionary <string, string> dut = CreateFileBasedDictionary(fs, TestEntry); string value; dut.TryGetValue(TestKey, out value).ShouldEqual(true); value.ShouldEqual(TestValue); }
public void SetValueAndFlushRecoversFromMixOfFailures() { FileBasedDictionaryFileSystem fs = new FileBasedDictionaryFileSystem(failuresAcrossOpenExistsAndOverwritePath: MockEntryFileName + ".tmp"); FileBasedDictionary <string, string> dut = CreateFileBasedDictionary(fs, string.Empty); dut.SetValueAndFlush(TestKey, TestValue); fs.ExpectedFiles[MockEntryFileName].ReadAsString().ShouldEqual(TestEntry); }
public void SetValueAndFlushRecoversFromMixOfFailures() { FileBasedDictionaryFileSystem fs = new FileBasedDictionaryFileSystem(failuresAcrossOpenExistsAndOverwritePath: MockEntryFileName + ".tmp"); FileBasedDictionary <string, string> dut = CreateFileBasedDictionary(fs, string.Empty); dut.SetValueAndFlush(TestKey, TestValue); this.FileBasedDictionaryFileSystemShouldContain(fs, new[] { TestEntry }); }
public void SetValuesAndFlushUsesLastValueWhenKeyDuplicated() { FileBasedDictionaryFileSystem fs = new FileBasedDictionaryFileSystem(); FileBasedDictionary <string, string> dut = CreateFileBasedDictionary(fs, string.Empty); dut.SetValuesAndFlush( new[] { new KeyValuePair <string, string>(TestKey, TestValue), new KeyValuePair <string, string>(TestKey, UpdatedTestValue), }); fs.ExpectedFiles[MockEntryFileName].ReadAsString().ShouldEqual(UpdatedTestEntry); }
public void SetValuesAndFlushWritesEntriesToDisk() { FileBasedDictionaryFileSystem fs = new FileBasedDictionaryFileSystem(); FileBasedDictionary <string, string> dut = CreateFileBasedDictionary(fs, string.Empty); dut.SetValuesAndFlush( new[] { new KeyValuePair <string, string>(TestKey, TestValue), new KeyValuePair <string, string>(TestKey2, TestValue2), }); this.FileBasedDictionaryFileSystemShouldContain(fs, new[] { TestEntry, TestEntry2 }); }
public void SetValuesAndFlushUsesLastValueWhenKeyDuplicated() { FileBasedDictionaryFileSystem fs = new FileBasedDictionaryFileSystem(); FileBasedDictionary <string, string> dut = CreateFileBasedDictionary(fs, string.Empty); dut.SetValuesAndFlush( new[] { new KeyValuePair <string, string>(TestKey, TestValue), new KeyValuePair <string, string>(TestKey, UpdatedTestValue), }); this.FileBasedDictionaryFileSystemShouldContain(fs, new[] { UpdatedTestEntry }); }
public void SetValuesAndFlushWritesEntriesToDisk() { FileBasedDictionaryFileSystem fs = new FileBasedDictionaryFileSystem(); FileBasedDictionary <string, string> dut = CreateFileBasedDictionary(fs, string.Empty); dut.SetValuesAndFlush( new[] { new KeyValuePair <string, string>(TestKey, TestValue), new KeyValuePair <string, string>(TestKey2, TestValue2), }); fs.ExpectedFiles[MockEntryFileName].ReadAsString().ShouldEqual(TestEntry + TestEntry2); }
public void SetValueAndFlushRecoversFromDeletedTempAndFailedOverwrite() { FileBasedDictionaryFileSystem fs = new FileBasedDictionaryFileSystem( openFileStreamFailurePath: null, maxOpenFileStreamFailures: 0, fileExistsFailurePath: MockEntryFileName + ".tmp", maxFileExistsFailures: 5, maxMoveAndOverwriteFileFailures: 5); FileBasedDictionary <string, string> dut = CreateFileBasedDictionary(fs, string.Empty); dut.SetValueAndFlush(TestKey, TestValue); fs.ExpectedFiles[MockEntryFileName].ReadAsString().ShouldEqual(TestEntry); }
public void SetValueAndFlushRecoversFromDeletedTempAndFailedOverwrite() { FileBasedDictionaryFileSystem fs = new FileBasedDictionaryFileSystem( openFileStreamFailurePath: null, maxOpenFileStreamFailures: 0, fileExistsFailurePath: MockEntryFileName + ".tmp", maxFileExistsFailures: 5, maxMoveAndOverwriteFileFailures: 5); FileBasedDictionary <string, string> dut = CreateFileBasedDictionary(fs, string.Empty); dut.SetValueAndFlush(TestKey, TestValue); this.FileBasedDictionaryFileSystemShouldContain(fs, new[] { TestEntry }); }
public void SetValuesAndFlushWritesNewEntryAndUpdatesExistingEntryOnDisk() { FileBasedDictionaryFileSystem fs = new FileBasedDictionaryFileSystem(); FileBasedDictionary <string, string> dut = CreateFileBasedDictionary(fs, string.Empty); // Add TestKey to disk dut.SetValueAndFlush(TestKey, TestValue); fs.ExpectedFiles[MockEntryFileName].ReadAsString().ShouldEqual(TestEntry); // This call to SetValuesAndFlush should update TestKey and write TestKey2 dut.SetValuesAndFlush( new[] { new KeyValuePair <string, string>(TestKey, UpdatedTestValue), new KeyValuePair <string, string>(TestKey2, TestValue2), }); this.FileBasedDictionaryFileSystemShouldContain(fs, new[] { UpdatedTestEntry, TestEntry2 }); }
private void FileBasedDictionaryFileSystemShouldContain( FileBasedDictionaryFileSystem fs, IList <string> expectedEntries) { string delimiter = "\r\n"; string fileContents = fs.ExpectedFiles[MockEntryFileName].ReadAsString(); fileContents.Substring(fileContents.Length - delimiter.Length).ShouldEqual(delimiter); // Remove the trailing delimiter fileContents = fileContents.Substring(0, fileContents.Length - delimiter.Length); string[] fileLines = fileContents.Split(new[] { delimiter }, StringSplitOptions.None); fileLines.Length.ShouldEqual(expectedEntries.Count); foreach (string expectedEntry in expectedEntries) { fileLines.ShouldContain(line => line.Equals(expectedEntry.Substring(0, expectedEntry.Length - delimiter.Length))); } }
private static FileBasedDictionary <string, string> CreateFileBasedDictionary(FileBasedDictionaryFileSystem fs, string initialContents) { fs.ExpectedFiles.Add(MockEntryFileName, new ReusableMemoryStream(initialContents)); fs.ExpectedOpenFileStreams.Add(MockEntryFileName + ".tmp", new ReusableMemoryStream(string.Empty)); fs.ExpectedOpenFileStreams.Add(MockEntryFileName, fs.ExpectedFiles[MockEntryFileName]); string error; FileBasedDictionary <string, string> dut; FileBasedDictionary <string, string> .TryCreate(null, MockEntryFileName, fs, out dut, out error).ShouldEqual(true, error); dut.ShouldNotBeNull(); // FileBasedDictionary should only open a file stream to the non-tmp file when being created. At all other times it should // write to a tmp file and overwrite the non-tmp file fs.ExpectedOpenFileStreams.Remove(MockEntryFileName); return(dut); }