Пример #1
0
        public void TestOr()
        {
            Tokens tokens = new Tokens();

            tokens.AddToken(new WordToken("word1"));
            tokens.AddToken(new WordToken("word2"));
            tokens.AddToken(new WordToken("word4"));
            tokens.AddToken(new WordToken("word6"));
            tokens.AddToken(new WordToken("word8"));

            Parser parse = new Parser(tokens);
            Node   root  = parse.BinaryTree.root;

            Evaluater     eval = new Evaluater(root, index);
            List <string> res  = eval.result.ToList <string>();

            Assert.IsNotNull(res);
            Assert.Contains("doc1", res);
            Assert.Contains("doc2", res);
            Assert.Contains("doc3", res);
            Assert.Contains("doc4", res);
            Assert.Contains("doc6", res);
            Assert.AreEqual(5, res.Count);
            Assert.AreNotEqual(2, res.Count);
        }
Пример #2
0
        public void TestParserSimpleLogicExpression()
        {
            Tokens tokens = new Tokens();

            tokens.AddToken(new ParenthesisBeginToken());
            tokens.AddToken(new WordToken("w1"));
            tokens.AddToken(new OrToken());
            tokens.AddToken(new WordToken("w2"));
            tokens.AddToken(new ParenthesisEndToken());

            _parser = new Parser(tokens);
            Node treeRoot = _parser.BinaryTree.root;

            Assert.AreEqual(3, _parser.BinaryTree.count);
        }
Пример #3
0
        public void TestParserSingleWordOnly()
        {
            Tokens tokens = new Tokens();

            tokens.AddToken(new WordToken("good men"));

            _parser = new Parser(tokens);
            Node treeRoot = _parser.BinaryTree.root;

            Assert.AreEqual(1, _parser.BinaryTree.count);
        }
Пример #4
0
        public void TestAndNot()
        {
            Tokens tokens = new Tokens();

            tokens.AddToken(new ParenthesisBeginToken());
            tokens.AddToken(new WordToken("word6"));
            tokens.AddToken(new AndNotToken());
            tokens.AddToken(new WordToken("word12"));
            tokens.AddToken(new ParenthesisEndToken());

            Parser parse = new Parser(tokens);
            Node   root  = parse.BinaryTree.root;

            Evaluater     eval = new Evaluater(root, index);
            List <string> res  = eval.result.ToList <string>();

            Assert.IsNotNull(res);
            Assert.Contains("doc2", res);
            Assert.AreEqual(1, res.Count);
        }
Пример #5
0
        public void AuthorizesMeToAccessTo()
        {
            var resourceOwner1 = ResourceOwners.Add("testusertoken1");
            var resourceOwner2 = ResourceOwners.Add("testusertoken2");

            var authorizationRequestUri = new Uri("http://example.com/TokenTest/AuthRequest");
            var accessTokenRequestUri   = new Uri("http://example.com/TokenTest/AccessRequest");
            var redirectUri             = new Uri("http://example.com/TokenTest/Redirect");
            var server = ServersWithAuthorizationCode.Add("testclienid", "testsecret", authorizationRequestUri, accessTokenRequestUri, redirectUri);

            var token = new Token(server, resourceOwner1);

            token.AuthorizationCode = "foobar";
            Tokens.AddToken(token);

            resourceOwner1.AuthorizesMeToAccessTo(server).Should().BeTrue();
            resourceOwner2.AuthorizesMeToAccessTo(server).Should().BeFalse();
        }
Пример #6
0
        public void TestParserWordsOnlyNoLogic()
        {
            Tokens tokens = new Tokens();

            tokens.AddToken(new WordToken("w1"));
            tokens.AddToken(new WordToken("w2"));
            tokens.AddToken(new WordToken("w3"));
            tokens.AddToken(new WordToken("w4"));
            tokens.AddToken(new WordToken("w5"));
            tokens.AddToken(new WordToken("w6"));
            tokens.AddToken(new WordToken("w7"));

            _parser = new Parser(tokens);
            Node treeRoot = _parser.BinaryTree.root;

            Assert.AreEqual(13, _parser.BinaryTree.count);
        }
Пример #7
0
        public void GetSignedRequestTest()
        {
            var resourceOwner = ResourceOwners.Add("testusersignedRequest");
            var server        = ServersWithAuthorizationCode.Add("clientid",
                                                                 "secret",
                                                                 new Uri("http://example.org/auth"),
                                                                 new Uri("http://example.org/access"),
                                                                 new Uri("http://example.org/redirect"));
            var token = new Token(server, resourceOwner);

            Tokens.AddToken(token);
            token.AuthorizationCode = "authcode";
            token.AccessToken       = "access123";
            token.Expires           = DateTime.Now.AddHours(1);

            var location1 = "http://example.org/protectedresource1";
            var location2 = "http://example.org/protectedresource2?foo=bar";

            var webRequest1 = resourceOwner.GetSignedRequestFor(server, location1);
            var webRequest2 = resourceOwner.GetSignedRequestFor(server, location2);

            webRequest1.RequestUri.Should().Be(location1 + "?access_token=access123");
            webRequest2.RequestUri.Should().Be(location2 + "&access_token=access123");
        }
Пример #8
0
        public void TestParserComplexLogicExpression()
        {
            Tokens tokens = new Tokens();

            tokens.AddToken(new ParenthesisBeginToken());
            tokens.AddToken(new WordToken("good men"));
            tokens.AddToken(new OrToken());
            tokens.AddToken(new ParenthesisBeginToken());
            tokens.AddToken(new WordToken("evil"));
            tokens.AddToken(new OrToken());
            tokens.AddToken(new WordToken("bad"));
            tokens.AddToken(new ParenthesisEndToken());
            tokens.AddToken(new ParenthesisEndToken());
            tokens.AddToken(new AndToken());
            tokens.AddToken(new ParenthesisBeginToken());
            tokens.AddToken(new WordToken("women"));
            tokens.AddToken(new AndToken());
            tokens.AddToken(new WordToken("children"));
            tokens.AddToken(new ParenthesisEndToken());


            _parser = new Parser(tokens);
            Node treeRoot = _parser.BinaryTree.root;

            Assert.AreEqual(9, _parser.BinaryTree.count);
        }