Beispiel #1
0
 public void Should_fail_to_get_unsupported_verb()
 {
     _routeConvention.Should().Throw <InvalidOperationException>(
         x => x.GetRouteDescriptors(new RouteContext(ActionMethod
                                                     .From <VerbHandler>(h => h.NotASupportedVerb()))))
     .Message.ShouldContainAll(typeof(VerbHandler).FullName,
                               nameof(VerbHandler.NotASupportedVerb));
 }
 public ActionParameter(ActionMethod action, ParameterDescriptor parameter)
 {
     Descriptor          = parameter;
     Name                = parameter.Name;
     IsParameter         = true;
     Action              = action;
     ParameterDescriptor = parameter;
     TypeDescriptor      = parameter?.ParameterType;
 }
Beispiel #3
0
        public void MultiMethodsTestInvalid2()
        {
            TypeDefinition <IMultiMethods1> typeDefinition =
                new TypeDefinition <IMultiMethods1>(
                    ActionMethod.Create("Foo", (short value) => { }));
            IMultiMethods1 instance = typeDefinition.Create();

            instance.Foo(5);
        }
Beispiel #4
0
        public void Should_get_all_common_http_verbs(Expression <Action <VerbHandler> > action)
        {
            var descriptors = _routeConvention.GetRouteDescriptors(
                new RouteContext(ActionMethod.From(action)));

            descriptors.Count.ShouldEqual(1);
            descriptors.First().Method.ShouldEqual(action.GetMethodInfo()
                                                   .Name.Replace("_Segment", "").ToUpper());
        }
Beispiel #5
0
        public void MultiMethodsTest2()
        {
            TypeDefinition <IMultiMethods1> typeDefinition =
                new TypeDefinition <IMultiMethods1>(
                    ActionMethod.Create("Foo", (int a) => { }));
            IMultiMethods1 instance = typeDefinition.Create();

            instance.Foo(5);
        }
Beispiel #6
0
 public GatherVerb(string action = "", ActionMethod method = ActionMethod.POST, uint timeout = 5, char finishOnKey = '#', int numDigits = 1000)
     : base(Verb.Gather)
 {
     this.Action      = action;
     this.Method      = method;
     this.Timeout     = timeout;
     this.FinishOnKey = finishOnKey;
     this.NumDigits   = numDigits;
 }
 /// <summary>
 /// Adds a Redirect Element to the Response.
 /// </summary>
 /// <param name="url">The URL.</param>
 /// <param name="method">The method.</param>
 public TwiMLBuilder Redirect(string url, ActionMethod method = ActionMethod.POST)
 {
     return(AddVerb(Verb.Redirect,
                    url,
                    new
     {
         method = method
     }));
 }
Beispiel #8
0
        private ActionDescriptor AddRoute(List <ActionDescriptor> actions, string route)
        {
            var descriptor = new ActionDescriptor(ActionMethod.From <Handler>(x => x.Get()),
                                                  new RouteDescriptor("GET", route, null, null, null, null),
                                                  null, null, null, null, null, null, new TypeCache());

            actions.Add(descriptor);
            return(descriptor);
        }
 public ActionParameter(ActionMethod action, PropertyDescriptor property)
 {
     Descriptor         = property;
     Name               = property.Name;
     IsProperty         = true;
     Action             = action;
     PropertyDescriptor = property;
     TypeDescriptor     = property?.PropertyType;
 }
Beispiel #10
0
        public void MultiMethodsTestInvalid1()
        {
            TypeDefinition <IMultiMethods1> typeDefinition =
                TypeDefinition <IMultiMethods1> .Create(ActionMethod.Create("Foo", (string value) => { }));

            IMultiMethods1 instance = typeDefinition.CreateNew();

            instance.Foo(5);
        }
 protected virtual void ValidateUrlParameters(ActionMethod action,
                                              List <UrlParameter> urlParameters)
 {
     if (urlParameters.Count(x => x.IsWildcard) > 1)
     {
         throw new InvalidOperationException("Multiple wildcard parameters found on " +
                                             $"action {action.HandlerTypeDescriptor.FriendlyFullName}." +
                                             $"{action.MethodDescriptor.FriendlyName}.");
     }
 }
        private static void Add <T>(IList <string> source, ActionMethod action,
                                    Func <T, string[]> items) where T : Attribute
        {
            var attribute = action.GetActionOrHandlerAttribute <T>();

            if (attribute != null && items(attribute).Any())
            {
                source.AddRange(items(attribute));
            }
        }
Beispiel #13
0
        public void Should_build_url(Expression <Action <UrlHandler> > action, string url)
        {
            var descriptors = _routeConvention.GetRouteDescriptors(
                new RouteContext(ActionMethod.From(action)));

            descriptors.Count.ShouldEqual(1);
            var descriptor = descriptors.First();

            descriptor.Url.ShouldEqual($"Unit/Routing/{url}".Trim('/'));
        }
Beispiel #14
0
 public void Setup()
 {
     _requestMessage = new HttpRequestMessage(HttpMethod.Post, "http://www.fark.com");
     _requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(MimeTypes.ApplicationAtomXml));
     _actionMethod     = ActionMethod.From <Handler>(x => x.Post());
     _urlTemplate      = "http://www.fark.com/{fark}";
     _actionDescriptor = new ActionDescriptor(_actionMethod,
                                              new RouteDescriptor("POST", _urlTemplate, null, null, null, null),
                                              null, null, null, null, null, null, null);
 }
Beispiel #15
0
        public void Should_fail_to_bind_parameter()
        {
            var action          = ActionMethod.From <PropertyBinderHandler>(x => x.Action(null));
            var parameter       = action.MethodDescriptor.Parameters.First();
            var actionParameter = new ActionParameter(action, parameter);
            var model           = new PropertyBinderHandler.Model();

            actionParameter.Should().Throw <InvalidOperationException>(
                x => x.BindProperty(model, "fark"));
        }
Beispiel #16
0
        public void Should_get_value_from_argument()
        {
            var action    = ActionMethod.From <ArgumentHandler>(x => x.Action(null, null));
            var parameter = action.MethodDescriptor.Parameters
                            .First(x => x.Name == "value");
            var actionParameter = new ActionParameter(action, parameter);
            var arguments       = new object[] { null, "fark" };

            actionParameter.GetArgument(arguments).ShouldEqual("fark");
        }
Beispiel #17
0
 public static IEnumerable <IRouteConvention> ThatApplyTo(
     this IEnumerable <IRouteConvention> routeConventions,
     ActionMethod actionMethod, Configuration configuration,
     HttpConfiguration httpConfiguration)
 {
     return(configuration.RouteConventions
            .ThatAppliesTo(routeConventions, new RouteConfigurationContext(
                               configuration, httpConfiguration, actionMethod),
                           new RouteContext(actionMethod)));
 }
Beispiel #18
0
        public void Should_override_no_response_code(
            [Values(null, "fark")] string reasonPhrase)
        {
            _configuration.DefaultNoResponseReasonPhrase = reasonPhrase;
            CreateStatus(ActionMethod.From <Handler>(x => x.OverrideCodePost()))
            .SetStatus(CreateContext(ResponseState.NoResponse));

            _response.StatusCode.ShouldEqual(HttpStatusCode.Created);
            _response.ReasonPhrase.ShouldEqual(reasonPhrase ?? "Created");
        }
Beispiel #19
0
        public void Should_set_default_no_response_status(
            [Values(null, "fark")] string reasonPhrase)
        {
            _configuration.DefaultNoResponseReasonPhrase = reasonPhrase;
            CreateStatus(ActionMethod.From <Handler>(x => x.Post()))
            .SetStatus(CreateContext(ResponseState.NoResponse));

            _response.StatusCode.ShouldEqual(_configuration.DefaultNoResponseStatusCode);
            _response.ReasonPhrase.ShouldEqual(reasonPhrase ?? "No Content");
        }
Beispiel #20
0
        public void Should_fail_if_multiple_wildcards_specified()
        {
            var action = ActionMethod.From <WildcardHandler>(t => t
                                                             .GetWildcardAttributeMultiple_Values1_Values2(null, null));

            var message = _routeConvention.Should().Throw <InvalidOperationException>(x => x
                                                                                      .GetRouteDescriptors(
                                                                                          new RouteContext(action))).Message;

            message.ShouldContain(action.MethodDescriptor.FriendlyName);
        }
Beispiel #21
0
        public void Should_return_null_if_property_argument_is_null()
        {
            var action    = ActionMethod.From <ArgumentHandler>(x => x.Action(null, null));
            var parameter = action.MethodDescriptor.Parameters
                            .First(x => x.Name == "value");
            var property        = parameter.ParameterType.Properties.First();
            var actionParameter = new ActionParameter(action, parameter, property);
            var arguments       = new object[2];

            actionParameter.GetArgument(arguments).ShouldBeNull();
        }
Beispiel #22
0
        public void Should_fail_to_bind_property_to_arguments()
        {
            var action   = ActionMethod.From <ArgumentHandler>(x => x.Action(null, null));
            var property = action.MethodDescriptor.Parameters
                           .First(x => x.Name == "model").ParameterType.Properties.First();
            var actionParameter = new ActionParameter(action, property);
            var arguments       = new object[2];

            actionParameter.Should().Throw <InvalidOperationException>(
                x => x.BindArgument(arguments, "fark"));
        }
 public ValueMapperConfigurationContext(Configuration configuration,
                                        HttpConfiguration httpConfiguration,
                                        ActionMethod actionMethod, RouteDescriptor routeDescriptor,
                                        ActionParameter parameter, object[] values)
     : base(parameter, values)
 {
     Configuration     = configuration;
     HttpConfiguration = httpConfiguration;
     Action            = actionMethod;
     Route             = routeDescriptor;
 }
Beispiel #24
0
 /// <summary>
 /// condition CANNOT be null!
 /// </summary>
 /// <param name="condition"></param>
 /// <param name="action"></param>
 public Coroutine(ConditionMethod condition, ActionMethod action)
     : this()
 {
     if (condition == null)
     {
         throw new ArgumentNullException("condition");
     }
     ID        = null;
     Condition = condition;
     Action    = action;
 }
Beispiel #25
0
        public static List <Type> ThatApplyTo(this ConditionalPlugins
                                              <IBehavior, ActionConfigurationContext> behaviors,
                                              ActionMethod actionMethod, RouteDescriptor routeDescriptor,
                                              Configuration configuration, HttpConfiguration httpConfiguration)
        {
            var context = new ActionConfigurationContext(configuration,
                                                         httpConfiguration, actionMethod, routeDescriptor);

            return(behaviors.ThatApplyTo(context)
                   .Select(x => x.Type).ToList());
        }
Beispiel #26
0
 internal static void Invoke(object thisObject, ActionMethod method, object param)
 {
     if (param.GetType().IsArray)
     {
         method.MethodInfo.Invoke(thisObject, param.CastToType <object[]>());
     }
     else
     {
         Invoke(thisObject, method.Method, param);
     }
 }
Beispiel #27
0
        private void RegisterController(Type type)
        {
            var query = from a in System.Attribute.GetCustomAttributes(type)
                        where a is attribute.Controller
                        select a.CastToType <attribute.Controller>();

            attribute.Controller controlerAttribute = query.FirstOrDefault();
            if (controlerAttribute.IsNotNull())
            {
                Controller controller = _controllers.FirstOrDefault(c => c.Name == controlerAttribute.ControllerName);
                if (controller.IsNull() || controller.Object.IsNull())
                {
                    type.GetMethods().AsEnumerable().Where(m => !m.IsConstructor && !m.IsGenericMethod && m.IsPublic &&
                                                           !m.IsStatic && m.IsVirtual).SelectMany(m => System.Attribute.GetCustomAttributes(m).Where(a => a.IsTypeOf <ActionMethod>()),
                                                                                                  (m, a) => new { Method = m, Attribute = a.CastToType <ActionMethod>() }).
                    ToList().ForEach((ma) =>
                    {
                        ActionMethod action = ma.Attribute;
                        controller          = controller.IfNullDefault <Controller>(() =>
                        {
                            Controller c = new Controller()
                            {
                                Name = controlerAttribute.ControllerName,
                                Type = type,
                            };
                            return(c);
                        });

                        AddActionMethod(controller, type, action.ActionName, ma.Method.Name, ma.Method);
                    });

                    if (controller.IsNotNull())
                    {
                        _controllers.AddIfNotContains(controller);
                        if (controller.Object.IsNull())
                        {
                            var options = new ProxyGenerationOptions(new ControllerInterceptorGenerationHook())
                            {
                                Selector = new ControllerInterceptorSelector()
                            };
                            controller.Object = _generator.CreateClassProxy(type, options, new ControllerInterceptor(controlerAttribute.ControllerName));
                        }
                    }
                }
                else
                {
                    throw new ControllerRegistrationException(controlerAttribute.ControllerName + " already register ");
                }
            }
            else
            {
                throw new ControllerRegistrationException("Type[" + type.FullName + "] it cann't be recognise as valid Controller. Controller Attribute on class level is required.");
            }
        }
		public static string GetActionName( ActionMethod method )
		{
			string action_name = null;

			if ( m_methods.Contains( method ) )
			{
				int index = m_methods.IndexOfValue( method );
				action_name = (string)m_methods.GetKey(index);
			}

			return action_name;
		}
Beispiel #29
0
        public void Should_exclude_diagnostics_pages_if_configured(
            [Values(true, false)] bool excludeDiagnostics)
        {
            var actionDescriptor = new ActionDescriptorFactory(_configuration, null, new TypeCache())
                                   .CreateDescriptor(ActionMethod.From <GraphiteHandler>(x => x.Post()), null);
            var behavior = new AuthenticationBehavior(_behaviorChain, _requestMessage,
                                                      _responseMessage, _authenticators, _configuration, actionDescriptor);

            _configuration.ExcludeDiagnosticsFromAuthentication = excludeDiagnostics;

            behavior.ShouldRun().ShouldEqual(!excludeDiagnostics);
        }
Beispiel #30
0
 public ParameterBinder(Configuration configuration,
                        HttpConfiguration httpConfiguration,
                        ActionMethod actionMethod,
                        RouteDescriptor routeDescriptor,
                        IEnumerable <IValueMapper> mappers)
 {
     _configuration     = configuration;
     _httpConfiguration = httpConfiguration;
     _mappers           = mappers;
     _actionMethod      = actionMethod;
     _routeDescriptor   = routeDescriptor;
 }
 public MethodAction(ActionMethod actionMethod)
     : base()
 {
     m_actionMethod = actionMethod;
 }
Beispiel #32
0
 public OpenFile(ActionMethod method)
 {
     openfileAction = method;
 }
Beispiel #33
0
 public StopVirtualHardware(ActionMethod method)
 {
     stopVirtualHardwareAction = method;
 }
Beispiel #34
0
        /// <summary>
        /// Adds a Gather Element with a nested Playing Element.
        /// </summary>
        /// <param name="fileUrl">The file URL.</param>
        /// <param name="timesToLoop">The times to loop.</param>
        /// <param name="actionUrl">The action URL.</param>
        /// <param name="actionMethod">The action method.</param>
        /// <param name="timeoutSeconds">The timeout seconds.</param>
        /// <param name="keyThatFinishes">The key that finishes.</param>
        /// <param name="numDigitsToCollect">The num digits to collect.</param>
        public TwiMLBuilder GatherWhilePlaying(string fileUrl, uint timesToLoop = 1,
            string actionUrl = "", ActionMethod actionMethod = ActionMethod.POST, uint timeoutSeconds = 5,
            char keyThatFinishes = '#', uint numDigitsToCollect = 1000)
        {
            var playChild = Tuple.Create(Verb.Play,
                fileUrl,
                (object)new
                {
                    loop = timesToLoop
                });

            return Gather(actionUrl, actionMethod, timeoutSeconds, keyThatFinishes, numDigitsToCollect, playChild);
        }
Beispiel #35
0
        /// -------------------------------------------------------------------
        /// <summary>Helper: Press button</summary>
        /// -------------------------------------------------------------------
        void HelperPressButton(AutomationElement element, ActionMethod actionBY, CheckType checkType)
        {
            Library.ValidateArgumentNonNull(element, "Button AutomationElement");

            string name = element.Current.Name;

            switch (actionBY)
            {
                case ActionMethod.KeyPadOnly:
                    {
                        string buffer = element.Current.AccessKey;
                        if (!string.IsNullOrEmpty(buffer))
                        {
                            // There is an access key so use it
                            Comment("Pressing keyboard access key \"" + element.Current.AccessKey + "\"");
                            Input.SendKeyboardInput(element.Current.AccessKey);
                        }
                        else
                        {
                            // No access key so set focus and press enter
                            Comment("Setting focus to \"{0}\" and pressing ENTER", element.Current.Name);
                            element.SetFocus();
                            Input.SendKeyboardInput(System.Windows.Input.Key.Enter);
                        }
                    }
                    break;
                case ActionMethod.MouseClick:
                    {
                        Comment("Moving mouse to \"" + element.Current.Name + "\" and left clicking");
                        Input.MoveToAndClick(element);
                    }
                    break;
                default:
                    {
                        if (!(bool)element.GetCurrentPropertyValue(AutomationElement.IsInvokePatternAvailableProperty))
                            ThrowMe(checkType, "Button \"" + name + "\" does not support Invoke pattern");

                        Comment("Calling InvokePattern.Invoke() on \"" + name + "\"");
                        ((InvokePattern)element.GetCurrentPattern(InvokePattern.Pattern)).Invoke();
                    }
                    break;
            }
        }
Beispiel #36
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        void TS_DialogAboutBoxOpen(ActionMethod actionMethod, CheckType checkType)
        {
            switch (actionMethod)
            {
                case ActionMethod.Menu:
                    {
                        Comment("Opening \"About dialog\" by clicking on the menu item");
                        HelperExpandMenuUsingAccessKey(MainForm.ApplicationMenuBar.HelpMenu.AutomationElement, checkType);
                        HelperInvokeMenuItemUsingAccessKey(MainForm.ApplicationMenuBar.HelpMenu.HelpAbout, CheckType.Verification);
                    }
                    break;
                default:
                    ThrowMe(checkType, "Invalid argument");
                    break;
            }

            Wait(WaitForAboutBoxDialogToBeVisible, _WAIT_NORMAL_MILLISECONDS, checkType);

            m_TestStep++;
        }
Beispiel #37
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -----------------------`--------------------------------------------
        private void TSM_MainDialogSettings(
            ActionMethod actionMethod,
            string keyName,
            GetElement subMenu,
            GetElement checkBox,
            WaitTestState callbackCheckBoxIsChecked,
            WaitTestState callbackCheckBoxIsUnChecked,
            CheckType checkType)
        {

            // "Step: Toggle the \"\" menu",
            TS_ToggleMainFormSettingsByMenu(
                ActionMethod.Menu,
                MainForm.ApplicationMenuBar.PreferencesMenu.AutomationElement,
                subMenu,
                callbackCheckBoxIsChecked, callbackCheckBoxIsUnChecked,
                CheckType.Verification);

            HelperPersistKeyNameValuesToTable(_keyNameValuesCurrent);

            // "Step: Close Narrator",
            TS_NarratorClose(ActionMethod.UIAutomation, true, CheckType.Verification);

            // "Step: Restart Narrator",
            TS_NarratorStart(WindowVisualState.Normal, CheckType.Verification);

            // "Step: Verify current \"\" registry setting to previous runs value set",
            // "Step: Verify current \"\" check box setting to previous runs value set",
            // "Step: Verify the ToggleState of the sub menu",
            TS3_VerifyMainFormSetting(keyName, checkBox, MainForm.ApplicationMenuBar.PreferencesMenu.AutomationElement, subMenu, CheckType.Verification);
        }
Beispiel #38
0
 /// <summary>
 /// Adds a Dial and Number Element with the specified details.
 /// </summary>
 /// <param name="numberToDial">The number to dial.</param>
 /// <param name="digitsToSendAfterConnect">The digits to send after connect.</param>
 /// <param name="numberUrl">The number URL.</param>
 /// <param name="actionUrl">The action URL.</param>
 /// <param name="actionMethod">The action method.</param>
 /// <param name="timeoutSeconds">The timeout seconds.</param>
 /// <param name="hangupOnStar">if set to <c>true</c> [hangup on star].</param>
 /// <param name="timeLimitMilliseconds">The time limit milliseconds.</param>
 /// <param name="statusCallbackUrl">The status callback URL.</param>
 /// <param name="callerIdNumber">The caller id number.</param>
 /// <returns></returns>
 public TwiMLBuilder DialNumber(string numberToDial, string digitsToSendAfterConnect = "", string numberUrl = "",
     string actionUrl = "", ActionMethod actionMethod = ActionMethod.POST, uint timeoutSeconds = 30,
     bool hangupOnStar = false, uint timeLimitMilliseconds = 14400,
     string statusCallbackUrl = "", string callerIdNumber = "")
 {
     return AddVerb(Verb.Dial,
         string.Empty,
         new
         {
             action = actionUrl,
             method = actionMethod,
             timeout = timeoutSeconds,
             hangupOnStar = hangupOnStar,
             timeLimit = timeLimitMilliseconds,
             callerId = callerIdNumber
         },
         Tuple.Create(Verb.Number, numberToDial, (object)new { sendDigits = digitsToSendAfterConnect, url = numberUrl }));
 }
Beispiel #39
0
 /// <summary>
 /// Adds a Dial and Conference Element with the specified details.
 /// </summary>
 /// <param name="conferenceName">Name of the conference.</param>
 /// <param name="participantMuted">if set to <c>true</c> [participant muted].</param>
 /// <param name="beepOnEnterOrExit">if set to <c>true</c> [beep on enter or exit].</param>
 /// <param name="startConferenceOnEnter">if set to <c>true</c> [start conference on enter].</param>
 /// <param name="endConferenceOnExit">if set to <c>true</c> [end conference on exit].</param>
 /// <param name="waitMusicUrl">The wait music URL.</param>
 /// <param name="waitMusicMethod">The wait music method.</param>
 /// <param name="maxParticipants">The max participants.</param>
 /// <param name="actionUrl">The action URL.</param>
 /// <param name="methodUrl">The method URL.</param>
 /// <param name="timeoutSeconds">The timeout seconds.</param>
 /// <param name="hangupOnStar">if set to <c>true</c> [hangup on star].</param>
 /// <param name="timeLimitMilliseconds">The time limit milliseconds.</param>
 /// <param name="statusCallbackUrl">The status callback URL.</param>
 /// <param name="callerIdNumber">The caller id number.</param>
 /// <param name="record">UNDOCUMENTED: Whether to record this conference or not.</param>
 public TwiMLBuilder DialConference(string conferenceName, bool participantMuted = false, bool beepOnEnterOrExit = true, bool startConferenceOnEnter = true, bool endConferenceOnExit = false,
     string waitMusicUrl = "", ActionMethod waitMusicMethod = ActionMethod.POST, uint maxParticipants = 40,
     string actionUrl = "", ActionMethod methodUrl = ActionMethod.POST, uint timeoutSeconds = 30,
     bool hangupOnStar = false, uint timeLimitMilliseconds = 14400,
     string statusCallbackUrl = "", string callerIdNumber = "", bool? record = null)
 {
     return AddVerb(Verb.Dial,
         string.Empty,
         new
         {
             action = actionUrl,
             method = methodUrl,
             timeout = timeoutSeconds,
             hangupOnStar = hangupOnStar,
             timeLimit = timeLimitMilliseconds,
             callerId = callerIdNumber
         },
         Tuple.Create(Verb.Conference,
             conferenceName,
             (object)new
             {
                 muted = participantMuted,
                 beep = beepOnEnterOrExit,
                 startConferenceOnEnter = startConferenceOnEnter,
                 endConferenceOnExit = endConferenceOnExit,
                 waitUrl = waitMusicUrl,
                 waitMethod = waitMusicMethod,
                 record = record
             })
         );
 }
Beispiel #40
0
 /// <summary>
 /// Adds an Sms Element with the specified details.
 /// </summary>
 /// <param name="messageText">The message text.</param>
 /// <param name="toNumber">To number.</param>
 /// <param name="fromNumber">From number.</param>
 /// <param name="actionUrl">The action URL.</param>
 /// <param name="actionMethod">The action method.</param>
 public TwiMLBuilder Sms(string messageText, string toNumber = "", string fromNumber = "",
     string actionUrl = "", ActionMethod actionMethod = ActionMethod.POST)
 {
     return AddVerb(Verb.Sms,
         messageText,
         new
         {
             to = toNumber,
             from = fromNumber,
             action = actionUrl,
             method = actionMethod,
         });
 }
Beispiel #41
0
 /// <summary>
 /// Adds a Redirect Element to the Response.
 /// </summary>
 /// <param name="url">The URL.</param>
 /// <param name="method">The method.</param>
 public TwiMLBuilder Redirect(string url, ActionMethod method = ActionMethod.POST)
 {
     return AddVerb(Verb.Redirect,
         url,
         new
         {
             method = method
         });
 }
Beispiel #42
0
 /// <summary>
 /// Adds a Record Element with the specified details.
 /// </summary>
 /// <param name="actionUrl">The action URL.</param>
 /// <param name="actionMethod">The action method.</param>
 /// <param name="timeoutSeconds">The timeout seconds.</param>
 /// <param name="keyThatFinishes">The key that finishes.</param>
 /// <param name="maxLengthMilliseconds">The max length milliseconds.</param>
 /// <param name="transcribeAudio">if set to <c>true</c> [transcribe audio].</param>
 /// <param name="transcribeCallbackUrl">The transcribe callback URL.</param>
 /// <param name="playBeepBeforeStart">if set to <c>true</c> [play beep before start].</param>
 public TwiMLBuilder Record(string actionUrl = "", ActionMethod actionMethod = ActionMethod.POST, uint timeoutSeconds = 5,
     char keyThatFinishes = '#', uint maxLengthMilliseconds = 3600,
     bool transcribeAudio = false, string transcribeCallbackUrl = "", bool playBeepBeforeStart = true)
 {
     return AddVerb(Verb.Record,
         string.Empty,
         new
         {
             action = actionUrl,
             method = actionMethod,
             timeout = timeoutSeconds,
             finishOnKey = keyThatFinishes,
             maxLength = maxLengthMilliseconds,
             transcribe = transcribeAudio,
             transcribeCallback = transcribeCallbackUrl,
             playBeep = playBeepBeforeStart
         });
 }
Beispiel #43
0
        /// <summary>
        /// Adds a Gather element with a nested say element.
        /// </summary>
        /// <param name="textToSay">The text to say.</param>
        /// <param name="actionUrl">The action URL.</param>
        /// <param name="actionMethod">The action method.</param>
        /// <param name="timeoutSeconds">The timeout seconds.</param>
        /// <param name="keyThatFinishes">The key that finishes.</param>
        /// <param name="numDigitsToCollect">The num digits to collect.</param>
        public TwiMLBuilder GatherWhileSaying(string textToSay, SayVoice voiceSex = SayVoice.man, SayLanguage voiceLanguage = SayLanguage.en, int loopTimes = 1,
            string actionUrl = "", ActionMethod actionMethod = ActionMethod.POST, uint timeoutSeconds = 5,
            char keyThatFinishes = '#', uint numDigitsToCollect = 1000)
        {
            var textChild = Tuple.Create(Verb.Say, textToSay,
                (object)new
                {
                    voice = voiceSex,
                    language = voiceLanguage,
                    loop = loopTimes
                });

            return Gather(actionUrl, actionMethod, timeoutSeconds, keyThatFinishes, numDigitsToCollect, textChild);
        }
 protected CollectionDefinition(Type collectionType, Type itemType, ActionMethod addMethod)
     : base(collectionType, itemType)
 {
     adder = addMethod;
 }
Beispiel #45
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        private void TS_ToggleMainFormSettingsByMenu(
            ActionMethod actionMethod,
            AutomationElement menu,
            GetElement subMenu,
            WaitTestState checkBoxOnCallBack,
            WaitTestState checkBoxOffCallBack,
            CheckType checkType)
        {
            switch (actionMethod)
            {
                case ActionMethod.Menu:
                    {
                        HelperExpandMenuUsingAccessKey(menu, checkType);
                        AutomationElement subMenuItem = subMenu();
                        ToggleState ts = GetMenuToggleState(subMenuItem);
                        HelperInvokeMenuItemUsingAccessKey(subMenuItem, CheckType.Verification);


                        if (ts == ToggleState.Off)
                            Wait(checkBoxOnCallBack, _WAIT_NORMAL_MILLISECONDS, checkType);
                        else
                            Wait(checkBoxOffCallBack, _WAIT_NORMAL_MILLISECONDS, checkType);


                    }
                    break;
                default:
                    throw new ArgumentException();
            }


            m_TestStep++;
        }
Beispiel #46
0
 public MethodAction(ActionMethod actionMethod, bool loop)
     : base()
 {
     m_loop = loop;
     m_actionMethod = actionMethod;
 }
Beispiel #47
0
        /// -------------------------------------------------------------------
        /// <summary>Test step: Close Narrator</summary>
        /// -------------------------------------------------------------------
        void TS_NarratorClose(ActionMethod actionMethod, bool pressYes, CheckType checkType)
        {
            HelperCloseAllDialogs();

            // "Step: Start closing Narrator, which will open the \"Do you want to exit Narrator\" dialog",
            HelperCloseNarrator(actionMethod, pressYes, checkType);

            m_TestStep++;
        }
Beispiel #48
0
        /// -------------------------------------------------------------------
        /// <summary>Test step: Close the application by calling WindowPattern.Close()</summary>
        /// -------------------------------------------------------------------
        void HelperCloseNarrator(ActionMethod actionMethod, bool pressYes, CheckType checkType)
        {
            AutomationElement narrator = MainForm.AutomationElement;

            if (null == narrator)
                return;

            switch (actionMethod)
            {
                case ActionMethod.UIAutomation:
                    {
                        Comment("Closing \"" + narrator.Current.Name + "\" window using WindowPattern.Close()");
                        if (!(bool)narrator.GetCurrentPropertyValue(AutomationElement.IsWindowPatternAvailableProperty))
                            ThrowMe(checkType, "\"" + narrator.Current.Name + "\" window does not support WindowPatternAvailableProperty and should");

                        ((WindowPattern)narrator.GetCurrentPattern(WindowPattern.Pattern)).Close();
                    }
                    break;
                case ActionMethod.KeyPadOnly:
                    {
                        Comment("Closing \"" + narrator.Current.Name + "\" by pressing \"Close\" button");
                        HelperPressButton(MainForm.ButtonExit, ActionMethod.KeyPadOnly, checkType);
                    }
                    break;
                case ActionMethod.CloseXButton:
                    {
                        Comment("Closing \"" + narrator.Current.Name + "\" by pressing \"Alt+F4\" button");
                        HelperPressButton(MainForm.TitleBar.ButtonClose, ActionMethod.MouseClick, checkType);
                    }
                    break;
                case ActionMethod.KillProcess:
                    {
                        Comment("Closing \"" + narrator.Current.Name + "\" by call Process.Kill()");
                        try
                        {
                            Process.GetProcessesByName("Narrator")[0].Kill();
                        }
                        catch (IndexOutOfRangeException)
                        {
                            // There is no process with that name so referencing [0] is invalid
                        }
                    }
                    break;
                case ActionMethod.AltF4:
                    {
                        Comment("Closing \"" + narrator.Current.Name + "\" by pressing \"Alt+F4\" button");
                        Input.SendKeyboardInput(System.Windows.Input.Key.LeftAlt, true);
                        Input.SendKeyboardInput(System.Windows.Input.Key.F4, true);
                        Input.SendKeyboardInput(System.Windows.Input.Key.F4, false);
                        Input.SendKeyboardInput(System.Windows.Input.Key.LeftAlt, false);
                    }
                    break;

                default:
                    ThrowMe(CheckType.Verification, "Incorrect argument");
                    break;
            }


            if (actionMethod != ActionMethod.KillProcess)
            {
                Wait(WaitForExitDialogToBeVisible, _WAIT_NORMAL_MILLISECONDS, checkType);
                HelperCloseExitDialog(ActionMethod.KeyPadOnly, pressYes, checkType);
            }

            // If we closed it, then wait till everything is closed down
            if (pressYes || actionMethod == ActionMethod.KillProcess)
            {
                Wait(WaitForNarratorToBeNotVisible, _WAIT_NORMAL_MILLISECONDS, checkType);
                Wait(WaitForNarratorProcessToCeaseToExists, _WAIT_STARTUP_MILLISECONDS, checkType);
            }
            else
            {
                // nop, we cancelled the dialog
            }

        }
Beispiel #49
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        void TS_HelpDocumentOpen(ActionMethod actionMethod, CheckType checkType)
        {
            switch (actionMethod)
            {
                case ActionMethod.Menu:
                    {
                        Comment("Opening \"Help Document\" by clicking on the menu item");
                        HelperExpandMenuUsingAccessKey(MainForm.ApplicationMenuBar.HelpMenu.AutomationElement, checkType);
                        HelperInvokeMenuItemUsingAccessKey(MainForm.ApplicationMenuBar.HelpMenu.Documentation, CheckType.Verification);
                    }
                    break;
                case ActionMethod.F1:
                    {
                        Comment("Opening \"Help Document\" by pressing F1");
                        Input.SendKeyboardInput(System.Windows.Input.Key.F1, true);
                        Input.SendKeyboardInput(System.Windows.Input.Key.F1, false);
                    }
                    break;
                default:
                    ThrowMe(checkType, "Invalid argument");
                    break;
            }

            Wait(WaitForHelpDocumentDialogToBeVisible, _WAIT_NORMAL_MILLISECONDS, checkType);

            m_TestStep++;
        }
 protected CollectionDefinition(Type collectionType, Type itemType, ActionMethod addMethod)
     : base(collectionType, itemType)
 {
     _adder = addMethod;
     _concreteListType = typeof(List<>).MakeGenericType(itemType);
 }
Beispiel #51
0
        /// -------------------------------------------------------------------
        /// <summary>Test step: Close Exit dialog</summary>
        /// -------------------------------------------------------------------
        private void HelperCloseExitDialog(ActionMethod actionMethod, bool pressYes, CheckType checkType)
        {
            if (pressYes)
            {
                // Step: Press the Yes button
                HelperPressButton(MainForm.DialogExit.ButtonYes, actionMethod, CheckType.Verification);
            }
            else
            {
                // Step: Press the No button
                HelperPressButton(MainForm.DialogExit.ButtonNo, actionMethod, CheckType.Verification);
            }

            // Wait for the dialog to go away
            Wait(WaitForExitDialogToBeNotVisible, _WAIT_NORMAL_MILLISECONDS, checkType);

        }
Beispiel #52
0
        /// <summary>
        /// Adds a Gather Element to the response.
        /// </summary>
        /// <param name="actionUrl">The action URL.</param>
        /// <param name="actionMethod">The action method.</param>
        /// <param name="timeoutSeconds">The timeout seconds.</param>
        /// <param name="keyThatFinishes">The key that finishes collection.</param>
        /// <param name="numDigitsToCollect">The num digits to collect.</param>
        /// <param name="children">The children of this element (Can be Say or Play Elements).</param>
        public TwiMLBuilder Gather(string actionUrl = "", ActionMethod actionMethod = ActionMethod.POST, uint timeoutSeconds = 5,
            char keyThatFinishes = '#', uint numDigitsToCollect = 1000, params Tuple<Verb, string, object>[] children)
        {
            var validChildren = new Tuple<Verb, string, object>[] { };
            if (children != null)
                validChildren = children.Where(x => x.Item1 == Verb.Say || x.Item1 == Verb.Play).ToArray();

            return AddVerb(Verb.Gather,
                    string.Empty,
                    new
                    {
                        action = actionUrl,
                        method = actionMethod,
                        timeout = timeoutSeconds,
                        finishOnKey = keyThatFinishes,
                        numDigits = numDigitsToCollect
                    }, validChildren);
        }
 private DictionaryDefinition(Type collectionType, Type keyType, Type valueType, ActionMethod addMethod)
     : base(collectionType, typeof(KeyValuePair<,>).MakeGenericType(keyType, valueType), addMethod)
 {
     _concreteDictionaryType = typeof(Dictionary<,>).MakeGenericType(keyType, valueType);
 }
 public Transition(ActionMethod actionMethod, State nextState)
 {
     this.ActionMethod = actionMethod;
     this.NextState = nextState;
 }