示例#1
0
        public void Request_ConstantSubstitution_ExpectedValue()
        {
            Request request = new Request(new Uri(@"http://localhost/rest/user/login/"), HttpMethod.Get);

            request.Content = "{ \"email\":\"[email protected]\",\"password\":\"123456\"}";

            IRequestTokenizer tokenizer = new JsonTokenizer();
            TokenCollection   tokens    = tokenizer.ExtractTokens(request);

            List <IToken> email = tokens.GetByName("email");

            Assert.Single(email);

            ISubstitution substitution = new SubstituteConstant(email[0], "*****@*****.**");

            substitution.MakeSubstitution(null, request);

            tokens = tokenizer.ExtractTokens(request);
            email  = tokens.GetByName("email");
            Assert.Equal("*****@*****.**", email[0].Value);
        }
        public IEnumerable <RequestSequence> Generate(List <KnownEndpoint> endpoints, RequestSequence sequence, List <TokenCollection> sequenceResults)
        {
            if (dictionary.Count == 0)
            {
                yield break;
            }

            for (int i = 0; i < MaxSubstitutions; ++i)
            {
                if (sequence.StageCount() == 0)
                {
                    continue;
                }

                RequestSequence newSequence   = sequence.Copy();
                int             selectedStage = rand.Next(0, newSequence.StageCount());

                Stage stage = newSequence.Get(selectedStage);

                if (stage.Substitutions.Count == 0)
                {
                    continue;
                }

                int           subIndex = rand.Next(0, newSequence.Get(selectedStage).Substitutions.Count);
                ISubstitution sub      = newSequence.Get(selectedStage).Substitutions[subIndex];
                newSequence.Get(selectedStage).Substitutions.RemoveAt(subIndex);

                string             replacement        = dictionary[rand.Next(0, dictionary.Count)];
                SubstituteConstant substituteConstant = new SubstituteConstant(sub.GetTarget(), replacement);
                newSequence.Get(selectedStage).Substitutions.Add(substituteConstant);

                yield return(newSequence);
            }
            yield break;
        }