Beispiel #1
0
        public void DeleteUnusedKeyFlushesToDisk()
        {
            FileBasedDictionaryFileSystem        fs  = new FileBasedDictionaryFileSystem();
            FileBasedDictionary <string, string> dut = CreateFileBasedDictionary(fs, TestEntry);

            dut.RemoveAndFlush("UnusedKey");

            fs.ExpectedFiles[MockEntryFileName].ReadAsString().ShouldEqual(TestEntry);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        public void SetValueAndFlushWritesEntryToDisk()
        {
            FileBasedDictionaryFileSystem        fs  = new FileBasedDictionaryFileSystem();
            FileBasedDictionary <string, string> dut = CreateFileBasedDictionary(fs, string.Empty);

            dut.SetValueAndFlush(TestKey, TestValue);

            this.FileBasedDictionaryFileSystemShouldContain(fs, new[] { TestEntry });
        }
Beispiel #4
0
        public void SetValueAndFlushUpdatedEntryOnDisk()
        {
            FileBasedDictionaryFileSystem        fs  = new FileBasedDictionaryFileSystem();
            FileBasedDictionary <string, string> dut = CreateFileBasedDictionary(fs, TestEntry);

            dut.SetValueAndFlush(TestKey, UpdatedTestValue);

            this.FileBasedDictionaryFileSystemShouldContain(fs, new[] { UpdatedTestEntry });
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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 });
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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 });
        }
Beispiel #10
0
        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 });
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
        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);
        }
Beispiel #13
0
        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 });
        }
Beispiel #14
0
        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 });
        }
Beispiel #15
0
        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)));
            }
        }
Beispiel #16
0
        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);
        }