Esempio n. 1
0
        public Exercise(ILoggerService loggerService, ISpeechService speechService, string name, int setCount, int repetitionCount, IEnumerable<MatcherWithAction> matchersWithActions)
        {
            loggerService.AssertNotNull(nameof(loggerService));
            speechService.AssertNotNull(nameof(speechService));
            name.AssertNotNull(nameof(name));
            matchersWithActions.AssertNotNull(nameof(matchersWithActions));

            if (setCount < 0)
            {
                throw new ArgumentException("setCount cannot be less than zero.", "setCount");
            }

            if (repetitionCount < 0)
            {
                throw new ArgumentException("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);
            }
        }
Esempio n. 2
0
        internal static void VerifyValuesCoverage(this IEnumerable <Enumeration> values, IDictionary <string, int> coverage)
        {
            /* This is a hard exception. If this occurs, we have other problems to contend with.
             * Think it through, there need to be at least One item in the Values array for this
             * to be useful. */

            // ReSharper disable once InconsistentNaming
            var __values = values.AssertNotNull().AssertNotEmpty().ToArray();

            try
            {
                // Then, we expect each of the Values to be Evaluated.
                __values.AssertEqual(coverage.Count, x => x.Length);

                // Each of the Values shall be Evaluated at least Once.
                coverage.Values.AssertTrue(x => x.All(count => count > 0));
            }
            catch (Exception ex)
            {
                // TODO: TBD: Assert inconclusive how? i.e. NUnit provides Assert.Inconclusive(...).
                var incomplete = __values.Select(x => x.Name).Except(coverage.Keys)
                                 .Aggregate(Empty, (g, x) => IsNullOrEmpty(g) ? $"'{x}'" : $"{g}, '{x}'");

                // TODO: TBD: for lack of a better way of signaling, just throw the IOEX here...
                throw new InvalidOperationException($"Incomplete test coverage: [ {incomplete} ]", ex);
            }
        }
Esempio n. 3
0
        public IList <LibraryReference> Distinct(IEnumerable <LibraryReference> references)
        {
            references.AssertNotNull(nameof(references));

            var result = new Dictionary <LibraryId, LibraryReference>();

            foreach (var reference in references)
            {
                var key = reference.Id;
                if (!result.TryGetValue(key, out var existing))
                {
                    result.Add(key, reference);
                }
                else
                {
                    var shouldCombineFrameworks = ShouldCombine(existing.TargetFrameworks, reference.TargetFrameworks);
                    var shouldCombineInternal   = existing.IsInternal != reference.IsInternal;

                    if (shouldCombineFrameworks || shouldCombineInternal)
                    {
                        var targetFrameworks = shouldCombineFrameworks ? existing.TargetFrameworks.Union(reference.TargetFrameworks, StringComparer.OrdinalIgnoreCase).ToArray() : existing.TargetFrameworks;
                        var isInternal       = existing.IsInternal && reference.IsInternal;

                        result[key] = new LibraryReference(
                            key,
                            targetFrameworks,
                            existing.Dependencies.Union(reference.Dependencies).ToArray(),
                            isInternal);
                    }
                }
            }

            return(new List <LibraryReference>(result.Values));
        }
        public static TResult SelectLast <TSource, TResult>(this IEnumerable <TSource> source, Func <TSource, TResult> selector)
        {
            source.AssertNotNull("source");
            selector.AssertNotNull("selector");

            return(source.Select(selector).LastOrDefault());
        }
        public static IEnumerable <OuterLinqJoinResult <TOuter, TInner> > LeftJoin <TOuter, TInner, TKey>(this IEnumerable <TOuter> outer, IEnumerable <TInner> inner, Func <TOuter, TKey> outerKeySelector, Func <TInner, TKey> innerKeySelector, IEqualityComparer <TKey> comparer)
        {
            inner.AssertNotNull("outer");
            outer.AssertNotNull("outer");

            return
                (outer
                 .GroupJoin
                 (
                     inner,
                     outerKeySelector,
                     innerKeySelector,
                     (x, y) =>
                     new
            {
                LeftPart = x,
                RightPart = y
            },
                     comparer
                 )
                 .SelectMany
                 (
                     x => x.RightPart.DefaultIfEmpty(),
                     (x, y) =>
                     new OuterLinqJoinResult <TOuter, TInner>
            {
                LeftPart = x.LeftPart,
                RightPart = y
            }
                 ));
        }
 public Task <bool> IsInAllRolesAsync(Requester requester, IEnumerable <string> roles)
 {
     requester.AssertNotNull("requester");
     roles.AssertNotNull("roles");
     roles = this.CheckRoles(roles);
     return(Task.FromResult(roles.Where(v => v != null).All(requester.IsInRole)));
 }
Esempio n. 7
0
        public Exercise(ILoggerService loggerService, ISpeechService speechService, string name, int setCount, int repetitionCount, IEnumerable <MatcherWithAction> matchersWithActions)
        {
            loggerService.AssertNotNull(nameof(loggerService));
            speechService.AssertNotNull(nameof(speechService));
            name.AssertNotNull(nameof(name));
            matchersWithActions.AssertNotNull(nameof(matchersWithActions));

            if (setCount < 0)
            {
                throw new ArgumentException("setCount cannot be less than zero.", "setCount");
            }

            if (repetitionCount < 0)
            {
                throw new ArgumentException("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);
            }
        }
Esempio n. 8
0
 public void RegisterAllDefinitions(IEnumerable <IDialogDefinition> definitions)
 {
     definitions.AssertNotNull(nameof(definitions));
     foreach (var definition in definitions)
     {
         RegisterDialogDefinition(definition);
     }
 }
Esempio n. 9
0
        public static string BuildUsedBy(IEnumerable <PackageApplication> usedBy)
        {
            usedBy.AssertNotNull(nameof(usedBy));

            var list = usedBy.Select(i => i.InternalOnly ? i.Name + " internal" : i.Name).OrderBy(i => i);

            return(string.Join(", ", list));
        }
Esempio n. 10
0
            /// <summary>
            /// Initializes a new instance of the <see cref="OfferLogoMatcher"/> class.
            /// </summary>
            /// <param name="keywords">The keywords to match the offer product name against.</param>
            /// <param name="logo">The offer logo to use in case of a match.</param>
            public OfferLogoMatcher(IEnumerable <string> keywords, string logo)
            {
                keywords.AssertNotNull(nameof(keywords));
                logo.AssertNotEmpty("logo URI can't be empty");

                this.logo     = logo;
                this.keywords = new List <string>(keywords);
            }
Esempio n. 11
0
 public static IEnumerable <object> ToGenericEnumerable(this IEnumerable collection)
 {
     collection.AssertNotNull("Enumeration");
     foreach (var element in collection)
     {
         yield return(element);
     }
 }
Esempio n. 12
0
        public SqlQueryBuilder Select(IEnumerable <SelectField> fields)
        {
            fields.AssertNotNull(nameof(fields));

            fields        = fields.Select(x => new SelectField(DAOHelper.EscapeField(x.Field), x.Alias));
            _selectFields = fields;
            return(this);
        }
Esempio n. 13
0
        public void AssertNotNullOnNullEnumerableThrowsArgumentNullException()
        {
            IEnumerable sut = null;

            var ex = Assert.Throws <ArgumentNullException>(() => sut.AssertNotNull(true, "sut"));

            Assert.Equal("sut", ex.ParamName);
        }
Esempio n. 14
0
 public static void ForEach <T>(this IEnumerable <T> collection, Action <T> action)
 {
     action.AssertParameterNotNull(nameof(action));
     foreach (var element in collection.AssertNotNull("Enumeration"))
     {
         action(element);
     }
 }
Esempio n. 15
0
 public static IReadOnlyList <TRes> SelectToReadOnlyList <T, TRes>(this IEnumerable <T> source, Func <T, TRes> mapper)
 {
     if (source is IReadOnlyList <T> list)
     {
         return(SelectToReadOnlyList(list, mapper));
     }
     return(source.AssertNotNull($"\"{nameof(source)}\" cannot be null").Select(mapper).ToList());
 }
Esempio n. 16
0
        private void Initialize(IEnumerable <Tuple <TKey, IEnumerable <TValue> > > data)
        {
            data.AssertNotNull(nameof(data));

            foreach (var item in data)
            {
                _dict.Add(item.Item1, new EnumeratorWrapper <TValue>(item.Item2.ToEmptyIfNull()));
            }
        }
Esempio n. 17
0
        public static void AssertAreNotNull <T>(this IEnumerable <T> me)
        {
            me.AssertNotNull();

            foreach (var item in me)
            {
                item.AssertNotNull();
            }
        }
Esempio n. 18
0
        public void AddRange(IEnumerable <T> items)
        {
            items.AssertNotNull(nameof(items));

            foreach (var item in items)
            {
                Add(item);
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Writes a record to this <c>CsvWriter</c>.
        /// </summary>
        /// <remarks>
        /// Any <see langword="null"/> values will be written as empty strings.
        /// </remarks>
        /// <param name="values">
        /// The values comprising the record.
        /// </param>
        public void WriteRecord(IEnumerable <string> values)
        {
            Debug.Assert(this.bufferBuilder.Length == 0, "Expecting buffer to be empty.");

            this.EnsureNotDisposed();
            values.AssertNotNull("values");
            this.WriteRecordToBuffer(values);
            this.FlushBufferToTextWriter();
        }
Esempio n. 20
0
        /// <summary>
        /// Asynchronously writes a record to this <c>CsvWriter</c>.
        /// </summary>
        /// <remarks>
        /// None of the <see cref="System.String"/>s within <paramref name="values"/> can be <see langword="null"/>. If so, an exception will be thrown.
        /// </remarks>
        /// <param name="values">
        /// The values comprising the record.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> representing the asynchronous operation.
        /// </returns>
        public async Task WriteRecordAsync(IEnumerable<string> values)
        {
            Debug.Assert(this.bufferBuilder.Length == 0, "Expecting buffer to be empty.");

            this.EnsureNotDisposed();
            values.AssertNotNull("values");
            this.WriteRecordToBuffer(values);
            await this.FlushBufferToTextWriterAsync().ConfigureAwait(false);
        }
Esempio n. 21
0
        /// <summary>
        /// Asynchronously writes a record to this <c>CsvWriter</c>.
        /// </summary>
        /// <remarks>
        /// None of the <see cref="System.String"/>s within <paramref name="values"/> can be <see langword="null"/>. If so, an exception will be thrown.
        /// </remarks>
        /// <param name="values">
        /// The values comprising the record.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> representing the asynchronous operation.
        /// </returns>
        public async Task WriteRecordAsync(IEnumerable <string> values)
        {
            Debug.Assert(this.bufferBuilder.Length == 0, "Expecting buffer to be empty.");

            this.EnsureNotDisposed();
            values.AssertNotNull("values");
            this.WriteRecordToBuffer(values);
            await this.FlushBufferToTextWriterAsync().ConfigureAwait(false);
        }
Esempio n. 22
0
        public static void PushAll <T>(this Stack <T> stack, IEnumerable <T> items)
        {
            stack.AssertNotNull(nameof(stack));
            items.AssertNotNull(nameof(items));

            foreach (T item in items)
            {
                stack.Push(item);
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Creates a new NetNode with the specified fields.
        /// </summary>
        /// <param name="guid">The unique Id for the computer.</param>
        /// <param name="name">The user friendly name for the computer.</param>
        /// <param name="uri">The computer's Uri, if it has one.</param>
        /// <param name="edges">Edges from this computer to others.</param>
        public NetNode(Guid guid, string name, Uri uri, IEnumerable <INetEdge> edges)
        {
            guid.AssertNotNull(nameof(guid));
            name.AssertNotNullOrEmptyOrWhitespace(nameof(name));
            edges.AssertNotNull(nameof(edges));

            this.guid  = guid;
            this.name  = name;
            this.edges = edges.ToImmutableDictionary(edge => edge.Destination.Guid, edge => edge);
        }
Esempio n. 24
0
        public MetronomeAction(IAudioService audioService, IDelayService delayService, ILoggerService loggerService, IEnumerable <MetronomeTick> ticks)
        {
            audioService.AssertNotNull(nameof(audioService));
            delayService.AssertNotNull(nameof(delayService));
            loggerService.AssertNotNull(nameof(loggerService));
            ticks.AssertNotNull(nameof(ticks));

            this.ticks       = ticks.ToImmutableList();
            this.innerAction = new SequenceAction(GetInnerActions(audioService, delayService, loggerService, this.ticks));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AuthenticationParameters" /> class.
        /// </summary>
        protected AuthenticationParameters(MgmtAccount account, MgmtEnvironment environment, IEnumerable <string> scopes)
        {
            account.AssertNotNull(nameof(account));
            environment.AssertNotNull(nameof(environment));
            scopes.AssertNotNull(nameof(scopes));

            Account     = account;
            Environment = environment;
            Scopes      = scopes;
        }
Esempio n. 26
0
 public static IEnumerable <T> ExcludeDefaultValues <T>(this IEnumerable <T> collection)
 {
     foreach (var element in collection.AssertNotNull("Enumeration"))
     {
         if (!EqualityComparer <T> .Default.Equals(element, default(T)))
         {
             yield return(element);
         }
     }
 }
Esempio n. 27
0
        public static ObservableCollection <T> ToObservableCollection <T>(this IEnumerable <T> collection)
        {
            var observableCollection = new ObservableCollection <T>();

            foreach (var element in collection.AssertNotNull("Enumeration"))
            {
                observableCollection.Add(element);
            }
            return(observableCollection);
        }
Esempio n. 28
0
        public static Stack <T> ToStack <T>(this IEnumerable <T> collection)
        {
            var stack = new Stack <T>();

            foreach (var element in collection.AssertNotNull("Enumeration"))
            {
                stack.Push(element);
            }
            return(stack);
        }
Esempio n. 29
0
        public static Queue <T> ToQueue <T>(this IEnumerable <T> collection)
        {
            var queue = new Queue <T>();

            foreach (var element in collection.AssertNotNull("Enumeration"))
            {
                queue.Enqueue(element);
            }
            return(queue);
        }
Esempio n. 30
0
        /// <summary>
        /// Creates a new NetNode with the specified fields.
        /// </summary>
        /// <param name="guid">The unique Id for the computer.</param>
        /// <param name="name">The user friendly name for the computer.</param>
        /// <param name="uri">The computer's Uri, if it has one.</param>
        /// <param name="edges">Edges from this computer to others.</param>
        public NetNode(Guid guid, string name, Uri uri, IEnumerable<INetEdge> edges)
        {
            guid.AssertNotNull(nameof(guid));
            name.AssertNotNullOrEmptyOrWhitespace(nameof(name));
            edges.AssertNotNull(nameof(edges));

            this.guid = guid;
            this.name = name;
            this.edges = edges.ToImmutableDictionary(edge => edge.Destination.Guid, edge => edge);
        }
        public MetronomeAction(IAudioService audioService, IDelayService delayService, ILoggerService loggerService, IEnumerable<MetronomeTick> ticks)
        {
            audioService.AssertNotNull(nameof(audioService));
            delayService.AssertNotNull(nameof(delayService));
            loggerService.AssertNotNull(nameof(loggerService));
            ticks.AssertNotNull(nameof(ticks));

            this.ticks = ticks.ToImmutableList();
            this.innerAction = new SequenceAction(GetInnerActions(audioService, delayService, loggerService, this.ticks));
        }
Esempio n. 32
0
 public static bool IsSingleElement <T>(this IEnumerable <T> collection)
 {
     collection.AssertNotNull(nameof(collection));
     if (collection is ICollection list)
     {
         return(list.Count == 1);
     }
     using (var iter = collection.GetEnumerator()) {
         return(iter.MoveNext() && !iter.MoveNext());
     }
 }
        public ParallelAction(IEnumerable<IAction> children)
        {
            children.AssertNotNull(nameof(children), assertContentsNotNull: true);

            this.children = children.ToImmutableList();
            this.duration = this
                .children
                .Select(x => x.Duration)
                .DefaultIfEmpty()
                .Max();
        }
        public static IList <Tuple <TResult> > ToTupleList <TSource, TResult>(this IEnumerable <TSource> source, Func <TSource, TResult> selector)
        {
            source.AssertNotNull("source");
            selector.AssertNotNull("selector");

            return
                (source
                 .ToEmptyIfNull()
                 .Select(x => new Tuple <TResult>(selector(x)))
                 .ToList());
        }
        public SequenceAction(IEnumerable <IAction> children)
        {
            children.AssertNotNull(nameof(children), assertContentsNotNull: true);

            this.children = children.ToImmutableList();
            this.duration = this
                            .children
                            .Select(x => x.Duration)
                            .DefaultIfEmpty()
                            .Aggregate((running, next) => running + next);
        }
Esempio n. 36
0
        /// <summary>
        /// Creates a new NetGraph representation from raw data.
        /// </summary>
        /// <param name="nodes">
        /// A list of all nodes. The first node is assumed to be this computer.
        /// </param>
        private NetGraph(IEnumerable<INetNode> nodes)
        {
            nodes.AssertNotNull(nameof(nodes));

            if (nodes.FirstOrDefault() != null)
            {
                this.thisNode = nodes.First();
            }

            this.nodes = nodes.ToImmutableDictionary(edge => edge.Guid, edge => edge);
        }
        public SequenceAction(IEnumerable<IAction> children)
        {
            children.AssertNotNull(nameof(children), assertContentsNotNull: true);

            this.children = children.ToImmutableList();
            this.duration = this
                .children
                .Select(x => x.Duration)
                .DefaultIfEmpty()
                .Aggregate((running, next) => running + next);
        }
Esempio n. 38
0
        public IRace Create(IDistanceCalculator distanceCalculator, IEnumerable<Waypoint> waypoints)
        {
          
                distanceCalculator.AssertNotNull();
                waypoints = waypoints as List<Waypoint> ?? waypoints.ToList();
                waypoints.AssertNotEmpty();
                waypoints.AssertNotNull();

                var Race = new RaceService(distanceCalculator, waypoints);
                return Race;
  
            
        }
Esempio n. 39
0
        /// <summary>
        /// Determines whether the principal contains the specified claims.
        /// </summary>
        /// <param name="principal">The principal.</param>
        /// <param name="claims">The claims.</param>
        /// <returns><c>true</c> if the principal contains the specified claims; otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="claims"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException">
        /// One of the items in the <paramref name="claims"/> collection is <see langword="null"/>.
        /// </exception>
        public static bool HasClaims(this ClaimsPrincipal principal, IEnumerable<Claim> claims)
        {
            claims.AssertNotNull(true, "claims");

            foreach (var claim in claims)
            {
                if (!principal.HasClaim(claim.Type, claim.Value))
                {
                    return false;
                }
            }

            return true;
        }
Esempio n. 40
0
        /// <summary>
        /// Determines whether the principal contains the specified claim types.
        /// </summary>
        /// <param name="principal">The principal.</param>
        /// <param name="claimTypes">The claim types.</param>
        /// <returns>
        /// <c>true</c> if the principal contains the specified claim types; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="claimTypes"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// One of the items in the <paramref name="claimTypes"/> collection is <see langword="null"/>.
        /// </exception>
        public static bool HasClaimTypes(this ClaimsPrincipal principal, IEnumerable<string> claimTypes)
        {
            claimTypes.AssertNotNull(true, "claimTypes");

            foreach (var type in claimTypes)
            {
                if (!principal.HasClaim(c => c.Type == type))
                {
                    return false;
                }
            }

            return true;
        }
        public ExerciseProgram(ILoggerService loggerService, string name, IEnumerable<Exercise> exercises)
        {
            loggerService.AssertNotNull(nameof(loggerService));
            name.AssertNotNull(nameof(name));
            exercises.AssertNotNull(nameof(exercises), assertContentsNotNull: true);

            this.logger = loggerService.GetLogger(this.GetType());
            this.name = name;
            this.exercises = exercises.ToImmutableList();
            this.duration = this
                .exercises
                .Select(x => x.Duration)
                .DefaultIfEmpty()
                .Aggregate((running, next) => running + next);
        }
 public JsonSyntaxNode(IEnumerable<JsonSyntaxNode> children)
 {
     children.AssertNotNull();
     this.children = new ReadOnlyCollection<JsonSyntaxNode>(children.ToList());
 }
 public ExercisePrograms(IEnumerable<ExerciseProgram> programs)
 {
     programs.AssertNotNull(nameof(programs), assertContentsNotNull: true);
     this.programs = programs.ToImmutableList();
 }
Esempio n. 44
0
        /// <summary>
        /// Initializes a new instance of the HeaderRecord class.
        /// </summary>
        /// <param name="columnNames">
        /// The names of the columns in the header record.
        /// </param>
        /// <param name="readOnly">
        /// <see langword="true"/> if the header record is read-only, otherwise <see langword="false"/>.
        /// </param>
        public HeaderRecord(bool readOnly, IEnumerable<string> columnNames)
            : base(readOnly, columnNames)
        {
            columnNames.AssertNotNull("columnNames", true);

            this.columnNameToIndexMap = new Dictionary<string, int>();
            this.PopulateColumnNameToIndexMap(0, true);

            if (readOnly)
            {
                this.columnNameToIndexMap = new ReadOnlyDictionary<string, int>(this.columnNameToIndexMap);
            }
        }
Esempio n. 45
0
        /// <summary>
        /// Writes a record to this <c>CsvWriter</c>.
        /// </summary>
        /// <remarks>
        /// Any <see langword="null"/> values will be written as empty strings.
        /// </remarks>
        /// <param name="values">
        /// The values comprising the record.
        /// </param>
        public void WriteRecord(IEnumerable<string> values)
        {
            Debug.Assert(this.bufferBuilder.Length == 0, "Expecting buffer to be empty.");

            this.EnsureNotDisposed();
            values.AssertNotNull("values");
            this.WriteRecordToBuffer(values);
            this.FlushBufferToTextWriter();
        }