public void Constructor_PassValidArguments_CopyValues() { using (ConnectionBase connection = new ConnectionMock()) { string[] documents = new string[] { "doc 1", "doc 2", "doc 3" }; string[] keywords = new string[] { "keyword1", "keyword2" }; string index = "test"; BuildExcerptsCommand target = new BuildExcerptsCommand(connection, documents, keywords, index); target.Documents.Should().Have.SameValuesAs(documents); target.Keywords.Should().Have.SameValuesAs(keywords); target.Index.Should().Be.EqualTo(index); } }
public void DeserializeResponseTest() { using (ConnectionMock connection = new ConnectionMock("test")) { bool deserializeCalled = false; BuildExcerptsCommand target = new BuildExcerptsCommand(connection); var accessor = GetCommandAccessor(target); IBinaryReader arrayReader = new ArrayListReaderMock(new ArrayList()); accessor.Result = new MBuildExcerptsCommandResult { DeserializeIBinaryReaderInt32 = (reader, count) => { deserializeCalled = (reader == arrayReader && count == 1); } }; target.Documents.Add("test"); accessor.DeserializeResponse(arrayReader); Assert.IsTrue(deserializeCalled); } }
public void SerializeRequestTest() { using (ConnectionMock connection = new ConnectionMock("test")) { BuildExcerptsCommand target = new BuildExcerptsCommand(connection); var accessor = GetCommandAccessor(target); ArrayList values = new ArrayList(); IBinaryWriter writer = new ArrayListWriterMock(values); accessor.SerializeRequest(writer); Assert.AreEqual(values.Count, 15); Assert.AreEqual(values[0], BuildExcerptsCommand_Accessor.MODE); Assert.AreEqual(values[1], (int)target.Options); Assert.AreEqual(values[2], target.Index); // Keywords skipped, will be tested in unit-test for StringList class Assert.AreEqual(values[4], target.BeforeMatch); Assert.AreEqual(values[5], target.AfterMatch); Assert.AreEqual(values[6], target.SnippetsDelimiter); Assert.AreEqual(values[7], target.SnippetSizeLimit); Assert.AreEqual(values[8], target.WordsAroundKeyword); Assert.AreEqual(values[9], target.SnippetsCountLimit); Assert.AreEqual(values[10], target.WordsCountLimit); Assert.AreEqual(values[11], target.StartPassageId); Assert.AreEqual(values[12], target.HtmlStripMode.ToString().ToLowerInvariant()); Assert.AreEqual(values[13], target.PassageBoundary.ToString().ToLowerInvariant()); // Documents skipped, for same reason } }
public void ExecuteTest_EmptyIndex_ThrowsException() { using (ConnectionMock connection = new ConnectionMock("test")) { connection.SkipHandshake = true; connection.SkipDeserializeCommand = true; connection.SkipSerializeCommand = true; BuildExcerptsCommand target = new BuildExcerptsCommand(connection); target.Documents.Add("test doc content"); target.Keywords.Add("test"); Executing.This(target.Execute).Should().Throw<ArgumentException>(); target.Index = "test"; Executing.This(target.Execute).Should().NotThrow(); } }
public void CommandInfoTest() { using (ConnectionMock connection = new ConnectionMock("test")) { BuildExcerptsCommand target = new BuildExcerptsCommand(connection); BuildExcerptsCommand_Accessor accessor = GetCommandAccessor(target); Assert.IsNotNull(accessor.CommandInfo); Assert.AreEqual(accessor.CommandInfo.Id, ServerCommand.Excerpt); Assert.AreEqual(accessor.CommandInfo.Version, BuildExcerptsCommand_Accessor.COMMAND_VERSION); } }
public void DocumentsTest() { using (ConnectionMock connection = new ConnectionMock("test")) { BuildExcerptsCommand target = new BuildExcerptsCommand(connection); Assert.IsNotNull(target.Documents); Assert.IsInstanceOfType(target.Documents, typeof (IList<string>)); } }
public void IndexTest() { using (ConnectionBase connection = new ConnectionMock()) { BuildExcerptsCommand target = new BuildExcerptsCommand(connection); // default value Assert.AreEqual(target.Index, null); // valid value string expected = "test"; target.Index = expected; Assert.AreEqual(expected, target.Index); // invalid value target.Index = null; } }
public void WordsAroundKeywordTest() { using (ConnectionBase connection = new ConnectionMock()) { BuildExcerptsCommand target = new BuildExcerptsCommand(connection); // default value Assert.AreEqual(target.WordsAroundKeyword, BuildExcerptsCommand_Accessor.DEFAULT_WORDS_AROUND_KEYWORD); // valid value int expected = 0; target.WordsAroundKeyword = expected; Assert.AreEqual(expected, target.WordsAroundKeyword); // invalid value target.WordsAroundKeyword = -1; } }
public void PassageBoundaryTest() { using (ConnectionBase connection = new ConnectionMock()) { BuildExcerptsCommand target = new BuildExcerptsCommand(connection); // default value Assert.AreEqual(target.PassageBoundary, BuildExcerptsCommand_Accessor.DEFAULT_PASSAGE_BOUNDARY); // valid value PassageBoundary expected = PassageBoundary.Paragraph; target.PassageBoundary = expected; Assert.AreEqual(expected, target.PassageBoundary); } }
public void HtmlStripModeTest() { using (ConnectionBase connection = new ConnectionMock()) { BuildExcerptsCommand target = new BuildExcerptsCommand(connection); // default value Assert.AreEqual(target.HtmlStripMode, BuildExcerptsCommand_Accessor.DEFAULT_HTML_STRIP_MODE); // valid value HtmlStripMode expected = HtmlStripMode.Retain; target.HtmlStripMode = expected; Assert.AreEqual(expected, target.HtmlStripMode); } }
public void StartPassageIdTest() { using (ConnectionBase connection = new ConnectionMock()) { BuildExcerptsCommand target = new BuildExcerptsCommand(connection); // default value Assert.AreEqual(target.StartPassageId, BuildExcerptsCommand_Accessor.DEFAULT_START_PASSAGE_ID); // valid value int expected = 1; target.StartPassageId = expected; Assert.AreEqual(expected, target.StartPassageId); // valid value target.StartPassageId = -1; } }
public void WordsCountLimitTest() { using (ConnectionBase connection = new ConnectionMock()) { BuildExcerptsCommand target = new BuildExcerptsCommand(connection); // default value Assert.AreEqual(target.WordsCountLimit, BuildExcerptsCommand_Accessor.DEFAULT_WORDS_COUNT_LIMIT); // valid value int expected = 1; target.WordsCountLimit = expected; Assert.AreEqual(expected, target.WordsCountLimit); // invalid value target.WordsCountLimit = -1; } }
public void SnippetsDelimiterTest() { using (ConnectionBase connection = new ConnectionMock()) { BuildExcerptsCommand target = new BuildExcerptsCommand(connection); // default value Assert.AreEqual(target.SnippetsDelimiter, BuildExcerptsCommand_Accessor.DEFAULT_SNIPPETS_DELIMITER); // valid value string expected = String.Empty; target.SnippetsDelimiter = expected; Assert.AreEqual(expected, target.SnippetsDelimiter); // invalid value target.SnippetsDelimiter = null; } }
public void SnippetSizeLimitTest() { using (ConnectionBase connection = new ConnectionMock()) { BuildExcerptsCommand target = new BuildExcerptsCommand(connection); // default value Assert.AreEqual(target.SnippetSizeLimit, BuildExcerptsCommand_Accessor.DEFAULT_SNIPPET_SIZE_LIMIT); // valid value int expected = 1; target.SnippetSizeLimit = expected; Assert.AreEqual(expected, target.SnippetSizeLimit); // invalid value target.SnippetSizeLimit = 0; } }
public void OptionsTest() { using (ConnectionBase connection = new ConnectionMock()) { BuildExcerptsCommand target = new BuildExcerptsCommand(connection); // default value Assert.AreEqual(target.Options, BuildExcerptsCommand_Accessor.DEFAULT_OPTIONS); // valid value BuildExcerptsOptions expected = BuildExcerptsOptions.OrderByWeight; target.Options = expected; Assert.AreEqual(expected, target.Options); } }
public void BeforeMatchTest() { using (ConnectionBase connection = new ConnectionMock()) { BuildExcerptsCommand target = new BuildExcerptsCommand(connection); // default value Assert.AreEqual(target.BeforeMatch, BuildExcerptsCommand_Accessor.DEFAULT_BEFORE_MATCH); // valid value string expected = "<pre>"; target.BeforeMatch = expected; target.BeforeMatch.Should().Be.EqualTo(expected); // invalid value target.BeforeMatch = null; } }
public void AfterMatchTest() { using (ConnectionBase connection = new ConnectionMock()) { BuildExcerptsCommand target = new BuildExcerptsCommand(connection); // default value Assert.AreEqual(target.AfterMatch, BuildExcerptsCommand_Accessor.DEFAULT_AFTER_MATCH); // valid value string expected = "</pre>"; target.AfterMatch = expected; string actual = target.AfterMatch; Assert.AreEqual(expected, actual); // invalid value target.AfterMatch = null; } }