Commits

Nerzhul500 committed dcb7b2e

Refactoring and tests

Comments (0)

Files changed (12)

ReSpeller.BasicTests/IdentifierSplitterTest.cs

-using System.Collections.Generic;
-using NUnit.Framework;
-using ReSpeller.SpellEngine;
-
-namespace ReSpeller.BasicTests
-{
-  [TestFixture]
-  internal class IdentifierSplitterTest
-  {
-    private static readonly object[] ourCases =
-      {
-        new object[] {"ident", new List<TextPart> {new TextPart("ident", TextPartType.Word, 0, 4)}},
-        new object[]
-          {
-            "newIdent", new List<TextPart>
-                          {
-                            new TextPart("new", TextPartType.Word, 0, 2),
-                            new TextPart("Ident", TextPartType.Word, 3, 7)
-                          }
-          },
-        new object[]
-          {
-            "new123Ident", new List<TextPart>
-                             {
-                               new TextPart("new", TextPartType.Word, 0, 2),
-                               new TextPart("123", TextPartType.NotAWord, 3, 5),
-                               new TextPart("Ident", TextPartType.Word, 6, 10)
-                             }
-          },
-        new object[]
-          {
-            "MyIdent", new List<TextPart>
-                         {
-                           new TextPart("My", TextPartType.Word, 0, 1),
-                           new TextPart("Ident", TextPartType.Word, 2, 6)
-                         }
-          },
-        new object[]
-          {
-            "My123", new List<TextPart>
-                       {
-                         new TextPart("My", TextPartType.Word, 0, 1),
-                         new TextPart("123", TextPartType.NotAWord, 2, 4)
-                       }
-          },
-        new object[] {"Ident", new List<TextPart> {new TextPart("Ident", TextPartType.Word, 0, 4)}},
-        new object[]
-          {
-            "my_ident", new List<TextPart>
-                          {
-                            new TextPart("my", TextPartType.Word, 0, 1),
-                            new TextPart("_", TextPartType.NotAWord, 2, 2),
-                            new TextPart("ident", TextPartType.Word, 3, 7)
-                          }
-          },
-        new object[]
-          {
-            "my_Ident", new List<TextPart>
-                          {
-                            new TextPart("my", TextPartType.Word, 0, 1),
-                            new TextPart("_", TextPartType.NotAWord, 2, 2),
-                            new TextPart("Ident", TextPartType.Word, 3, 7)
-                          }
-          },
-        new object[]
-          {
-            "CAPITAL_ONLY", new List<TextPart>
-                              {
-                                new TextPart("CAPITAL", TextPartType.Word, 0, 6),
-                                new TextPart("_", TextPartType.NotAWord, 7, 7),
-                                new TextPart("ONLY", TextPartType.Word, 8, 11)
-                              }
-          },
-        new object[]
-          {
-            "CAPITAL_andNotONLY", new List<TextPart>
-                                    {
-                                      new TextPart("CAPITAL", TextPartType.Word, 0, 6),
-                                      new TextPart("_", TextPartType.NotAWord, 7, 7),
-                                      new TextPart("and", TextPartType.Word, 8, 10),
-                                      new TextPart("Not", TextPartType.Word, 11, 13),
-                                      new TextPart("ONLY", TextPartType.Word, 14, 17)
-                                    }
-          },
-        new object[]
-          {
-            "FUCKText", new List<TextPart>
-                          {
-                            new TextPart("FUCK", TextPartType.Word, 0, 3),
-                            new TextPart("Text", TextPartType.Word, 4, 7)
-                          }
-          },
-        new object[]
-          {
-            "andFUCKText", new List<TextPart>
-                             {
-                               new TextPart("and", TextPartType.Word, 0, 2),
-                               new TextPart("FUCK", TextPartType.Word, 3, 6),
-                               new TextPart("Text", TextPartType.Word, 7, 10)
-                             }
-          },
-        new object[]
-          {
-            "some Text", new List<TextPart>
-                           {
-                             new TextPart("some", TextPartType.Word, 0, 3),
-                             new TextPart(" ", TextPartType.NotAWord, 4, 4),
-                             new TextPart("Text", TextPartType.Word, 5, 8)
-                           }
-          },
-        new object[]
-          {
-            "he won't do", new List<TextPart>
-                             {
-                               new TextPart("he", TextPartType.Word, 0, 1),
-                               new TextPart(" ", TextPartType.NotAWord, 2, 2),
-                               new TextPart("won't", TextPartType.Word, 3, 7),
-                               new TextPart(" ", TextPartType.NotAWord, 8, 8),
-                               new TextPart("do", TextPartType.Word, 9, 10)
-                             }
-          },
-        new object[]
-          {
-            "he won'", new List<TextPart>
-                         {
-                           new TextPart("he", TextPartType.Word, 0, 1),
-                           new TextPart(" ", TextPartType.NotAWord, 2, 2),
-                           new TextPart("won", TextPartType.Word, 3, 5),
-                           new TextPart("'", TextPartType.NotAWord, 6, 6)
-                         }
-          },
-        new object[]
-          {
-            "he 'won", new List<TextPart>
-                         {
-                           new TextPart("he", TextPartType.Word, 0, 1),
-                           new TextPart(" '", TextPartType.NotAWord, 2, 3),
-                           new TextPart("won", TextPartType.Word, 4, 6)
-                         }
-          }
-      };
-
-    [Test, TestCaseSource("ourCases")]
-    public void SplitTest(string text, List<TextPart> result)
-    {
-      List<TextPart> actual = TextSplitter.Split(text);
-      Assert.AreEqual(result, actual);
-    }
-  }
-}

ReSpeller.BasicTests/ReSpeller.BasicTests.csproj

     </CodeAnalysisDependentAssemblyPaths>
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="IdentifierSplitterTest.cs" />
+    <Compile Include="SpellEngine\Dictionaries\UserInternalDictionaryTest.cs" />
+    <Compile Include="SpellEngine\TextSplitterTest.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
-    <Compile Include="SuggestionGeneratorTest.cs" />
+    <Compile Include="SpellEngine\SuggestionGeneratorTest.cs" />
   </ItemGroup>
   <ItemGroup>
     <WCFMetadata Include="Service References\" />
       <Name>ReSpeller</Name>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup />
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 

ReSpeller.BasicTests/SpellEngine/Dictionaries/UserInternalDictionaryTest.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using ReSpeller.SpellEngine.Dictionaries;
+using Rhino.Mocks;
+
+namespace ReSpeller.BasicTests.SpellEngine.Dictionaries
+{
+  [TestFixture]
+  public class UserInternalDictionaryTest
+  {
+    private IUserInternalDictionary myUserInternalDictionary;
+    private IDictionaryEngine myDictionaryEngine;
+    private IDictionaryStorage myUserStorage;
+    private IDictionaryStorage myInternalStorage;
+    private string myLanguage;
+
+    [SetUp]
+    public void SetUp()
+    {
+      myDictionaryEngine = MockRepository.GenerateMock<IDictionaryEngine>();
+      myUserStorage = MockRepository.GenerateMock<IDictionaryStorage>();
+      myInternalStorage = MockRepository.GenerateMock<IDictionaryStorage>();
+      myLanguage = "en_US";
+      myUserInternalDictionary = new UserInternalDictionary(myDictionaryEngine, myLanguage, myUserStorage, myInternalStorage);
+    }
+
+    [Test]
+    public void TestCheckWord()
+    {
+      myDictionaryEngine.Stub(engine => engine.Check("word")).Repeat.Once().Return(true);
+      myDictionaryEngine.Stub(engine => engine.Check("woard")).Repeat.Once().Return(false);
+      bool correctWord = myUserInternalDictionary.Check("word");
+      Assert.IsTrue(correctWord);
+      bool incorrectWord = myUserInternalDictionary.Check("woard");
+      Assert.IsFalse(incorrectWord);
+      myDictionaryEngine.VerifyAllExpectations();
+    }
+
+    [Test]
+    public void TestAddToUser()
+    {
+      myUserStorage.Stub(storage => storage.AddWord("woard")).Repeat.Once();
+      myDictionaryEngine.Stub(engine => engine.Add("woard")).Repeat.Once();
+      myDictionaryEngine.Stub(engine => engine.Check("woard")).Repeat.Once().Return(true);
+      myUserInternalDictionary.AddToUserDict("woard");
+      bool check = myUserInternalDictionary.Check("woard");
+      Assert.IsTrue(check);
+      myUserStorage.VerifyAllExpectations();
+      myDictionaryEngine.VerifyAllExpectations();
+    }
+
+    [Test]
+    public void TestAddToInternal()
+    {
+      myInternalStorage.Stub(storage => storage.AddWord("woard")).Repeat.Once();
+      myDictionaryEngine.Stub(engine => engine.Add("woard")).Repeat.Once();
+      myDictionaryEngine.Stub(engine => engine.Check("woard")).Repeat.Once().Return(true);
+      myUserInternalDictionary.AddToInternalDict("woard");
+      bool check = myUserInternalDictionary.Check("woard");
+      Assert.IsTrue(check);
+      myInternalStorage.VerifyAllExpectations();
+      myDictionaryEngine.VerifyAllExpectations();
+    }
+
+    [Test]
+    public void TestLanguage()
+    {
+      Assert.AreEqual(myLanguage, myUserInternalDictionary.Language);
+    }
+  }
+}

ReSpeller.BasicTests/SpellEngine/SuggestionGeneratorTest.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using NUnit.Framework;
+using ReSpeller.SpellEngine;
+using Rhino.Mocks;
+
+namespace ReSpeller.BasicTests.SpellEngine
+{
+  /// <summary>
+  /// Summary description for SuggestionGeneratorTest
+  /// </summary>
+  [TestFixture]
+  public class SuggestionGeneratorTest
+  {
+    private readonly ISpellChecker myChecker;
+    private readonly SuggestionGenerator myGenerator;
+
+    public SuggestionGeneratorTest()
+    {
+      myChecker = MockRepository.GenerateStub<ISpellChecker>();
+      myGenerator = new SuggestionGenerator(myChecker);
+      Dictionary<string, string> suggests = new Dictionary<string, string>
+                                              {
+                                                {"idetnifier", "identifier verifier"},
+                                                {"Idetnifier", "identifier verifier"},
+                                                {"my", "my"},
+                                                {"My", "my"},
+                                                {"ixdent", "ident indent"},
+                                                {"Ixdent", "ident indent"},
+                                                {"Sufh", "such much"},
+                                                {"sufh", "such much"},
+                                                {"Fael", "fail fuel fall"},
+                                                {"fael", "fail fuel fall"},
+                                                {"Werd", "ward weird"},
+                                                {"werd", "ward weird"}
+                                              };
+      foreach (var suggest in suggests)
+      {
+        KeyValuePair<string, string> suggest1 = suggest;
+        myChecker.Stub(checker => checker.Suggestions(suggest1.Key)).Return(suggest1.Value.Split(' ').ToList());
+      }
+      Dictionary<string, bool> wordValidity = new Dictionary<string, bool>
+                                                {
+                                                  {"Idetnifier", false},
+                                                  {"idetnifier", false},
+                                                  {"ixdent", false},
+                                                  {"Ixdent", false},
+                                                  {"Sufh", false},
+                                                  {"sufh", false},
+                                                  {"my", true},
+                                                  {"My", true},
+                                                  {"Fael", false},
+                                                  {"Werd", false},
+                                                  {"best", true}
+                                                };
+      foreach (var pair in wordValidity)
+      {
+        KeyValuePair<string, bool> pair1 = pair;
+        myChecker.Stub(checker => checker.CheckWordSpelling(pair1.Key)).Return(pair1.Value);
+      }
+      myGenerator = new SuggestionGenerator(myChecker);
+    }
+
+    [Test]
+    [TestCase("myIdetnifier")]
+    [TestCase("myIdetnifier123Idetnifier")]
+    [TestCase("myIdetnifier123Ixdent")]
+    [TestCase("mySufh123Idetnifier")]
+    [TestCase("bestFaelWerd")]
+    public void SuggestsTest(string s)
+    {
+      var parts = TextSplitter.Split(s);
+      var variants = (from part in parts
+                     select part.Type == TextPartType.NotAWord || myChecker.CheckWordSpelling(part.Text) ?
+                          new List<string> { part.Text } : myChecker.Suggestions(part.Text).Where(s1 => s1.All(Char.IsLetter)).ToList()).
+                          ToList();
+      var expectedCount = variants.Aggregate(1, (i, list) => i * list.Count);
+      var suggests = myGenerator.Generate(s);
+      Assert.AreEqual(expectedCount, suggests.Count);
+    }
+  }
+}

ReSpeller.BasicTests/SpellEngine/TextSplitterTest.cs

+using System.Collections.Generic;
+using NUnit.Framework;
+using ReSpeller.SpellEngine;
+
+namespace ReSpeller.BasicTests.SpellEngine
+{
+  [TestFixture]
+  internal class TextSplitterTest
+  {
+    private static readonly object[] Cases =
+      {
+        new object[] {"ident", new List<TextPart> {new TextPart("ident", TextPartType.Word, 0, 4)}},
+        new object[]
+          {
+            "newIdent", new List<TextPart>
+                          {
+                            new TextPart("new", TextPartType.Word, 0, 2),
+                            new TextPart("Ident", TextPartType.Word, 3, 7)
+                          }
+          },
+        new object[]
+          {
+            "new123Ident", new List<TextPart>
+                             {
+                               new TextPart("new", TextPartType.Word, 0, 2),
+                               new TextPart("123", TextPartType.NotAWord, 3, 5),
+                               new TextPart("Ident", TextPartType.Word, 6, 10)
+                             }
+          },
+        new object[]
+          {
+            "MyIdent", new List<TextPart>
+                         {
+                           new TextPart("My", TextPartType.Word, 0, 1),
+                           new TextPart("Ident", TextPartType.Word, 2, 6)
+                         }
+          },
+        new object[]
+          {
+            "My123", new List<TextPart>
+                       {
+                         new TextPart("My", TextPartType.Word, 0, 1),
+                         new TextPart("123", TextPartType.NotAWord, 2, 4)
+                       }
+          },
+        new object[] {"Ident", new List<TextPart> {new TextPart("Ident", TextPartType.Word, 0, 4)}},
+        new object[]
+          {
+            "my_ident", new List<TextPart>
+                          {
+                            new TextPart("my", TextPartType.Word, 0, 1),
+                            new TextPart("_", TextPartType.NotAWord, 2, 2),
+                            new TextPart("ident", TextPartType.Word, 3, 7)
+                          }
+          },
+        new object[]
+          {
+            "my_Ident", new List<TextPart>
+                          {
+                            new TextPart("my", TextPartType.Word, 0, 1),
+                            new TextPart("_", TextPartType.NotAWord, 2, 2),
+                            new TextPart("Ident", TextPartType.Word, 3, 7)
+                          }
+          },
+        new object[]
+          {
+            "CAPITAL_ONLY", new List<TextPart>
+                              {
+                                new TextPart("CAPITAL", TextPartType.Word, 0, 6),
+                                new TextPart("_", TextPartType.NotAWord, 7, 7),
+                                new TextPart("ONLY", TextPartType.Word, 8, 11)
+                              }
+          },
+        new object[]
+          {
+            "CAPITAL_andNotONLY", new List<TextPart>
+                                    {
+                                      new TextPart("CAPITAL", TextPartType.Word, 0, 6),
+                                      new TextPart("_", TextPartType.NotAWord, 7, 7),
+                                      new TextPart("and", TextPartType.Word, 8, 10),
+                                      new TextPart("Not", TextPartType.Word, 11, 13),
+                                      new TextPart("ONLY", TextPartType.Word, 14, 17)
+                                    }
+          },
+        new object[]
+          {
+            "FUCKText", new List<TextPart>
+                          {
+                            new TextPart("FUCK", TextPartType.Word, 0, 3),
+                            new TextPart("Text", TextPartType.Word, 4, 7)
+                          }
+          },
+        new object[]
+          {
+            "andFUCKText", new List<TextPart>
+                             {
+                               new TextPart("and", TextPartType.Word, 0, 2),
+                               new TextPart("FUCK", TextPartType.Word, 3, 6),
+                               new TextPart("Text", TextPartType.Word, 7, 10)
+                             }
+          },
+        new object[]
+          {
+            "some Text", new List<TextPart>
+                           {
+                             new TextPart("some", TextPartType.Word, 0, 3),
+                             new TextPart(" ", TextPartType.NotAWord, 4, 4),
+                             new TextPart("Text", TextPartType.Word, 5, 8)
+                           }
+          },
+        new object[]
+          {
+            "he won't do", new List<TextPart>
+                             {
+                               new TextPart("he", TextPartType.Word, 0, 1),
+                               new TextPart(" ", TextPartType.NotAWord, 2, 2),
+                               new TextPart("won't", TextPartType.Word, 3, 7),
+                               new TextPart(" ", TextPartType.NotAWord, 8, 8),
+                               new TextPart("do", TextPartType.Word, 9, 10)
+                             }
+          },
+        new object[]
+          {
+            "he won'", new List<TextPart>
+                         {
+                           new TextPart("he", TextPartType.Word, 0, 1),
+                           new TextPart(" ", TextPartType.NotAWord, 2, 2),
+                           new TextPart("won", TextPartType.Word, 3, 5),
+                           new TextPart("'", TextPartType.NotAWord, 6, 6)
+                         }
+          },
+        new object[]
+          {
+            "he 'won", new List<TextPart>
+                         {
+                           new TextPart("he", TextPartType.Word, 0, 1),
+                           new TextPart(" '", TextPartType.NotAWord, 2, 3),
+                           new TextPart("won", TextPartType.Word, 4, 6)
+                         }
+          }
+      };
+
+    [Test, TestCaseSource("Cases")]
+    public void TestTextSplitter(string text, List<TextPart> result)
+    {
+      List<TextPart> actual = TextSplitter.Split(text);
+      Assert.AreEqual(result, actual);
+    }
+  }
+}

ReSpeller.BasicTests/SuggestionGeneratorTest.cs

-using System;
-using System.Collections.Generic;
-using System.Linq;
-using NUnit.Framework;
-using ReSpeller.SpellEngine;
-using Rhino.Mocks;
-
-namespace ReSpeller.BasicTests
-{
-  /// <summary>
-  /// Summary description for SuggestionGeneratorTest
-  /// </summary>
-  [TestFixture]
-  public class SuggestionGeneratorTest
-  {
-    private readonly ISpellChecker myChecker;
-    private readonly SuggestionGenerator myGenerator;
-
-    public SuggestionGeneratorTest()
-    {
-      myChecker = MockRepository.GenerateStub<ISpellChecker>();
-      myGenerator = new SuggestionGenerator(myChecker);
-      Dictionary<string, string> suggests = new Dictionary<string, string>
-                                              {
-                                                {"idetnifier", "identifier verifier"},
-                                                {"Idetnifier", "identifier verifier"},
-                                                {"my", "my"},
-                                                {"My", "my"},
-                                                {"ixdent", "ident indent"},
-                                                {"Ixdent", "ident indent"},
-                                                {"Sufh", "such much"},
-                                                {"sufh", "such much"},
-                                                {"Fael", "fail fuel fall"},
-                                                {"fael", "fail fuel fall"},
-                                                {"Werd", "ward weird"},
-                                                {"werd", "ward weird"}
-                                              };
-      foreach (var suggest in suggests)
-      {
-        KeyValuePair<string, string> suggest1 = suggest;
-        myChecker.Stub(checker => checker.Suggestions(suggest1.Key)).Return(suggest1.Value.Split(' ').ToList());
-      }
-      Dictionary<string, bool> wordValidity = new Dictionary<string, bool>
-                                                {
-                                                  {"Idetnifier", false},
-                                                  {"idetnifier", false},
-                                                  {"ixdent", false},
-                                                  {"Ixdent", false},
-                                                  {"Sufh", false},
-                                                  {"sufh", false},
-                                                  {"my", true},
-                                                  {"My", true},
-                                                  {"Fael", false},
-                                                  {"Werd", false},
-                                                  {"best", true}
-                                                };
-      foreach (var pair in wordValidity)
-      {
-        KeyValuePair<string, bool> pair1 = pair;
-        myChecker.Stub(checker => checker.CheckWordSpelling(pair1.Key)).Return(pair1.Value);
-      }
-      myGenerator = new SuggestionGenerator(myChecker);
-    }
-
-    [Test]
-    [TestCase("myIdetnifier")]
-    [TestCase("myIdetnifier123Idetnifier")]
-    [TestCase("myIdetnifier123Ixdent")]
-    [TestCase("mySufh123Idetnifier")]
-    [TestCase("bestFaelWerd")]
-    public void SuggestsTest(string s)
-    {
-      var parts = TextSplitter.Split(s);
-      var variants = (from part in parts
-                     select part.Type == TextPartType.NotAWord || myChecker.CheckWordSpelling(part.Text) ?
-                          new List<string> { part.Text } : myChecker.Suggestions(part.Text).Where(s1 => s1.All(Char.IsLetter)).ToList()).
-                          ToList();
-      var expectedCount = variants.Aggregate(1, (i, list) => i * list.Count);
-      var suggests = myGenerator.Generate(s);
-      Assert.AreEqual(expectedCount, suggests.Count);
-    }
-  }
-}

ReSpeller/ReSpeller.csproj

     <Compile Include="Settings\ReSpellerSettingsControl.xaml.cs">
       <DependentUpon>ReSpellerSettingsControl.xaml</DependentUpon>
     </Compile>
+    <Compile Include="SpellEngine\Constants.cs" />
     <Compile Include="SpellEngine\Dictionaries\DictionaryFactory.cs" />
     <Compile Include="SpellEngine\Dictionaries\FileDictionaryStorage.cs" />
     <Compile Include="SpellEngine\Dictionaries\HunspellEngine.cs" />

ReSpeller/SpellEngine/Constants.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ReSpeller.SpellEngine
+{
+  static class Constants
+  {
+    public const string DictExt = "dic";
+    public const string InternalDictSuffix = "_custom";
+    public const string MainDictSubDir = "dic";
+    public const string UserDictSubDir = "ReSpeller";
+    public const string HunspellAffixExt = "aff";
+    public const string HunspellDictExt = "dic";
+  }
+}

ReSpeller/SpellEngine/Dictionaries/HunspellEngine.cs

 using System.Collections.Generic;
+using System.IO;
 using NHunspell;
 
 namespace ReSpeller.SpellEngine.Dictionaries
   {
     private readonly Hunspell myHunspell;
 
+    public static string NativeDllPath
+    {
+      get { return Hunspell.NativeDllPath; }
+      set { Hunspell.NativeDllPath = value; }
+    }
+
     public HunspellEngine(string affixFile, string dictFile)
     {
       myHunspell = new Hunspell(affixFile, dictFile);
       if (myHunspell != null && !myHunspell.IsDisposed)
         myHunspell.Dispose();
     }
+
+    public static HunspellEngine CreateForLanguage(string dictDir, string language)
+    {
+      string dictFile = Path.Combine(dictDir, language + "." + Constants.HunspellDictExt);
+      string affixFile = Path.Combine(dictDir, language + "." + Constants.HunspellAffixExt);
+      return new HunspellEngine(affixFile, dictFile);
+    }
   }
 }

ReSpeller/SpellEngine/Dictionaries/HunspellLanguageDictionary.cs

-using System.Collections.Generic;
-using System.IO;
-using Microsoft.Deployment.Compression;
-using NHunspell;
-
-namespace ReSpeller.SpellEngine.Dictionaries
-{
-  public class HunspellLanguageDictionary : ILanguageDictionary
-  {
-    private readonly string myLanguage;
-    private readonly IDictionaryEngine myEngine;
-    private const string HunspellAffixExt = "aff";
-    private const string HunspellDicExt = "dic";
-
-    public static string NativeDllPath
-    {
-      get { return Hunspell.NativeDllPath; }
-      set { Hunspell.NativeDllPath = value; }
-    }
-
-    public HunspellLanguageDictionary(string mainDictDir, string language)
-    {
-      if (string.IsNullOrEmpty(language))
-        throw new ArchiveException(language);
-      myLanguage = language;
-      string affixFile = Path.Combine(mainDictDir, language + "." + HunspellAffixExt);
-      string dictFile = Path.Combine(mainDictDir, language + "." + HunspellDicExt);
-      myEngine = new HunspellEngine(affixFile, dictFile);
-    }
-
-    public string Language
-    {
-      get { return myLanguage; }
-    }
-
-    public IDictionaryEngine Engine { get { return myEngine; } }
-
-    public bool Check(string word)
-    {
-      return myEngine.Check(word);
-    }
-
-    public List<string> Suggests(string word)
-    {
-      return myEngine.Suggest(word);
-    }
-
-    public void Dispose()
-    {
-      myEngine.Dispose();
-    }
-  }
-}

ReSpeller/SpellEngine/Dictionaries/UserInternalDictionary.cs

 
 namespace ReSpeller.SpellEngine.Dictionaries
 {
+  
   public class UserInternalDictionary : IUserInternalDictionary
   {
-    private const string DictExt = "dic";
-    private const string InternalDictSuffix = "_custom";
-    private readonly ILanguageDictionary myLanguageDictionary;
+    private readonly IDictionaryEngine myEngine;
+    private readonly string myLanguage;
     private readonly IDictionaryStorage myUserStorage;
     private readonly IDictionaryStorage myInternalStorage;
 
 
-    public UserInternalDictionary(ILanguageDictionary languageDictionary, string userDictDir, string internalDictDir)
+    public UserInternalDictionary(IDictionaryEngine engine, string language, IDictionaryStorage userStorage, IDictionaryStorage internalStorage)
     {
-      myLanguageDictionary = languageDictionary;
-      myUserStorage = new FileDictionaryStorage(Path.Combine(userDictDir, languageDictionary.Language + "." + DictExt));
-      myLanguageDictionary.Engine.AddRange(myUserStorage.GetContent());
-      myInternalStorage = new FileDictionaryStorage(Path.Combine(internalDictDir, 
-                                                                 languageDictionary.Language + InternalDictSuffix + "." + DictExt));
-      myLanguageDictionary.Engine.AddRange(myInternalStorage.GetContent());
+      myEngine = engine;
+      myLanguage = language;
+      myUserStorage = userStorage;
+      myInternalStorage = internalStorage;
+      myEngine.AddRange(myUserStorage.GetContent());    
+      myEngine.AddRange(myInternalStorage.GetContent());
     }
 
     public void Dispose()
     {
-      myLanguageDictionary.Dispose();
+      myEngine.Dispose();
     }
 
-    public string Language { get { return myLanguageDictionary.Language; } }
+    public string Language { get { return myLanguage; } }
 
-    public IDictionaryEngine Engine { get { return myLanguageDictionary.Engine; } }
+    public IDictionaryEngine Engine { get { return myEngine; } }
 
     public bool Check(string word)
     {
-      return myLanguageDictionary.Check(word);
+      return myEngine.Check(word);
     }
 
     public List<string> Suggests(string word)
     {
-      return myLanguageDictionary.Suggests(word);
+      return myEngine.Suggest(word);
     }
 
     public void AddToUserDict(string word)
     {
       myUserStorage.AddWord(word);
-      myLanguageDictionary.Engine.Add(word);
+      myEngine.Add(word);
     }
 
     public void AddToInternalDict(string word)
     {
       myInternalStorage.AddWord(word);
-      myLanguageDictionary.Engine.Add(word);
+      myEngine.Add(word);
     }
   }
 }

ReSpeller/SpellEngine/SpellChecker.cs

   public sealed class SpellChecker : IDisposable, ISpellChecker
   {
     private readonly IContextBoundSettingsStore myStore;
-    private const string MainDictSubDir = "dic";
-    private const string UserDictSubDir = "ReSpeller";
     private const string CurrentLanguage = "en_us";
 
     private readonly UserInternalDictionary myDictionary;
     public SpellChecker(ISettingsStore store)
     {
       myStore = store.BindToContextTransient(ContextRange.ApplicationWide);      
-      HunspellLanguageDictionary.NativeDllPath = myPluginPath;
-      string mainDictDir = Path.Combine(myPluginPath, MainDictSubDir);
-      string userDictDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), UserDictSubDir);
-      var dictionary = new HunspellLanguageDictionary(mainDictDir, CurrentLanguage);
-      myDictionary = new UserInternalDictionary(dictionary, userDictDir, mainDictDir);
+      HunspellEngine.NativeDllPath = myPluginPath;
+      string mainDictDir = Path.Combine(myPluginPath, Constants.MainDictSubDir);
+      string userDictDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Constants.UserDictSubDir);
+      //var dictionary = new HunspellLanguageDictionary(mainDictDir, CurrentLanguage);
+      var userStorage = new FileDictionaryStorage(Path.Combine(userDictDir, CurrentLanguage + "." + Constants.DictExt));
+      var internalStorage = new FileDictionaryStorage(Path.Combine(mainDictDir, CurrentLanguage + Constants.InternalDictSuffix + "." + Constants.DictExt));
+      HunspellEngine hunspellEngine = HunspellEngine.CreateForLanguage(mainDictDir, CurrentLanguage);
+      myDictionary = new UserInternalDictionary(hunspellEngine, CurrentLanguage, userStorage, internalStorage);
     }
 
     #region IDisposable Members