示例#1
0
        public void argument_condition_throws_if_condition_does_not_hold(string message, string argumentName)
        {
            var ex = Assert.Throws <ArgumentException>(() => Ensure.ArgumentCondition(false, message, argumentName));

            Assert.StartsWith(message, ex.Message);
            Assert.Equal(argumentName, ex.ParamName);
        }
示例#2
0
        public Exercise(ILoggerService loggerService, ISpeechService speechService, string name, int setCount, int repetitionCount, IEnumerable <MatcherWithAction> matchersWithActions)
        {
            Ensure.ArgumentNotNull(loggerService, nameof(loggerService));
            Ensure.ArgumentNotNull(speechService, nameof(speechService));
            Ensure.ArgumentNotNull(name, nameof(name));
            Ensure.ArgumentNotNull(matchersWithActions, nameof(matchersWithActions));
            Ensure.ArgumentCondition(setCount >= 0, "setCount cannot be less than zero.", "setCount");
            Ensure.ArgumentCondition(repetitionCount >= 0, "repetitionCount cannot be less than zero.", "repetitionCount");

            this.logger              = loggerService.GetLogger(this.GetType());
            this.speechService       = speechService;
            this.name                = name;
            this.setCount            = setCount;
            this.repetitionCount     = repetitionCount;
            this.matchersWithActions = matchersWithActions.ToImmutableList();

            using (var dummyExecutionContext = new ExecutionContext())
            {
                this.duration = this
                                .GetEventsWithActions(dummyExecutionContext)
                                .SelectMany(x => x.Actions)
                                .Select(x => x.Duration)
                                .DefaultIfEmpty()
                                .Aggregate((running, next) => running + next);
            }
        }
示例#3
0
        protected NumberedEvent(ExecutionContext executionContext, int number)
            : base(executionContext)
        {
            Ensure.ArgumentCondition(number >= 0, "number must be greater than or equal to zero.", "number");

            this.number = number;
        }
        public async Task <bool> SetUrl(string url, int networkId = 1)
        {
            Ensure.ArgumentCondition(Nethereum.UI.Util.Utils.IsValidUrl(url), "Invalid url", "Url");
            var web3 = new Web3.Web3(url);

            try
            {
                var blockNumber = await web3.Eth.Blocks.GetBlockNumber.SendRequestAsync();

                Url             = url;
                SelectedNetwork = networkId;

                if (NetworkChanged != null)
                {
                    await NetworkChanged(networkId);
                }

                _enabledCallback.OnNext(Enabled);
                return(true);
            }
            catch // toasts and other stuff
            {
                Url = null;
                _enabledCallback.OnNext(Enabled);
                return(false);
            }
        }
示例#5
0
        public WaitAction(IDelayService delayService, TimeSpan delay)
        {
            Ensure.ArgumentNotNull(delayService, nameof(delayService));
            Ensure.ArgumentCondition(delay >= TimeSpan.Zero, "delay must be greater than or equal to zero.", nameof(delay));

            this.delayService = delayService;
            this.delay        = delay;
        }
        public Task <string> SignMessageAsync(string message)
        {
            Ensure.ArgumentCondition(!string.IsNullOrEmpty(message), "message cannot be null", nameof(message));
            var signer        = new EthereumMessageSigner();
            var signedMessage = signer.EncodeUTF8AndSign(message, new EthECKey(((Web3.Accounts.Account)Account).PrivateKey));

            return(Task.FromResult(signedMessage));
        }
示例#7
0
        public WaitWithPromptAction(IDelayService delayService, ISpeechService speechService, TimeSpan duration, string promptSpeechText)
        {
            Ensure.ArgumentNotNull(delayService, nameof(delayService));
            Ensure.ArgumentNotNull(speechService, nameof(speechService));
            Ensure.ArgumentNotNull(promptSpeechText, nameof(promptSpeechText));
            Ensure.ArgumentCondition(duration >= TimeSpan.Zero, "duration must be greater than or equal to zero.", nameof(duration));

            this.innerAction = new SequenceAction(GetInnerActions(delayService, speechService, duration, promptSpeechText));
        }
示例#8
0
            public void ThrowsExceptionWhenConditionIsFalse()
            {
                bool   condition = false;
                string msg       = "error message";

                Action act = () => Ensure.ArgumentCondition(condition, nameof(condition), msg);

                Assert.Throws <ArgumentException>(act);
            }
示例#9
0
        public static Parser <ParallelAction> GetParser(
            int indentLevel,
            IAudioService audioService,
            IDelayService delayService,
            ISpeechService speechService)
        {
            Ensure.ArgumentCondition(indentLevel >= 0, "indentLevel must be greater than or equal to 0.", "indentLevel");
            Ensure.ArgumentNotNull(audioService, nameof(audioService));
            Ensure.ArgumentNotNull(delayService, nameof(delayService));
            Ensure.ArgumentNotNull(speechService, nameof(speechService));

            return
                (from _ in Parse.IgnoreCase("parallel:")
                 from __ in VerticalSeparationParser.Parser.AtLeastOnce()
                 from actions in ActionListParser.GetParser(indentLevel + 1, audioService, delayService, speechService)
                 select new ParallelAction(actions));
        }
示例#10
0
        public static Parser <IEnumerable <IAction> > GetParser(
            int indentLevel,
            IAudioService audioService,
            IDelayService delayService,
            ISpeechService speechService)
        {
            Ensure.ArgumentCondition(indentLevel >= 0, "indentLevel must be greater than or equal to 0.", "indentLevel");
            Ensure.ArgumentNotNull(audioService, nameof(audioService));
            Ensure.ArgumentNotNull(delayService, nameof(delayService));
            Ensure.ArgumentNotNull(speechService, nameof(speechService));

            return
                ((from _ in Parse.String("  ").Or(Parse.String("\t")).Repeat(indentLevel)
                  from __ in Parse.String("* ")
                  from action in ActionParser.GetParser(indentLevel, audioService, delayService, speechService).Token(HorizontalWhitespaceParser.Parser)
                  select action).DelimitedBy(NewLineParser.Parser));
        }
示例#11
0
        public static Parser <IAction> GetParser(
            int indentLevel,
            IAudioService audioService,
            IDelayService delayService,
            ISpeechService speechService)
        {
            Ensure.ArgumentCondition(indentLevel >= 0, "indentLevel must be greater than or equal to 0.", "indentLevel");
            Ensure.ArgumentNotNull(audioService, nameof(audioService));
            Ensure.ArgumentNotNull(delayService, nameof(delayService));
            Ensure.ArgumentNotNull(speechService, nameof(speechService));

            return(BreakActionParser.GetParser(delayService, speechService)
                   .Or <IAction>(MetronomeActionParser.GetParser(audioService, delayService))
                   .Or <IAction>(PrepareActionParser.GetParser(delayService, speechService))
                   .Or <IAction>(SayActionParser.GetParser(speechService))
                   .Or <IAction>(WaitActionParser.GetParser(delayService))
                   .Or <IAction>(DoNotAwaitActionParser.GetParser(indentLevel, audioService, delayService, speechService))
                   .Or <IAction>(ParallelActionParser.GetParser(indentLevel, audioService, delayService, speechService))
                   .Or <IAction>(SequenceActionParser.GetParser(indentLevel, audioService, delayService, speechService)));
        }
        public static IObservable <T> ErrorWithProbabilityIf <T>(this IObservable <T> src, bool enableRandomErrors, int percent)
        {
            Ensure.ArgumentCondition(percent >= 0, "percent must be greater than or equal to zero.", nameof(percent));
            Ensure.ArgumentCondition(percent <= 100, "percent must be less than or equal to one hundred.", nameof(percent));

            if (enableRandomErrors)
            {
                if (Random.Next(0, 100) < percent)
                {
                    return(Observable.Throw <T>(new DisconnectedErrorException($"Sequence failed due to {percent}% chance of failure.")));
                }
                else
                {
                    return(src);
                }
            }
            else
            {
                return(src);
            }
        }
        public static Parser <DoNotAwaitAction> GetParser(
            int indentLevel,
            IAudioService audioService,
            IDelayService delayService,
            ISpeechService speechService)
        {
            Ensure.ArgumentCondition(indentLevel >= 0, "indentLevel must be greater than or equal to 0.", "indentLevel");
            Ensure.ArgumentNotNull(audioService, nameof(audioService));
            Ensure.ArgumentNotNull(delayService, nameof(delayService));
            Ensure.ArgumentNotNull(speechService, nameof(speechService));

            return
                (from _ in Parse.IgnoreCase("don't")
                 from __ in HorizontalWhitespaceParser.Parser.AtLeastOnce()
                 from ___ in Parse.IgnoreCase("wait:")
                 from ____ in VerticalSeparationParser.Parser.AtLeastOnce()
                 from actions in ActionListParser.GetParser(indentLevel + 1, audioService, delayService, speechService)
                 let child = new SequenceAction(actions)
                             select new DoNotAwaitAction(
                     child));
        }
示例#14
0
 public void argument_condition_does_not_throw_if_condition_holds()
 {
     Ensure.ArgumentCondition(true, "message", "whatever");
 }