public void TraceFunction() { var list = new System.Collections.Generic.List <string>(); using (NHunspellWrapper wrap = new NHunspellWrapper()) { wrap.LogAction = (x, y) => { if (x == typeof(MockSpeller)) { list.Add(y); } }; wrap.OverrideType = typeof(MockSpeller).AssemblyQualifiedName; wrap.Load(this.affixFile, this.dictFile); wrap.Spell("test"); wrap.Add("test"); } Assert.AreEqual(4, list.Count, string.Join(Environment.NewLine, list.ToArray())); Assert.IsTrue(list.Contains("Init")); Assert.IsTrue(list.Contains("Spell")); Assert.IsTrue(list.Contains("Add")); Assert.IsTrue(list.Contains("Free")); }
/// <summary> /// Run the wrapper through some tests /// </summary> /// <param name='wrap'>Wrapper to test</param> private static void Test(NHunspellWrapper wrap) { if (wrap.Spell("notaword")) { Assert.Fail("notaword should not be considered spelled correctly"); } // It was cached, no change wrap.Add("notaword"); if (wrap.Spell("notaword")) { Assert.Fail("notaword should not be considered spelled correctly"); } // Clearing the cache wrap.Clear(); if (!wrap.Spell("notaword")) { Assert.Fail("notaword should be considered spelled correctly"); } if (!wrap.Spell("word")) { Assert.Fail("word should be considered spelled correctly"); } // Set as valid and test after wrap.Add("notaword2"); if (!wrap.Spell("notaword2")) { Assert.Fail("notaword2 should be considered spelled correctly"); } if (wrap.IsDisposed) { Assert.Fail("Wrapper shouldn't be disposed yet"); } string test = string.Empty; wrap.LogAction = (x, y) => { test = "done"; }; wrap.LogAction.Invoke(typeof(WrapperTests), "done"); if (test != "done") { Assert.Fail("Unable to change logger, value was " + test); } test = null; wrap.LogAction = null; wrap.LogAction.Invoke(typeof(WrapperTests), "done"); if (test != null) { Assert.Fail("Value should not have been set"); } if (wrap.Spell("flushCacheTest")) { Assert.Fail("flushCacheTest should not be considered spelled correctly"); } if (wrap.DisableCache) { Assert.Fail("Cache should not be disabled"); } // Limit the cache size, check the word is still not valid wrap.CacheSize = 1; wrap.Add("flushCacheTest"); if (!wrap.Spell("flushCacheTest")) { Assert.Fail("flushCacheTest should be considered spelled correctly"); } if (!wrap.DisableCache) { Assert.Fail("Cache should be disabled"); } wrap.DisableCache = false; if (wrap.DisableCache) { Assert.Fail("Cache should not be disabled"); } wrap.DisableCache = true; if (!wrap.DisableCache) { Assert.Fail("Cache should be disabled"); } }
public void TraceFunctionAttached() { var list = new System.Collections.Generic.List<string>(); Log log = (x, y) => { if (x == typeof(MockSpeller)) { list.Add(y); } }; using (NHunspellWrapper wrap = new NHunspellWrapper(this.affixFile, this.dictFile, typeof(MockSpeller).AssemblyQualifiedName, log)) { wrap.Spell("test"); wrap.Add("test"); } Assert.AreEqual(4, list.Count, string.Join(Environment.NewLine, list.ToArray())); Assert.IsTrue(list.Contains("Init")); Assert.IsTrue(list.Contains("Spell")); Assert.IsTrue(list.Contains("Add")); Assert.IsTrue(list.Contains("Free")); }