Ejemplo n.º 1
0
        public void Add_Item_Null()
        {
            WordInfoCollection sut = new WordInfoCollection();
            var ex = Assert.Throws <ArgumentNullException>(() => sut.Add(null));

            Assert.Equal("Value cannot be null.\r\nParameter name: item", ex.Message);
        }
Ejemplo n.º 2
0
        public void Constructor_WithCapacity()
        {
            WordInfoCollection sut = new WordInfoCollection(15);

            Assert.Empty(sut);
            Assert.Equal(15, sut.Capacity);
        }
Ejemplo n.º 3
0
        public void CopyTo()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("continuous", 0, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("goose", 34, 0, WordLocation.Content);

            collection.Add(mi1);
            collection.Add(mi2);

            WordInfo[] matches = new WordInfo[2];
            collection.CopyTo(matches, 0);

            Assert.AreEqual(mi1, matches[0], "Wrong match item");
            Assert.AreEqual(mi2, matches[1], "Wrong match item");

            matches = new WordInfo[3];
            collection.CopyTo(matches, 0);

            Assert.AreEqual(mi1, matches[0], "Wrong match item");
            Assert.AreEqual(mi2, matches[1], "Wrong match item");
            Assert.IsNull(matches[2], "Non-null item");

            matches = new WordInfo[3];
            collection.CopyTo(matches, 1);

            Assert.IsNull(matches[0], "Non-null item");
            Assert.AreEqual(mi1, matches[1], "Wrong match item");
            Assert.AreEqual(mi2, matches[2], "Wrong match item");
        }
Ejemplo n.º 4
0
        public void CopyTo_Array_Null()
        {
            WordInfoCollection sut = new WordInfoCollection();
            var ex = Assert.Throws <ArgumentNullException>(() => sut.CopyTo(null, 0));

            Assert.Equal("Value cannot be null.\r\nParameter name: array", ex.Message);
        }
Ejemplo n.º 5
0
        public void CopyTo()
        {
            WordInfoCollection sut = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("continuous", 0, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("goose", 34, 0, WordLocation.Content);

            sut.Add(mi1);
            sut.Add(mi2);

            WordInfo[] matches = new WordInfo[2];
            sut.CopyTo(matches, 0);

            Assert.Equal(mi1, matches[0]);
            Assert.Equal(mi2, matches[1]);

            matches = new WordInfo[3];
            sut.CopyTo(matches, 0);

            Assert.Equal(mi1, matches[0]);
            Assert.Equal(mi2, matches[1]);
            Assert.Null(matches[2]);

            matches = new WordInfo[3];
            sut.CopyTo(matches, 1);

            Assert.Null(matches[0]);
            Assert.Equal(mi1, matches[1]);
            Assert.Equal(mi2, matches[2]);
        }
Ejemplo n.º 6
0
        public void Constructor_WithCapacity()
        {
            WordInfoCollection collection = new WordInfoCollection(15);

            Assert.AreEqual(0, collection.Count, "Wrong count (collection should be empty)");
            Assert.AreEqual(15, collection.Capacity, "Wrong capacity");
        }
Ejemplo n.º 7
0
        public void GetEnumerator()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("goose", 1, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("hello", 12, 0, WordLocation.Content);

            collection.Add(mi2);
            collection.Add(mi1);

            int count = 0;

            foreach (WordInfo r in collection)
            {
                if (count == 0)
                {
                    Assert.Equal(mi1, r);
                }
                if (count == 1)
                {
                    Assert.Equal(mi2, r);
                }
                count++;
            }
            Assert.Equal(2, count);
        }
Ejemplo n.º 8
0
        public void GetEnumerator()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("goose", 1, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("hello", 12, 0, WordLocation.Content);

            collection.Add(mi2);
            collection.Add(mi1);

            int count = 0;

            foreach (WordInfo r in collection)
            {
                if (count == 0)
                {
                    Assert.AreEqual(mi1, r, "Wrong item at position 0");
                }

                if (count == 1)
                {
                    Assert.AreEqual(mi2, r, "Wrong item at position 1");
                }

                count++;
            }
            Assert.AreEqual(2, count, "Wrong count - enumerator does not work");
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SearchResult" /> class.
        /// </summary>
        /// <param name="document">The document the result refers to.</param>
        /// <remarks>The relevance is initially set to <b>0</b>.</remarks>
        /// <exception cref="ArgumentNullException">If <paramref name="document"/> is <c>null</c>.</exception>
        public SearchResult(IDocument document)
        {
            if(document == null) throw new ArgumentNullException("document");

            this.document = document;
            this.matches = new WordInfoCollection();
            this.relevance = new Relevance(0);
        }
Ejemplo n.º 10
0
        public void CopyTo_InvalidIndex_TooBig()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo[] results = new WordInfo[10];

            collection.CopyTo(results, 10);
        }
Ejemplo n.º 11
0
        public void CopyTo_InvalidIndex_Negative()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo[] results = new WordInfo[10];

            collection.CopyTo(results, -1);
        }
Ejemplo n.º 12
0
        public void CopyTo_InvalidIndex_TooBig()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo[] results = new WordInfo[10];

            Assert.Throws <ArgumentOutOfRangeException>(() => collection.CopyTo(results, 10));
        }
Ejemplo n.º 13
0
        public void Indexer_Index_TooBig()
        {
            WordInfoCollection sut = new WordInfoCollection();

            var ex = Assert.Throws <IndexOutOfRangeException>(() => sut[1]);

            Assert.Equal("Index should be greater than or equal to zero and less than the number of items in the collection.", ex.Message);
        }
Ejemplo n.º 14
0
        public void CopyTo_Index_TooBig()
        {
            WordInfoCollection sut = new WordInfoCollection();

            WordInfo[] results = new WordInfo[10];

            var ex = Assert.Throws <ArgumentOutOfRangeException>(() => sut.CopyTo(results, 10));

            Assert.Equal("Index should be greater than or equal to zero and less than the number of items in the array.\r\nParameter name: arrayIndex", ex.Message);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Gets the formatted page excerpt.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="matches">The matches to highlight.</param>
        /// <returns>The excerpt.</returns>
        private static string GetExcerpt(PageInfo page, WordInfoCollection matches)
        {
            PageContent pageContent = Content.GetPageContent(page, true);
            string      content     = pageContent.Content;

            List <WordInfo> sortedMatches = new List <WordInfo>(matches);

            sortedMatches.RemoveAll(delegate(WordInfo wi) { return(wi.Location != WordLocation.Content); });
            sortedMatches.Sort(delegate(WordInfo x, WordInfo y) { return(x.FirstCharIndex.CompareTo(y.FirstCharIndex)); });

            return(BuildFormattedExcerpt(sortedMatches, Host.Instance.PrepareContentForIndexing(page, content)));
        }
Ejemplo n.º 16
0
        public void Indexer()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("taskbar", 1, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("goose", 12, 0, WordLocation.Content);

            collection.Add(mi2);
            collection.Add(mi1);

            Assert.Equal(mi1, collection[0]);
            Assert.Equal(mi2, collection[1]);
        }
Ejemplo n.º 17
0
        public void Remove()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("goose", 1, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("hello", 12, 0, WordLocation.Content);

            collection.Add(mi1);
            Assert.IsTrue(collection.Contains(mi1), "Collection should contain item");
            Assert.IsFalse(collection.Contains(mi2), "Collection should not contain item");

            Assert.IsFalse(collection.Contains(null as WordInfo), "Contains should return false");
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Gets the formatted message excerpt.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="messageID">The message ID.</param>
        /// <param name="matches">The matches to highlight.</param>
        /// <returns>The excerpt.</returns>
        private static string GetExcerpt(PageInfo page, int messageID, WordInfoCollection matches)
        {
            Message message = Pages.FindMessage(Pages.GetPageMessages(page), messageID);

            string content = message.Body;

            List <WordInfo> sortedMatches = new List <WordInfo>(matches);

            sortedMatches.RemoveAll(delegate(WordInfo wi) { return(wi.Location != WordLocation.Content); });
            sortedMatches.Sort(delegate(WordInfo x, WordInfo y) { return(x.FirstCharIndex.CompareTo(y.FirstCharIndex)); });

            return(BuildFormattedExcerpt(sortedMatches, Host.Instance.PrepareContentForIndexing(null, content)));
        }
Ejemplo n.º 19
0
        public void Indexer()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("taskbar", 1, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("goose", 12, 0, WordLocation.Content);

            collection.Add(mi2);
            collection.Add(mi1);

            Assert.AreEqual(mi1, collection[0], "Wrong item at position 0");
            Assert.AreEqual(mi2, collection[1], "Wrong item at position 0");
        }
Ejemplo n.º 20
0
        public void AddAndCount()
        {
            var collection = new WordInfoCollection();

            var mi1 = new WordInfo("continuous", 0, 0, WordLocation.Content);
            var mi2 = new WordInfo("taskbar", 21, 1, WordLocation.Content);

            Assert.AreEqual(0, collection.Count, "Wrong count (collection should be empty)");
            collection.Add(mi2);
            collection.Add(mi1);
            Assert.AreEqual(2, collection.Count, "Wrong count (collection should contain 2 items)");
            Assert.AreEqual(mi1, collection[0], "Wrong item at index 0");
            Assert.AreEqual(mi2, collection[1], "Wrong item at index 1");
        }
Ejemplo n.º 21
0
        public void CopyTo_ArrayTooSmall()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("home", 0, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("taskbar", 100, 0, WordLocation.Content);

            collection.Add(mi1);
            collection.Add(mi2);

            WordInfo[] matches = new WordInfo[1];

            collection.CopyTo(matches, 0);
        }
Ejemplo n.º 22
0
        public void Contains_WordInfo()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("continuous", 0, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("taskbar", 21, 0, WordLocation.Content);

            collection.Add(mi1);

            Assert.IsTrue(collection.Contains(mi1), "Collection should contain item");
            Assert.IsFalse(collection.Contains(mi2), "Collection should not contain item");

            Assert.IsFalse(collection.Contains(null as WordInfo), "Contains should return false");
        }
Ejemplo n.º 23
0
        public void CopyTo_NoSpaceAtIndex()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("home", 0, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("taskbar", 100, 0, WordLocation.Content);

            collection.Add(mi1);
            collection.Add(mi2);

            WordInfo[] matches = new WordInfo[2];

            collection.CopyTo(matches, 1);
        }
Ejemplo n.º 24
0
        public void Clear()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("continuous", 0, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("taskbar", 21, 1, WordLocation.Content);

            collection.Add(mi1);
            collection.Add(mi2);
            Assert.AreEqual(2, collection.Count, "Wrong count (collection should contain 2 items)");

            collection.Clear();
            Assert.AreEqual(0, collection.Count, "Wrong count (collection should be empty)");
        }
Ejemplo n.º 25
0
        public void Clear()
        {
            WordInfoCollection sut = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("continuous", 0, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("taskbar", 21, 1, WordLocation.Content);

            sut.Add(mi1);
            sut.Add(mi2);
            Assert.Equal(2, sut.Count);

            sut.Clear();
            Assert.Empty(sut);
        }
Ejemplo n.º 26
0
        public void Contains_String()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("continuous", 0, 0, WordLocation.Content);

            collection.Add(mi1);

            Assert.IsTrue(collection.Contains("continuous"), "Collection should contain string");
            Assert.IsFalse(collection.Contains("taskbar"), "Collection should not contain string");

            Assert.IsFalse(collection.Contains(null as string), "Contains should return false");
            Assert.IsFalse(collection.Contains(""), "Contains should return false");
        }
Ejemplo n.º 27
0
        public void Clear()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("continuous", 0, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("taskbar", 21, 1, WordLocation.Content);

            collection.Add(mi1);
            collection.Add(mi2);
            Assert.AreEqual(2, collection.Count, "Wrong count (collection should contain 2 items)");

            collection.Clear();
            Assert.AreEqual(0, collection.Count, "Wrong count (collection should be empty)");
        }
Ejemplo n.º 28
0
        public void CopyTo_NoSpaceAtIndex()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("home", 0, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("taskbar", 100, 0, WordLocation.Content);

            collection.Add(mi1);
            collection.Add(mi2);

            WordInfo[] matches = new WordInfo[2];

            Assert.Throws <ArgumentOutOfRangeException>(() => collection.CopyTo(matches, 1));
        }
Ejemplo n.º 29
0
        public void CopyTo_Index_TooSmall()
        {
            WordInfoCollection sut = new WordInfoCollection();
            WordInfo           mi1 = new WordInfo("home", 0, 0, WordLocation.Content);
            WordInfo           mi2 = new WordInfo("taskbar", 100, 0, WordLocation.Content);

            sut.Add(mi1);
            sut.Add(mi2);

            WordInfo[] matches = new WordInfo[1];

            var ex = Assert.Throws <ArgumentOutOfRangeException>(() => sut.CopyTo(matches, 0));

            Assert.Equal("Not enough space for copying the items starting at the specified index.\r\nParameter name: arrayIndex", ex.Message);
        }
Ejemplo n.º 30
0
        public void ContainsOccurrence()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("continuous", 7, 0, WordLocation.Content);

            collection.Add(mi1);

            Assert.IsTrue(collection.ContainsOccurrence("continuous", 7), "Collection should contain occurrence");
            Assert.IsFalse(collection.ContainsOccurrence("continuous2", 7), "Collection should not contain occurrence");
            Assert.IsFalse(collection.ContainsOccurrence("continuous", 6), "Collection should not contain occurrence");
            Assert.IsFalse(collection.ContainsOccurrence("continuous", 8), "Collection should not contain occurrence");
            Assert.IsFalse(collection.ContainsOccurrence("continuous2", 6), "Collection should not contain occurrence");

            Assert.IsFalse(collection.ContainsOccurrence("continuous2", -1), "Contains should return false");
            Assert.IsFalse(collection.ContainsOccurrence("", 7), "Contains should return false");
            Assert.IsFalse(collection.ContainsOccurrence(null, 7), "Contains should return false");
        }
Ejemplo n.º 31
0
        public void ContainsOccurrence()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("continuous", 7, 0, WordLocation.Content);

            collection.Add(mi1);

            Assert.IsTrue(collection.ContainsOccurrence("continuous", 7), "Collection should contain occurrence");
            Assert.IsFalse(collection.ContainsOccurrence("continuous2", 7), "Collection should not contain occurrence");
            Assert.IsFalse(collection.ContainsOccurrence("continuous", 6), "Collection should not contain occurrence");
            Assert.IsFalse(collection.ContainsOccurrence("continuous", 8), "Collection should not contain occurrence");
            Assert.IsFalse(collection.ContainsOccurrence("continuous2", 6), "Collection should not contain occurrence");

            Assert.IsFalse(collection.ContainsOccurrence("continuous2", -1), "Contains should return false");
            Assert.IsFalse(collection.ContainsOccurrence("", 7), "Contains should return false");
            Assert.IsFalse(collection.ContainsOccurrence(null, 7), "Contains should return false");
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Gets a list of keywords formatted for the query string.
        /// </summary>
        /// <param name="matches">The search keywords.</param>
        /// <returns>The formatted list, for example 'word1,word2,word3'.</returns>
        private static string GetKeywordsForQueryString(WordInfoCollection matches)
        {
            StringBuilder buffer = new StringBuilder(100);
            List <string> added  = new List <string>(5);

            for (int i = 0; i < matches.Count; i++)
            {
                if (matches[i].Text.Length > 1 && !added.Contains(matches[i].Text))
                {
                    buffer.Append(Tools.UrlEncode(matches[i].Text));
                    if (i != matches.Count - 1)
                    {
                        buffer.Append(",");
                    }
                    added.Add(matches[i].Text);
                }
            }

            return(buffer.ToString().TrimEnd(','));
        }
Ejemplo n.º 33
0
 public void Add_NullItem()
 {
     WordInfoCollection collection = new WordInfoCollection();
     collection.Add(null);
 }
Ejemplo n.º 34
0
        public void Remove()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("goose", 1, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("hello", 12, 0, WordLocation.Content);

            collection.Add(mi1);
            Assert.IsTrue(collection.Contains(mi1), "Collection should contain item");
            Assert.IsFalse(collection.Contains(mi2), "Collection should not contain item");

            Assert.IsFalse(collection.Contains(null as WordInfo), "Contains should return false");
        }
Ejemplo n.º 35
0
 public void Remove_NullItem()
 {
     WordInfoCollection collection = new WordInfoCollection();
     collection.Remove(null);
 }
Ejemplo n.º 36
0
 public void Indexer_InvalidIndex_TooBig()
 {
     WordInfoCollection collection = new WordInfoCollection();
     WordInfo mi = collection[0];
 }
Ejemplo n.º 37
0
 public void ReadOnly()
 {
     WordInfoCollection collection = new WordInfoCollection();
     Assert.IsFalse(collection.IsReadOnly, "Collection should not be read-only");
 }
Ejemplo n.º 38
0
 public void Constructor_WithCapacity()
 {
     WordInfoCollection collection = new WordInfoCollection(15);
     Assert.AreEqual(0, collection.Count, "Wrong count (collection should be empty)");
     Assert.AreEqual(15, collection.Capacity, "Wrong capacity");
 }
Ejemplo n.º 39
0
        public void Contains_WordInfo()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("continuous", 0, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("taskbar", 21, 0, WordLocation.Content);

            collection.Add(mi1);

            Assert.IsTrue(collection.Contains(mi1), "Collection should contain item");
            Assert.IsFalse(collection.Contains(mi2), "Collection should not contain item");

            Assert.IsFalse(collection.Contains(null as WordInfo), "Contains should return false");
        }
Ejemplo n.º 40
0
        public void CopyTo_NullArray()
        {
            WordInfoCollection collection = new WordInfoCollection();

            collection.CopyTo(null, 0);
        }
Ejemplo n.º 41
0
        public void GetEnumerator()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("goose", 1, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("hello", 12, 0, WordLocation.Content);

            collection.Add(mi2);
            collection.Add(mi1);

            int count = 0;
            foreach(WordInfo r in collection) {
                if(count == 0) Assert.AreEqual(mi1, r, "Wrong item at position 0");
                if(count == 1) Assert.AreEqual(mi2, r, "Wrong item at position 1");
                count++;
            }
            Assert.AreEqual(2, count, "Wrong count - enumerator does not work");
        }
Ejemplo n.º 42
0
        public void Contains_String()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("continuous", 0, 0, WordLocation.Content);

            collection.Add(mi1);

            Assert.IsTrue(collection.Contains("continuous"), "Collection should contain string");
            Assert.IsFalse(collection.Contains("taskbar"), "Collection should not contain string");

            Assert.IsFalse(collection.Contains(null as string), "Contains should return false");
            Assert.IsFalse(collection.Contains(""), "Contains should return false");
        }
Ejemplo n.º 43
0
        /// <summary>
        /// Gets the formatted message excerpt.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="messageID">The message ID.</param>
        /// <param name="matches">The matches to highlight.</param>
        /// <returns>The excerpt.</returns>
        private static string GetExcerpt(PageInfo page, int messageID, WordInfoCollection matches)
        {
            Message message = Pages.FindMessage(Pages.GetPageMessages(page), messageID);

            string content = message.Body;

            List<WordInfo> sortedMatches = new List<WordInfo>(matches);
            sortedMatches.RemoveAll(delegate(WordInfo wi) { return wi.Location != WordLocation.Content; });
            sortedMatches.Sort(delegate(WordInfo x, WordInfo y) { return x.FirstCharIndex.CompareTo(y.FirstCharIndex); });

            return BuildFormattedExcerpt(sortedMatches, Host.Instance.PrepareContentForIndexing(null, content));
        }
Ejemplo n.º 44
0
        public void CopyTo_InvalidIndex_Negative()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo[] results = new WordInfo[10];

            collection.CopyTo(results, -1);
        }
Ejemplo n.º 45
0
        /// <summary>
        /// Gets the formatted page excerpt.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="matches">The matches to highlight.</param>
        /// <returns>The excerpt.</returns>
        private static string GetExcerpt(PageInfo page, WordInfoCollection matches)
        {
            PageContent pageContent = Content.GetPageContent(page, true);
            string content = pageContent.Content;

            List<WordInfo> sortedMatches = new List<WordInfo>(matches);
            sortedMatches.RemoveAll(delegate(WordInfo wi) { return wi.Location != WordLocation.Content; });
            sortedMatches.Sort(delegate(WordInfo x, WordInfo y) { return x.FirstCharIndex.CompareTo(y.FirstCharIndex); });

            return BuildFormattedExcerpt(sortedMatches, Host.Instance.PrepareContentForIndexing(page, content));
        }
Ejemplo n.º 46
0
        public void CopyTo()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("continuous", 0, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("goose", 34, 0, WordLocation.Content);

            collection.Add(mi1);
            collection.Add(mi2);

            WordInfo[] matches = new WordInfo[2];
            collection.CopyTo(matches, 0);

            Assert.AreEqual(mi1, matches[0], "Wrong match item");
            Assert.AreEqual(mi2, matches[1], "Wrong match item");

            matches = new WordInfo[3];
            collection.CopyTo(matches, 0);

            Assert.AreEqual(mi1, matches[0], "Wrong match item");
            Assert.AreEqual(mi2, matches[1], "Wrong match item");
            Assert.IsNull(matches[2], "Non-null item");

            matches = new WordInfo[3];
            collection.CopyTo(matches, 1);

            Assert.IsNull(matches[0], "Non-null item");
            Assert.AreEqual(mi1, matches[1], "Wrong match item");
            Assert.AreEqual(mi2, matches[2], "Wrong match item");
        }
Ejemplo n.º 47
0
        /// <summary>
        /// Gets a list of keywords formatted for the query string.
        /// </summary>
        /// <param name="matches">The search keywords.</param>
        /// <returns>The formatted list, for example 'word1,word2,word3'.</returns>
        private static string GetKeywordsForQueryString(WordInfoCollection matches)
        {
            StringBuilder buffer = new StringBuilder(100);
            List<string> added = new List<string>(5);

            for(int i = 0; i < matches.Count; i++) {
                if(matches[i].Text.Length > 1 && !added.Contains(matches[i].Text)) {
                    buffer.Append(Tools.UrlEncode(matches[i].Text));
                    if(i != matches.Count - 1) buffer.Append(",");
                    added.Add(matches[i].Text);
                }
            }

            return buffer.ToString().TrimEnd(',');
        }
Ejemplo n.º 48
0
        public void Indexer()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("taskbar", 1, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("goose", 12, 0, WordLocation.Content);

            collection.Add(mi2);
            collection.Add(mi1);

            Assert.AreEqual(mi1, collection[0], "Wrong item at position 0");
            Assert.AreEqual(mi2, collection[1], "Wrong item at position 0");
        }
Ejemplo n.º 49
0
 public void Constructor_InvalidCapacity()
 {
     WordInfoCollection collection = new WordInfoCollection(0);
 }
Ejemplo n.º 50
0
 public void Indexer_InvalidIndex_Negative()
 {
     WordInfoCollection collection = new WordInfoCollection();
     WordInfo mi = collection[-1];
 }
Ejemplo n.º 51
0
        public void CopyTo_InvalidIndex_TooBig()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo[] results = new WordInfo[10];

            collection.CopyTo(results, 10);
        }
Ejemplo n.º 52
0
        public void Add_NullItem()
        {
            WordInfoCollection collection = new WordInfoCollection();

            Assert.That(() => collection.Add(null), Throws.ArgumentNullException);
        }
Ejemplo n.º 53
0
        public void CopyTo_ArrayTooSmall()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("home", 0, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("taskbar", 100, 0, WordLocation.Content);

            collection.Add(mi1);
            collection.Add(mi2);

            WordInfo[] matches = new WordInfo[1];

            collection.CopyTo(matches, 0);
        }
Ejemplo n.º 54
0
        public void CopyTo_NoSpaceAtIndex()
        {
            WordInfoCollection collection = new WordInfoCollection();

            WordInfo mi1 = new WordInfo("home", 0, 0, WordLocation.Content);
            WordInfo mi2 = new WordInfo("taskbar", 100, 0, WordLocation.Content);

            collection.Add(mi1);
            collection.Add(mi2);

            WordInfo[] matches = new WordInfo[2];

            collection.CopyTo(matches, 1);
        }