Implements useful methods.
Beispiel #1
0
        public void StoreDocument( )
        {
            MockRepository  mocks = new MockRepository( );
            IIndexConnector conn  = mocks.StrictMock <IIndexConnector>( );
            IDocument       doc   = mocks.StrictMock <IDocument>( );

            const string dummyState = "state";

            const string content = "This is some test content.";
            const string title   = "My Document";

            Expect.Call(doc.Title).Return(title).Repeat.AtLeastOnce( );
            Expect.Call(doc.Tokenize(content)).Return(Tools.Tokenize(content, WordLocation.Content));
            Expect.Call(doc.Tokenize(title)).Return(Tools.Tokenize(title, WordLocation.Title));

            Predicate <WordInfo[]> contentPredicate = array => array.Length == 5 &&
                                                      array[0].Text == "this" &&
                                                      array[1].Text == "is" &&
                                                      array[2].Text == "some" &&
                                                      array[3].Text == "test" &&
                                                      array[4].Text == "content";
            Predicate <WordInfo[]> titlePredicate = array => array.Length == 2 &&
                                                    array[0].Text == "my" &&
                                                    array[1].Text == "document";
            Predicate <WordInfo[]> keywordsPredicate = array => array.Length == 1 &&
                                                       array[0].Text == "test";

            conn.DeleteDataForDocument(doc, dummyState);
            LastCall.On(conn);
            Expect.Call(conn.SaveDataForDocument(null, null, null, null, null)).IgnoreArguments( )
            .Constraints(Is.Same(doc), Is.Matching(contentPredicate), Is.Matching(titlePredicate), Is.Matching(keywordsPredicate), Is.Same(dummyState))
            .Return(8);

            mocks.ReplayAll( );

            SqlIndex index = new SqlIndex(conn);

            Assert.AreEqual(8, index.StoreDocument(doc, new[] { "test" }, content, dummyState), "Wrong occurrence count");

            mocks.VerifyAll( );
        }