예제 #1
0
        public void testExplicitRefreshAfterCompleteFileUpdate()
        {
            var file = Path.Combine(Path.GetTempPath(), "refresh");

            try {
                System.IO.File.WriteAllLines(file, new string[] { "123,456,3.0" });

                /// create a FileDataModel that always reloads when the underlying file has changed
                FileDataModel dataModel = new FileDataModel(file, false, 0L);
                Assert.AreEqual(3.0f, dataModel.GetPreferenceValue(123L, 456L), EPSILON);

                /// change the underlying file,
                /// we have to wait at least a second to see the change in the file's lastModified timestamp
                System.Threading.Thread.Sleep(2000);
                System.IO.File.WriteAllLines(file, new string[] { "123,456,5.0" });
                dataModel.Refresh(null);

                Assert.AreEqual(5.0f, dataModel.GetPreferenceValue(123L, 456L), EPSILON);
            } finally {
                if (System.IO.File.Exists(file))
                {
                    System.IO.File.Delete(file);
                }
            }
        }
예제 #2
0
        public void testTranspose()
        {
            FileDataModel    tModel    = new FileDataModel(testFileName, true, FileDataModel.DEFAULT_MIN_RELOAD_INTERVAL_MS);
            IPreferenceArray userPrefs = tModel.GetPreferencesFromUser(456);

            Assert.NotNull(userPrefs, "user prefs are null and it shouldn't be");
            IPreferenceArray pref = tModel.GetPreferencesForItem(123);

            Assert.NotNull(pref, "pref is null and it shouldn't be");
            Assert.AreEqual(3, pref.Length(), "pref Size: " + pref.Length().ToString() + " is not: " + 3);
        }
예제 #3
0
        public void testReadRegexSplittedFile()
        {
            var testRegexFileName = Path.Combine(Path.GetTempPath(), "testRegex.txt");

            System.IO.File.WriteAllLines(testRegexFileName, DATA_SPLITTED_WITH_TWO_SPACES);

            try {
                FileDataModel model = new FileDataModel(testRegexFileName, "\\s+");
                Assert.AreEqual(3, model.GetItemIDsFromUser(123).Count());
                Assert.AreEqual(4, model.GetItemIDsFromUser(456).Count());
            } finally {
                if (System.IO.File.Exists(testRegexFileName))
                {
                    System.IO.File.Delete(testRegexFileName);
                }
            }
        }