Beispiel #1
0
        public void When_Next_set_to_non_ChainTokenizer_Add_inserts_into_middle()
        {
            var chain = new FakeTokenizer {
                Next = new ValueTokenizer()
            };

            chain.AppendLink(new FakeTokenizer());
            Assert.IsType <FakeTokenizer>(chain.Next);
            Assert.IsType <ValueTokenizer>((chain.Next as ChainTokenizer).Next);
        }
        public void Test(string currentDomain, string expectedToken)
        {
            var logger     = new FakeLogger();
            var serializer = new FakeDomainSerializer();
            var check      = new StaticDomainCheck(logger, serializer);
            var tokenizer  = new FakeTokenizer();

            var generator = new AntiforgeryTokenGenerator(check, tokenizer, currentDomain);
            var result    = generator.GetAntiForgeryToken();
            var expected  = new MvcHtmlString(expectedToken);

            Assert.Equal(expected.ToString(), result.ToString());
        }
Beispiel #3
0
        public void WithCustomTokenizerFactory_ShouldPassCustomImplementationToIndex()
        {
            var tokenizer = new FakeTokenizer();
            var factory   = new Mock <ITokenizerFactory>();

            factory.Setup(f => f.Create(It.IsAny <TokenizationOptions>())).Returns(tokenizer);
            var parser = this.ConfigureQueryParserMock();

            this.sut.WithTokenizerFactory(factory.Object);

            var index = this.sut.Build();

            index.Search("test").Should().BeEmpty();

            parser.Verify(p => p.Parse(It.IsAny <IIndexedFieldLookup>(), It.IsAny <string>(), tokenizer), Times.Once);
        }
Beispiel #4
0
        public void WithDefaultTokenizationOptions_ShouldUseOptionsWhenSearchingWithNoTokenizerOptions()
        {
            var factory      = new Mock <ITokenizerFactory>();
            var tokenizer    = new FakeTokenizer();
            var xmlTokenizer = new XmlTokenizer();

            factory.Setup(f => f.Create(It.Is <TokenizationOptions>(o => o.TokenizerKind == TokenizerKind.XmlContent))).Returns(xmlTokenizer);
            factory.Setup(f => f.Create(It.Is <TokenizationOptions>(o => o.TokenizerKind == TokenizerKind.PlainText))).Returns(tokenizer);
            var parser = this.ConfigureQueryParserMock();

            this.sut.WithTokenizerFactory(factory.Object);
            this.sut.WithDefaultTokenizationOptions(o => o.XmlContent());

            var index = this.sut.Build();

            index.Search("test").Should().BeEmpty();
            index.Search("test with tokenization options", TokenizationOptions.Default).Should().BeEmpty();
            parser.Verify(p => p.Parse(It.IsAny <IIndexedFieldLookup>(), "test", xmlTokenizer), Times.Once);
            parser.Verify(p => p.Parse(It.IsAny <IIndexedFieldLookup>(), "test with tokenization options", tokenizer), Times.Once);
        }