public void op_Save_LexiconNull()
        {
            using (var file = new TempFile())
            {
                IStoreLexicon store = new CsvLexiconStorage(file.Info);

                Assert.Throws <ArgumentNullException>(() => store.Save(null));
            }
        }
        public void op_Save_LexiconWhenEmpty()
        {
            using (var file = new TempFile())
            {
                file.Info.Delete();

                IStoreLexicon store = new CsvLexiconStorage(file.Info);
                store.Save(new Lexicon(NormalityComparer.Ordinal));

                file.Info.Refresh();
                Assert.True(file.Info.Exists);

                Assert.True(File.ReadAllText(file.Info.FullName).StartsWith("CANONICAL,SYNONYMS", StringComparison.Ordinal));
            }
        }
        public void op_Load_INormalityComparerNull()
        {
            using (var file = new TempFile())
            {
                file.Info.Delete();

                var lexicon = new Lexicon(NormalityComparer.Ordinal)
                {
                    "Example"
                };

                IStoreLexicon store = new CsvLexiconStorage(file.Info);
                store.Save(lexicon);

                Assert.Throws <ArgumentNullException>(() => store.Load(null));
            }
        }
Beispiel #4
0
        protected virtual bool Execute(FileInfo file)
        {
            if (null != file)
            {
                file.Refresh();
                if (file.Exists)
                {
                    var lexicon = new CsvLexiconStorage(file).Load(NormalizationComparer.OrdinalIgnoreCase);
                    file.Delete();
                    lexicon.Save();
                    Log.LogMessage(file.FullName);
                    return true;
                }

                Log.LogWarning(file.FullName);
            }

            return false;
        }
        public void op_Save_LexiconWithComma()
        {
            using (var file = new TempFile())
            {
                file.Info.Delete();

                var lexicon = new Lexicon(NormalityComparer.Ordinal)
                {
                    "foo, bar"
                };

                IStoreLexicon store = new CsvLexiconStorage(file.Info);
                store.Save(lexicon);

                file.Info.Refresh();
                Assert.True(file.Info.Exists);

                Assert.True(store.Load(NormalityComparer.Ordinal).Contains("foo, bar"));
            }
        }
        public void op_Save_LexiconWithComma()
        {
            using (var file = new TempFile())
            {
                file.Info.Delete();

                var lexicon = new Lexicon(NormalityComparer.Ordinal)
                                  {
                                      "foo, bar"
                                  };

                IStoreLexicon store = new CsvLexiconStorage(file.Info);
                store.Save(lexicon);

                file.Info.Refresh();
                Assert.True(file.Info.Exists);

                Assert.True(store.Load(NormalityComparer.Ordinal).Contains("foo, bar"));
            }
        }
        public void op_Save_LexiconWhenEmpty()
        {
            using (var file = new TempFile())
            {
                file.Info.Delete();

                IStoreLexicon store = new CsvLexiconStorage(file.Info);
                store.Save(new Lexicon(NormalityComparer.Ordinal));

                file.Info.Refresh();
                Assert.True(file.Info.Exists);

                Assert.True(File.ReadAllText(file.Info.FullName).StartsWith("CANONICAL,SYNONYMS", StringComparison.Ordinal));
            }
        }
        public void op_Save_LexiconNull()
        {
            using (var file = new TempFile())
            {
                IStoreLexicon store = new CsvLexiconStorage(file.Info);

                Assert.Throws<ArgumentNullException>(() => store.Save(null));
            }
        }
        public void op_Load_INormalityComparerNull()
        {
            using (var file = new TempFile())
            {
                file.Info.Delete();

                var lexicon = new Lexicon(NormalityComparer.Ordinal)
                                  {
                                      "Example"
                                  };

                IStoreLexicon store = new CsvLexiconStorage(file.Info);
                store.Save(lexicon);

                Assert.Throws<ArgumentNullException>(() => store.Load(null));
            }
        }