Пример #1
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            MdToken tk = new MdToken();
            IEnumerable <string> headerValues;

            if (request.Headers.TryGetValues("authorization", out headerValues))
            {
                tk.Token = headerValues.First();
            }
            if (tk.Token != null)
            {
                Token.GetToken(request);
                var auth = Token.AutorizeToken(request);
                if (auth.MessageResponse != null)
                {
                    return(request.CreateErrorResponse(HttpStatusCode.Unauthorized, auth.MessageResponse));
                }
            }

            //Allow the request to process further down the pipeline
            var response = await base.SendAsync(request, cancellationToken);

            //Return the response back up the chain
            return(response);
        }
Пример #2
0
        public void MakeTokens_Should_ReturnSeveralEmptyTokens_When_TextWithMultipleSpacesAndNoSpecialSymbols()
        {
            var tokens        = tokenizer.MakeTokens("abc      bc").ToList();
            var firstToken    = tokens.First();
            var expectedToken = new MdToken("abc", "NONE", "NONE");

            firstToken.Should().BeEquivalentTo(expectedToken);
        }
Пример #3
0
        public void MakeTokens_Should_ReturnSeveralDifferentTokens_When_TextWithSeveralTokensWithSymbols()
        {
            var tokens        = tokenizer.MakeTokens("_abc_ _abc_ __ade__").ToList();
            var lastToken     = tokens.Last();
            var expectedToken = new MdToken("ade", "__", "__");

            lastToken.Should().BeEquivalentTo(expectedToken);
        }
        public void GetProcessedResult_Should_ProcessTokenToHtml(string tokenContent,
                                                                 string beginningSymbol,
                                                                 string endingSymbol,
                                                                 string parsedExpectedText)
        {
            var token      = new MdToken(tokenContent, beginningSymbol, endingSymbol);
            var parsedText = processor.GetProcessedResult(token);

            parsedText.Should().Be(parsedExpectedText);
        }
Пример #5
0
        public void MakeTokens_Should_ParseToken(string text,
                                                 string expectedContent,
                                                 string expectedSpecialSymbolBeginning,
                                                 string expectedSpecialSymbolEnding)
        {
            var actualToken   = (MdToken)tokenizer.MakeTokens(text).ToList().First();
            var expectedToken = new MdToken(expectedContent, expectedSpecialSymbolBeginning, expectedSpecialSymbolEnding);

            actualToken.Should().BeEquivalentTo(expectedToken);
        }
Пример #6
0
        public string GetProcessedResult(MdToken token)
        {
            if (token == null)
            {
                throw new ArgumentNullException(nameof(token));
            }
            if (token.Content == "")
            {
                throw new ArgumentException("Token content is empty");
            }

            var htmlBeginning = htmlSymbolTable.GetHtmlBeginning(token.BeginningSpecialSymbol);
            var htmlEnding    = htmlSymbolTable.GetHtmlEnding(token.EndingSpecialSymbol);

            return(htmlBeginning + token.Content + htmlEnding);
        }
Пример #7
0
        public void MakeTokens_Should_ParseIncorrectEmphasis_When_TextWithNestedTokens()
        {
            var tokens             = tokenizer.MakeTokens("__Lorem _ipsum dolor sit amet__").ToList();
            var firstToken         = tokens[0];
            var secondToken        = tokens[1];
            var lastToken          = tokens.Last();
            var expectedFirstToken = new MdToken("Lorem", "__", "NONE");

            firstToken.Should().BeEquivalentTo(expectedFirstToken);
            var expectedSecondToken = new MdToken("_ipsum", "NONE", "NONE");

            secondToken.Should().BeEquivalentTo(expectedSecondToken);
            var expectedLastToken = new MdToken("amet", "NONE", "__");

            lastToken.Should().BeEquivalentTo(expectedLastToken);
        }
Пример #8
0
        [Test] public void MakeTokens_Should_IgnoreNesting_When_NestedTokenCantBeNested()
        {
            var tokens             = tokenizer.MakeTokens("_Lorem __ipsum__ dolor sit amet_").ToList();
            var firstToken         = tokens[0];
            var secondToken        = tokens[1];
            var lastToken          = tokens.Last();
            var expectedFirstToken = new MdToken("Lorem", "_", "NONE");

            firstToken.Should().BeEquivalentTo(expectedFirstToken);
            var expectedSecondToken = new MdToken("__ipsum__", "NONE", "NONE");

            secondToken.Should().BeEquivalentTo(expectedSecondToken);
            var expectedLastToken = new MdToken("amet", "NONE", "_");

            lastToken.Should().BeEquivalentTo(expectedLastToken);
        }
Пример #9
0
        public static MdToken GetToken(HttpRequestMessage Request)
        {
            MdToken tk = new MdToken();
            IEnumerable <string> headerValues;

            if (Request.Headers.TryGetValues("authorization", out headerValues))
            {
                tk.Token = headerValues.First();
            }
            var jwtToken = new JwtSecurityToken(tk.Token);
            var payload  = jwtToken.Payload;

            tk.IdUser = Convert.ToInt32(payload["userId"]);
            tk.Name   = payload["name"].ToString();
            tk.Expire = payload["expire"].ToString();
            expire    = tk.Expire;
            return(tk);
        }
        public void GetProcessedResult_Should_ThrowArgumentException_When_TokenHasEmptyContent()
        {
            var token = new MdToken("", "NONE", "NONE");

            Following.Code(() => processor.GetProcessedResult(token)).Should().Throw <ArgumentException>();
        }