Esempio n. 1
0
        public override void Extract(object sender, ExtractionEventArgs e)
        {
            JsonExtractionRule msgIdExtractionRule =
                new JsonExtractionRule()
            {
                ContextParameterName = this.ContextParameterName, Name = ParamToExtract
            };

            msgIdExtractionRule.Extract(sender, e);

            WebTestContext context = e.WebTest.Context;

            try
            {
                if (context.ContainsKey(Constants.Context_MessageId) &&
                    context.ContainsKey(Constants.Context_UserActivity))
                {
                    string   jsonInput = context[Constants.Context_UserActivity].ToString();
                    Activity activity  = JsonConvert.DeserializeObject <Activity>(jsonInput);
                    activity.Conversation =
                        new ConversationAccount()
                    {
                        Id = context[Constants.Context_ConvId].ToString()
                    };

                    activity.Id = context[Constants.Context_MessageId].ToString();

                    context[Constants.Context_UserActivity] = JsonConvert.SerializeObject(activity);
                    int waterMark = int.Parse(context[Constants.Context_MessageId].ToString().Split('|')[1]);
                    if (waterMark > 1)
                    {
                        waterMark--;
                    }

                    context[Constants.Context_Watermark] = $"/{waterMark}";
                    e.Success = true;
                }
                else
                {
                    e.Success = false;
                    e.Message = "Message Id or User Activity not found";
                }
            }
            catch
            {
                e.Success = false;
            }
        }
Esempio n. 2
0
        public override void Validate(object sender, ValidationEventArgs e)
        {
            if (e.Response.StatusCode == HttpStatusCode.OK)
            {
                WebTestContext context = e.WebTest.Context;

                context[Constants.Context_MessagePostedToBot] = true;
                context[Constants.Context_TestStatus]         = true;
                context[Constants.Context_ActualResult]       = "Sent";

                if (context.ContainsKey(Constants.Context_MessageId) && context.ContainsKey(Constants.Context_UserActivity))
                {
                    string   jsonInput = context[Constants.Context_UserActivity].ToString();
                    Activity activity  = JsonConvert.DeserializeObject <Activity>(jsonInput);
                    activity.Timestamp = DateTime.UtcNow.AddSeconds(-2);
                    context[Constants.Context_UserActivity] = JsonConvert.SerializeObject(activity, new JsonSerializerSettings()
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    });
                }
            }
        }
Esempio n. 3
0
 public static string ResolveContextValue(WebTestContext context, string value)
 {
     return(_FindContextKey.Replace(value, new MatchEvaluator((m) => {
         string keyName = m.Groups[1].Value;
         if (context.ContainsKey(keyName))
         {
             return context[keyName].ToString();
         }
         else
         {
             throw new ApplicationException(string.Format("Key {0} not found in Context", keyName));
         }
     })));
 }
Esempio n. 4
0
        public static bool NotAlreadyDone(WebTestContext context, string stepKey, Action callback)
        {
            int    stepNo  = (int)context[ASPNETWebTestPlugin.STEP_NO_KEY];
            string keyName = stepKey + "." + stepNo;

            if (context.ContainsKey(keyName))
            {
                return(false);
            }
            else
            {
                callback();
                context[keyName] = true;
                return(true);
            }
        }
Esempio n. 5
0
        public static string PlaceUniqueItem(WebTestContext context, string keyPrefix, object value)
        {
            int i = 1;

            while (context.ContainsKey(keyPrefix + "." + i))
            {
                if (((IComparable)context[keyPrefix + "." + i]).Equals(value))
                {
                    break; // We already have this exact control in Context.
                }
                else
                {
                    i++; // Another instance of the same Control. Try another number in Key.
                }
            }

            string keyName = keyPrefix + "." + i;

            context[keyName] = value;

            return(keyName);
        }
Esempio n. 6
0
 public void ContainsPassesForValueSavedInContext()
 {
     WebTestContext.Set("a", "SetPropertyWithNewKey");
     Assert.True(WebTestContext.ContainsKey("a"), "Key exists, must return true.");
 }