public void NonQuotedTokenizedPhrasesSplitCorrectly() { // Mock the context for the object IInputContext context = DnaMockery.CurrentMockery.NewMock<IInputContext>(); Stub.On(context).Method("GetSiteOptionValueString").With("KeyPhrases", "DelimiterToken").Will(Return.Value(",")); // Create an instance of the class to test NamespacePhrases nsp = new NamespacePhrases(context); // Set up the phrases and namespace to test against string phrases = "one,two,three,four and a bit"; string namespaces = "test"; // Create a list of tokenized namespaced phrases to test List<TokenizedNamespacedPhrases> phrasesToTest = new List<TokenizedNamespacedPhrases>(); phrasesToTest.Add(new TokenizedNamespacedPhrases(namespaces, phrases)); // Now try to parse the list List<Phrase> parsedPrases = nsp.ParseTokenizedPhrases(phrasesToTest); Assert.AreEqual(4, parsedPrases.Count); Assert.AreEqual("one", parsedPrases[0].PhraseName); Assert.AreEqual("two", parsedPrases[1].PhraseName); Assert.AreEqual("three", parsedPrases[2].PhraseName); Assert.AreEqual("four and a bit", parsedPrases[3].PhraseName); Assert.AreEqual("test", parsedPrases[0].NameSpace); Assert.AreEqual("test", parsedPrases[1].NameSpace); Assert.AreEqual("test", parsedPrases[2].NameSpace); Assert.AreEqual("test", parsedPrases[3].NameSpace); }
/// <summary> /// Adds key phrases to the article from the users input /// </summary> /// <param name="h2g2ID">The h2g2 id of the article you want to add the key phrases to</param> private void AddKeyPhrasesToArticle(int h2g2ID) { // Now go through the fields getting all the ones marked as keyphrases string delimiter = NamespacePhrases.GetSiteDelimiterToken(InputContext); Dictionary<string, UIField>.Enumerator fields = _template.UIFields.GetEnumerator(); List<TokenizedNamespacedPhrases> phrasesToParse = new List<TokenizedNamespacedPhrases>(); while (fields.MoveNext()) { UIField field = fields.Current.Value; if (field.IsKeyPhrase) { // Add the phrase to the list phrasesToParse.Add(new TokenizedNamespacedPhrases(field.KeyPhraseNamespace, field.RawValue, delimiter)); } } // Did we have anything? if (phrasesToParse.Count > 0) { // Try to parse the string to get a list of phrases NamespacePhrases nsPhrases = new NamespacePhrases(InputContext); nsPhrases.AddNameSpacePhrasesToArticle(phrasesToParse, h2g2ID); } }