private void UpdateIcon(BambooPlan plan)
        {
            switch (plan.BuildState)
            {
            case BuildState.Failed:
                IconSource = new Uri("pack://application:,,,/Images/bamboo-failed.ico");
                break;

            case BuildState.Successful:
                if (_bambooPlans.All(x => x.Value.BuildState == BuildState.Successful))
                {
                    IconSource = new Uri("pack://application:,,,/Images/bamboo-successful.ico");
                }
                break;

            case BuildState.Unknown:
                if (_bambooPlans.All(x => x.Value.BuildState == BuildState.Unknown))
                {
                    IconSource = new Uri("pack://application:,,,/Images/bamboo.ico");
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #2
0
 protected override string Part1(string input)
 {
     return(ParseInput(input)
            .Count(p =>
                   PassportFields.All(f => p.Select(e => e.Key).Contains(f.Key))
                   )
            .ToString());
 }
Exemple #3
0
 public bool RepresentationIsRenaming(IDictionary <VCExprVar /*!*/, VCExprVar /*!*/> /*!*/ globalVars)
 {
     Contract.Requires(cce.NonNullDictionaryAndValues(globalVars));
     if (!Representation.Any(pair => pair.Key.Expr0 is VCExprVar && pair.Key.Expr1 is VCExprVar && !globalVars.ContainsKey(cce.NonNull((VCExprVar)pair.Key.Expr0)) && !globalVars.ContainsKey(cce.NonNull((VCExprVar /*!*/)pair.Key.Expr1))))
     {
         return(false);
     }
     // check that all substituted variables are distinct
     // TODO: optimise
     return
         (Representation.All(pair1 => Representation.All(pair2 => pair1.Value.Equals(pair2.Value) || !pair1.Key.Expr0.Equals(pair2.Key.Expr0) && !pair1.Key.Expr1.Equals(pair2.Key.Expr1))));
 }
Exemple #4
0
        /// <summary>
        ///     remove the 'root' portion of each given key
        /// </summary>
        /// <param name="keys"></param>
        /// <param name="root"></param>
        /// <returns></returns>
        private IResult <IDictionary <string, string> > RemoveRoot(IDictionary <string, string> keys, string root)
        {
            try
            {
                _logger.LogDebug($"attempting to remove root '{root}' from '{keys.Count}' items");

                if (!root.EndsWith('/'))
                {
                    _logger.LogDebug("appending '/' to root, to make results uniform");
                    root += '/';
                }

                // if every item passes the check for the same root
                // project each item into a new dict with the modified Key
                if (keys.All(k => k.Key.StartsWith(root, StringComparison.OrdinalIgnoreCase)))
                {
                    _logger.LogDebug($"all keys start with given root '{root}', re-rooting possible");
                    return(Result.Success((IDictionary <string, string>)keys.ToDictionary(kvp => kvp.Key.Substring(root.Length),
                                                                                          kvp => kvp.Value,
                                                                                          StringComparer.OrdinalIgnoreCase)));
                }

                _logger.LogDebug($"could not remove root '{root}' from all entries - not all items share same root");
                return(Result.Error <IDictionary <string, string> >($"could not remove root '{root}' from all entries - not all items share same root",
                                                                    ErrorCode.InvalidData));
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"could not remove root '{root}' from all entries");
                return(Result.Error <IDictionary <string, string> >($"could not remove root '{root}' from all entries", ErrorCode.Undefined));
            }
        }
        public bool CanMakeChange(IEnumerable <Coin> vault)
        {
            /*
             * So, I could spend ages working out an algorithm to work this problem out
             * for the generic case, or we can hard code a suboptimal solution that lets me
             * ship today.
             *
             * TODO: Replace with smarter algorithm.
             * Perhaps create a fallback algorithm for the CalculateRefund method,
             * or change it entirely to use the Greedy algorithm.
             *
             * See Issues #6 & #14
             */

            IDictionary <Coin, int> coinCounts = EmptyCoinDictionary();

            foreach (var coin in vault)
            {
                switch (coin)
                {
                case Coin.Nickel:
                case Coin.Dime:
                case Coin.Quarter:
                    coinCounts[coin]++;
                    break;

                default:
                    //do nothing with unsupported coins
                    break;
                }
            }

            return(coinCounts.All(count => count.Value >= 5));
        }
 public static bool ContainsAllTags(ObjectivesResultsCollection x, IDictionary<string, string> tags)
 {
     var xTags = x.Tags.Tags;
     return tags.All((dictTag =>
         (xTags.Any((xTag =>
             (dictTag.Key == xTag.Name && dictTag.Value == xTag.Value))))));
 }
Exemple #7
0
        /// <summary>
        ///     Checks if two dictionaries are equal
        /// </summary>
        /// <typeparam name="TKey">Key type</typeparam>
        /// <typeparam name="TValue">Value type</typeparam>
        /// <param name="first">First dictionary</param>
        /// <param name="second">Second dictionary</param>
        /// <returns>True if two dictionaries are same, false otherwise</returns>
        /// <exception cref="NullReferenceException">first is null</exception>
        /// <remarks>
        ///     It throws if first paramether is null. To get 'true' when both values are null do
        ///     <code>
        /// bool equals = first?.DictEquals(second) ?? RefenceEquals(first, second);
        /// </code>
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="collection" /> is null.
        /// </exception>
        public static bool DictEquals <TKey, TValue>(this IDictionary <TKey, TValue> first, IDictionary <TKey, TValue> second)
        {
            if (first == null)
            {
                throw new NullReferenceException();
            }

            if (second == null)
            {
                return(false);
            }

            if (ReferenceEquals(first, second))
            {
                return(true);
            }

            if (first.Count != second.Count)
            {
                return(false);
            }

            var hash = new HashSet <KeyValuePair <TKey, TValue> >(first);

            return(second.All(pair => hash.Contains(pair)));
        }
        private void ParseResponses(IDictionary <string, ApiObject> objects, KeyValuePair <string, ResourceType> type, Verb verb)
        {
            if (verb.Responses == null)
            {
                return;
            }

            foreach (var response in verb.Responses.Where(response => response != null))
            {
                var name = Enum.GetName(typeof(VerbType), verb.Type);
                if (name == null)
                {
                    continue;
                }

                var key = type.Key + "-" + name.ToLower() + ParserHelpers.GetStatusCode(response.Code) + ResponseContentSuffix;

                if (response.Body == null || !response.Body.Any(b => b.Value != null && !string.IsNullOrWhiteSpace(b.Value.Schema)))
                {
                    continue;
                }

                var mimeType = GeneratorServiceHelper.GetMimeType(response);

                var obj = objectParser.ParseObject(key, mimeType.Schema, objects, warnings);
                // Avoid duplicated keys and names
                if (obj != null && !objects.ContainsKey(key) && objects.All(o => o.Value.Name != obj.Name) && obj.Properties.Any())
                {
                    objects.Add(key, obj);
                }
            }
        }
        private void ParseResourceResponsesRecursively(IDictionary <string, ApiObject> objects, IEnumerable <Resource> resources)
        {
            foreach (var resource in resources)
            {
                if (resource.Methods != null)
                {
                    foreach (var method in resource.Methods.Where(m => m.Responses != null && m.Responses.Any()))
                    {
                        foreach (var response in method.Responses.Where(r => r.Body != null && r.Body.Any()))
                        {
                            foreach (var kv in response.Body.Where(b => b.Value.Schema != null))
                            {
                                var key = GeneratorServiceHelper.GetKeyForResource(method, resource) + ParserHelpers.GetStatusCode(response.Code) + ResponseContentSuffix;
                                if (objects.ContainsKey(key))
                                {
                                    continue;
                                }

                                var obj = objectParser.ParseObject(key, kv.Value.Schema, objects, warnings);

                                // Avoid duplicated names and objects without properties
                                if (obj != null && objects.All(o => o.Value.Name != obj.Name) && obj.Properties.Any())
                                {
                                    objects.Add(key, obj);
                                }
                            }
                        }
                    }
                }
                if (resource.Resources != null)
                {
                    ParseResourceResponsesRecursively(objects, resource.Resources);
                }
            }
        }
Exemple #10
0
        private static bool IsValidHttpRequestMessage(HttpRequestMessage httpRequestMessage,
                                                      HttpMethod httpMethod,
                                                      string path,
                                                      IList <KeyValuePair <string, string> > queryStingParameters,
                                                      IDictionary <string, string> headerParameters)
        {
            if (httpRequestMessage.Method != httpMethod)
            {
                return(false);
            }

            string requestUriAbsoluteUri = httpRequestMessage.RequestUri.ToString();

            if (!requestUriAbsoluteUri.Contains(path))
            {
                return(false);
            }

            if (!requestUriAbsoluteUri.Contains($"api_key={Token}"))
            {
                return(false);
            }

            if (queryStingParameters != null)
            {
                if (queryStingParameters.Any(valuePair => !requestUriAbsoluteUri.Contains($"{valuePair.Key}={valuePair.Value}")))
                {
                    return(false);
                }
            }

            return(headerParameters == null || headerParameters.All(valuePair => httpRequestMessage.Headers.GetValues(valuePair.Key).Contains(valuePair.Value)));
        }
        /// <summary>
        /// Compares two dictionaries for equality.
        /// </summary>
        /// <returns>
        /// True if the dictionaries have equal contents or are both null, otherwise false.
        /// </returns>
        public static bool DictionaryEqual <TKey, TValue>(
            this IDictionary <TKey, TValue> dict1, IDictionary <TKey, TValue> dict2,
            IEqualityComparer <TValue> equalityComparer = null)
        {
            if (dict1 == dict2)
            {
                return(true);
            }

            if (dict1 == null | dict2 == null)
            {
                return(false);
            }

            if (dict1.Count != dict2.Count)
            {
                return(false);
            }

            if (equalityComparer == null)
            {
                equalityComparer = EqualityComparer <TValue> .Default;
            }

            return(dict1.All(kvp =>
            {
                TValue value2;
                return dict2.TryGetValue(kvp.Key, out value2) &&
                equalityComparer.Equals(kvp.Value, value2);
            }));
        }
Exemple #12
0
        private void AddForeignsDelete(
            DbCommand cmd,
            Entity entity,
            IDictionary<string, DeleteOption> options)
        {
            if (options.All(x => x.Value == DeleteOption.Nothing || x.Value == DeleteOption.AskUser))
                return;

            var sbDeletes = new StringBuilder();
            var recordHierarchy = _hierarchySource.GetRecordHierarchy(entity);
            foreach (var subRecord in recordHierarchy.SubRecordsHierarchies)
            {
                var deleteOption = DeleteOption.Nothing;
                if (options.ContainsKey(subRecord.Entity.Name))
                {
                    deleteOption = options[subRecord.Entity.Name];
                }
                switch (deleteOption)
                {
                    case DeleteOption.SetNull:
                        sbDeletes.AppendLine(GetSetToNullUpdateSql(cmd, entity, subRecord));
                        break;
                    case DeleteOption.CascadeDelete:
                        var deletes = GetDeleteRelatedEntityDeleteSql(cmd, subRecord).Reverse();
                        sbDeletes.AppendLine(string.Join(Environment.NewLine, deletes));
                        break;
                }
            }
            cmd.CommandText = sbDeletes + cmd.CommandText;
        }
        protected void CleanProperties(IDictionary <string, ApiObject> apiObjects)
        {
            var keys            = apiObjects.Keys.ToList();
            var apiObjectsCount = keys.Count - 1;

            for (var i = apiObjectsCount; i >= 0; i--)
            {
                var apiObject = apiObjects[keys[i]];
                var count     = apiObject.Properties.Count;
                for (var index = count - 1; index >= 0; index--)
                {
                    var prop = apiObject.Properties[index];
                    var type = prop.Type;
                    if (!string.IsNullOrWhiteSpace(type) && type.EndsWith("[]"))
                    {
                        type = type.Substring(0, type.Length - 2);
                    }

                    if (!NetTypeMapper.IsPrimitiveType(type) && schemaResponseObjects.All(o => o.Value.Name != type) && schemaRequestObjects.All(o => o.Value.Name != type))
                    {
                        apiObject.Properties.Remove(prop);
                    }
                }
                if (!apiObject.Properties.Any())
                {
                    apiObjects.Remove(keys[i]);
                }
            }
        }
Exemple #14
0
        private void AddForeignsDelete(
            DbCommand cmd,
            Entity entity,
            IDictionary <string, DeleteOption> options)
        {
            if (options.All(x => x.Value == DeleteOption.Nothing || x.Value == DeleteOption.AskUser))
            {
                return;
            }

            var sbDeletes       = new StringBuilder();
            var recordHierarchy = _hierarchySource.GetRecordHierarchy(entity);

            foreach (var subRecord in recordHierarchy.SubRecordsHierarchies)
            {
                var deleteOption = DeleteOption.Nothing;
                if (options.ContainsKey(subRecord.Entity.Name))
                {
                    deleteOption = options[subRecord.Entity.Name];
                }
                switch (deleteOption)
                {
                case DeleteOption.SetNull:
                    sbDeletes.AppendLine(GetSetToNullUpdateSql(cmd, entity, subRecord));
                    break;

                case DeleteOption.CascadeDelete:
                    var deletes = GetDeleteRelatedEntityDeleteSql(cmd, subRecord).Reverse();
                    sbDeletes.AppendLine(string.Join(Environment.NewLine, deletes));
                    break;
                }
            }
            cmd.CommandText = sbDeletes + cmd.CommandText;
        }
        public static bool ContainsAllTags(ObjectivesResultsCollection x, IDictionary <string, string> tags)
        {
            var xTags = x.Tags.Tags;

            return(tags.All((dictTag =>
                             (xTags.Any((xTag =>
                                         (dictTag.Key == xTag.Name && dictTag.Value == xTag.Value)))))));
        }
Exemple #16
0
 public bool ConditionsMet(IDictionary<string, bool> playerState, IDictionary<string, bool> conditions)
 {
     return
         conditions.All(
             c =>
                 (!c.Value && (!playerState.ContainsKey(c.Key) || !playerState[c.Key])) ||
                 (c.Value && (playerState.ContainsKey(c.Key) && playerState[c.Key])));
 }
        public static string GetUniqueName(IDictionary<string, ApiObject> objects, string name, IDictionary<string, ApiObject> otherObjects, IDictionary<string, ApiObject> schemaObjects)
        {
            for (var i = 0; i < 100; i++)
            {
                var unique = name + i;
                if (schemaObjects.All(p => p.Value.Name != unique) && objects.All(p => p.Value.Name != unique) && otherObjects.All(p => p.Value.Name != unique))
                    return unique;
            }

            foreach (var suffix in Suffixes)
            {
                for (var i = 0; i < 100; i++)
                {
                    var unique = name + suffix + i;
                    if (schemaObjects.All(p => p.Value.Name != unique) && objects.All(p => p.Value.Name != unique) && otherObjects.All(p => p.Value.Name != unique))
                        return unique;
                }
            }
            throw new InvalidOperationException("Could not find a unique name for object: " + name);
        }
Exemple #18
0
        static bool JustAttributes(IDictionary<string, CfgMetadata> meta, object node) {
            if(meta.All(kv => kv.Value.ListType == null))
                return true;

            foreach(var pair in meta.Where(kv=>kv.Value.ListType != null)){
                var list = (IList)meta[pair.Key].Getter(node);
                if (list != null && list.Count > 0)
                    return false;
            }
            return true;
        }
        public static string GetUniqueKey(IDictionary<string, ApiObject> objects, string key, IDictionary<string, ApiObject> otherObjects)
        {
            for (var i = 0; i < 100; i++)
            {
                var unique = key + i;
                if (objects.All(p => !string.Equals(p.Key, unique, StringComparison.OrdinalIgnoreCase))
                    && otherObjects.All(p => !string.Equals(p.Key, unique, StringComparison.OrdinalIgnoreCase)))
                    return unique;
            }

            foreach (var suffix in Suffixes)
            {
                for (var i = 0; i < 100; i++)
                {
                    var unique = key + suffix + i;
                    if (objects.All(p => !string.Equals(p.Key, unique, StringComparison.OrdinalIgnoreCase))
                        && otherObjects.All(p => !string.Equals(p.Key, unique, StringComparison.OrdinalIgnoreCase)))
                        return unique;
                }
            }
            throw new InvalidOperationException("Could not find a key name for object: " + key);
        }
        private static object CheckForExistingProperty(object item2, PropertyInfo fi, IDictionary<string, object> result)
        {
            var newValue = fi.GetValue(item2, null);
            if (result.All(x => x.Key != fi.Name))
            {
                return newValue;
            }

            var foundProperty = result.Single(x => x.Key == fi.Name);

            if (!foundProperty.Value.Equals(newValue))
            {
                throw new Exception("Merging Property with different values - " + fi.Name);
            }
            return newValue;
        }
        public static string GetUniqueName(IDictionary<string, ApiEnum> enums, string name)
        {
            for (var i = 0; i < 100; i++)
            {
                var unique = name + i;
                if (enums.All(p => p.Key != unique))
                    return unique;
            }

            foreach (var suffix in Suffixes)
            {
                for (var i = 0; i < 100; i++)
                {
                    var unique = name + suffix + i;
                    if (enums.All(p => p.Key != unique))
                        return unique;
                }
            }
            throw new InvalidOperationException("Could not find a unique name for enum: " + name);
        }
Exemple #22
0
		void WaitChildForCompleted (ObjectValue val, IDictionary<ObjectValue, bool> evaluatingList, bool hasMore)
		{
			view.WriteOutput ("\n ");

			var mark = view.Buffer.CreateMark (null, view.InputLineEnd, true);
			var iteration = 0;

			GLib.Timeout.Add (100, () => {
				if (!val.IsEvaluating) {
					PrintChildValueAtMark (val, mark);

					lock (mutex) {
						// Maybe We don't need this lock because children evaluation is done synchronously
						evaluatingList[val] = true;
						if (evaluatingList.All (x => x.Value))
							FinishPrinting (hasMore);
					}

					return false;
				}

				string prefix = "\t" + val.Name + ": ";

				if (++iteration == 5) {
					SetLineText (prefix + GettextCatalog.GetString ("Evaluating"), mark);
				} else if (iteration > 5 && (iteration - 5) % 10 == 0) {
					string points = string.Join ("", Enumerable.Repeat (".", iteration / 10));
					SetLineText (prefix + GettextCatalog.GetString ("Evaluating") + " " + points, mark);
				}

				return true;
			});
		}	
	    private void AddObjectToObjectCollectionOrLink(ApiObject obj, string key, IDictionary<string, ApiObject> objects)
	    {
            if (obj == null || !obj.Properties.Any())
                return;

            if (objects.All(o => o.Value.Name != obj.Name))
	        {
                objects.Add(key, obj);
	        }
	        else
	        {
	            if (!linkKeysWithObjectNames.ContainsKey(key))
	                linkKeysWithObjectNames.Add(key, obj.Name);
	        }
	    }
 private string GetUniqueName(IDictionary<string, ApiEnum> enums, string name)
 {
     for (var i = 0; i < 9; i++)
     {
         var unique = name + suffixes[i];
         if (enums.All(p => p.Key != unique))
             return unique;
     }
     for (var i = 0; i < 100; i++)
     {
         var unique = name + "A" + i;
         if (enums.All(p => p.Key != unique))
             return unique;
     }
     throw new InvalidOperationException("Could not find a unique name for enum");
 }
        private void AddObjectToObjectCollectionOrLink(ApiObject obj, string key, IDictionary<string, ApiObject> objects, IDictionary<string, ApiObject> otherObjects)
        {
            if (obj == null || (!obj.Properties.Any() && obj.Type == null))
                return;

            if (schemaObjects.All(o => o.Value.Name != obj.Name) && objects.All(o => o.Value.Name != obj.Name) && otherObjects.All(o => o.Value.Name != obj.Name))
            {
                objects.Add(key, obj);
            }
            else
            {
                if (UniquenessHelper.HasSameProperties(obj, objects, key, otherObjects, schemaObjects))
                {
                    if (string.IsNullOrWhiteSpace(obj.GeneratedCode) && !linkKeysWithObjectNames.ContainsKey(key))
                        linkKeysWithObjectNames.Add(key, obj.Name);
                }
                else if(!objects.ContainsKey(key))
                {
                    obj.Name = UniquenessHelper.GetUniqueName(objects, obj.Name, schemaObjects, schemaObjects);
                    objects.Add(key, obj);
                }
            }
        }
Exemple #26
0
        private static void PostTestResultToAppveyor(IDictionary<string, PlatformResult> dict)
        {
            var tempResult = ResultKind.NoError;
            var tempPlatform = Enumerable.Empty<string>();
            if (dict.Any(it => it.Value.Result.Kind == ResultKind.Fail))
            {
                if (dict.All (it => it.Value.Result.Kind == ResultKind.Fail))
                    tempPlatform = new[]{ "All" };
                else
                    tempPlatform =  dict.Where (it => it.Value.Result.Kind == ResultKind.Fail).Select(it=>it.Value.Platform);
            }
            else if (dict.Any(it => it.Value.Result.Kind == ResultKind.Error))
            {
                if (dict.All (it => it.Value.Result.Kind == ResultKind.Error))
                    tempPlatform = new[]{ "All" };
                else
                    tempPlatform =  dict.Where (it => it.Value.Result.Kind == ResultKind.Error).Select(it=>it.Value.Platform);

            }
            else if (dict.Any(it => it.Value.Result.Kind == ResultKind.Ignore))
            {
                if (dict.All (it => it.Value.Result.Kind == ResultKind.Ignore))
                    tempPlatform = new[]{ "All" };
                else
                    tempPlatform =  dict.Where (it => it.Value.Result.Kind == ResultKind.Ignore).Select(it=>it.Value.Platform);
            }
            else if (dict.All(it => it.Value.Result.Kind == ResultKind.Success))
            {
                if (dict.All (it => it.Value.Result.Kind == ResultKind.Success))
                    tempPlatform = new[]{ "All" };
                else
                    tempPlatform =  dict.Where (it => it.Value.Result.Kind == ResultKind.Success).Select(it=>it.Value.Platform);
            }
            else
            {
                if (dict.All (it => it.Value.Result.Kind == ResultKind.NoError))
                    tempPlatform = new[]{ "All" };
                else
                    tempPlatform =  dict.Where (it => it.Value.Result.Kind == ResultKind.NoError).Select(it=>it.Value.Platform);
            }

            string outcome = null;
            switch (tempResult)
            {
                case ResultKind.Success:
                    outcome = "Passed";
                    break;
                case ResultKind.Fail:
                    outcome = "Failed";
                    break;
                case ResultKind.Error:
                    outcome = "NotRunnable";
                    break;
                case ResultKind.Ignore:
                    outcome = "Ignored";
                    break;
                case ResultKind.NoError:
                    outcome = "Inconclusive";
                    break;
            }

            var result = dict.Values.Select (it=>it.Result).First();

            var fullName = string.Format("{0}.{1}.{2} [{3}]", result.Test.Name, result.Test.Fixture.Name,
            result.Test.Fixture.Assembly.Name, tempPlatform);

            var json = string.Format(@"{{
                                        'testName': '{0}',
                                        'testFramework': '{1}',
                                        'fileName': '{2}',
                                        'outcome': '{3}',
                                        'durationMilliseconds': '{4}',
                                        'ErrorMessage': '',
                                        'ErrorStackTrace': '',
                                        'StdOut': '{5}',
                                        'StdErr': ''
                                    }}",
                                     fullName.EscapeJson(),
                                     "PclUnit",
                                     result.Test.Fixture.Assembly.Name.EscapeJson(),
                                     outcome.EscapeJson(),
                                     (result.EndTime - result.StartTime).Milliseconds,
                                     result.Output.EscapeJson()
                );

            PostToAppVeyor(json);
        }
 /// <summary>
 /// Sets the values of the Configuration properties.
 /// </summary>
 /// <param name="properties"></param>
 public void SetProperties(IDictionary<string, string> properties)
 {
     if (this.sessionFactory == null && properties != null && properties.Count > 0)
         properties.All
             (
                 current =>
                     {
                         this.OverrideProperty(current.Key, current.Value);
                         return true;
                     }
             );
 }
Exemple #28
0
        private object FindItem(IList itemCollection, IDictionary<string, object> itemKeys)
        {
            Type itemType = itemCollection.GetType().GetGenericArguments().Single();
            foreach (var item in itemCollection)
            {
                if (itemKeys.All(kv => itemType.GetProperty(kv.Key).GetValue(item, new object[] { }).Equals(kv.Value)))
                {
                    return item;
                }
            }

            throw new InvalidOperationException("No entity found matching " +string.Join(",", itemKeys.Select(kv => kv.Key + "=" + kv.Value.ToString())));
        }
Exemple #29
0
 // Returns true if the row matches the key/value pairs.
 bool match(Item i, IDictionary<string, object> constraints)
 {
     return constraints.All(
     c => i.values.ContainsKey(c.Key) && i.values[c.Key].Equals(c.Value)
     );
 }
Exemple #30
0
        public static void PrintResult(IDictionary<string, PlatformResult> dict)
        {
            if (dict.All(it => it.Value.Result != null))
            {

                if (AppVeyor)
                {
                    PostTestResultToAppveyor(dict);
                }

                var result = dict.Select(it => it.Value.Result).First();
                if (TeamCity)
                {
                    Console.WriteLine("##teamcity[testStarted name='{2}.{1}.{0}' captureStandardOutput='true']",
                                      result.Test.Name.TeamCityEncode(),
                                      result.Test.Fixture.Name.TeamCityEncode(),
                                      result.Test.Fixture.Assembly.Name.TeamCityEncode());
                }
                else if(Verbose)
                {
                    Console.Write(result.Test.Fixture.Assembly.Name + ".");
                    Console.Write(result.Test.Fixture.Name + ".");
                }
                if (TeamCity || Verbose) {
                  Console.WriteLine (result.Test.Name);
                }
                foreach (var grpResult in dict.GroupBy(it => it.Value.Result.Kind))
                {
                  if (Verbose || TeamCity) {
                    Console.Write ("{0}:", grpResult.Key);
                    foreach (var keyValuePair in grpResult) {
                      Console.Write (" ");
                      Console.Write (keyValuePair.Value.Platform);
                    }
                  }
                    if (TeamCity)
                    {
                        switch (grpResult.Key)
                        {
                            case ResultKind.Fail:
                            case ResultKind.Error:
                                Console.WriteLine(
                                    "##teamcity[testFailed name='{2}.{1}.{0}' message='See log or details']",
                                      result.Test.Name.TeamCityEncode(),
                                      result.Test.Fixture.Name.TeamCityEncode(),
                                      result.Test.Fixture.Assembly.Name.TeamCityEncode());
                                break;
                            case ResultKind.Ignore:
                                Console.WriteLine(
                                    "##teamcity[testIgnored name='{2}.{1}.{0}' message='See log or details']",
                                      result.Test.Name.TeamCityEncode(),
                                      result.Test.Fixture.Name.TeamCityEncode(),
                                      result.Test.Fixture.Assembly.Name.TeamCityEncode());
                                break;
                        }

                    }
                  if (Verbose || TeamCity) {
                    Console.WriteLine ();
                  }
                }
            if (Verbose || TeamCity) {
              var span = new TimeSpan ();
              foreach (var r in dict.Select(it => it.Value.Result)) {
            span += (r.EndTime - r.StartTime);
              }
              Console.WriteLine ("avg time:{0}", new TimeSpan (span.Ticks / dict.Count));
            }

            if (Verbose || TeamCity) {

                    foreach (var lup in dict.ToLookup(it => it.Value.Result.Output)) {
                        var name = String.Join (",", lup.Select (it => it.Value.Platform));

                        Console.WriteLine ("{0}:", name);
                        Console.WriteLine (lup.Key);
                    }
                }

                if (TeamCity)
                {
                    Console.WriteLine("##teamcity[testFinished name='{2}.{1}.{0}' duration='{3}']",
                         result.Test.Name.TeamCityEncode(),
                         result.Test.Fixture.Name.TeamCityEncode(),
                         result.Test.Fixture.Assembly.Name.TeamCityEncode(),
                        (result.EndTime - result.StartTime).TotalMilliseconds);
                }
                else
                {

                    if (dict.Any(it => it.Value.Result.Kind == ResultKind.Fail))
                    {
                        if (Verbose)
                            Console.WriteLine ("!!!!!!!!!!!!!!!!!!!!!!!!!");
                        else if (dict.All(it => it.Value.Result.Kind == ResultKind.Fail))
                            Console.Write("!  ");
                        else
                            Console.Write ("!{0} ", dict.Where (it => it.Value.Result.Kind == ResultKind.Fail).Count ());
                    }
                    else if (dict.Any(it => it.Value.Result.Kind == ResultKind.Error))
                    {
                        if (Verbose)
                            Console.WriteLine("EEEEEEEEEEEEEEEEEEEEEEEEE");
                        else if (dict.All(it => it.Value.Result.Kind == ResultKind.Error))
                            Console.Write("E  ");
                        else
                            Console.Write ("E{0} ", dict.Where (it => it.Value.Result.Kind == ResultKind.Error).Count ());

                    }
                    else if (dict.Any(it => it.Value.Result.Kind == ResultKind.Ignore))
                    {
                        if (Verbose)
                            Console.WriteLine("?????????????????????????");
                        else if (dict.All(it => it.Value.Result.Kind == ResultKind.Ignore))
                            Console.Write("?  ");
                        else
                            Console.Write ("?{0} ", dict.Where (it => it.Value.Result.Kind == ResultKind.Ignore).Count ());
                    }
                    else if (dict.All(it => it.Value.Result.Kind == ResultKind.Success))
                    {
                        if (Verbose)
                            Console.WriteLine("-------------------------");
                        else
                            Console.Write(".  ");
                    }
                    else
                    {
                        if (Verbose)
                            Console.WriteLine (".........................");
                        else if (dict.All (it => it.Value.Result.Kind == ResultKind.NoError))
                            Console.Write ("_  ");
                        else
                            Console.Write ("_{0} ", dict.Where (it => it.Value.Result.Kind == ResultKind.NoError).Count ());
                    }
                    if (Verbose || ++_resultCount % 26 == 0 )
                        Console.WriteLine(String.Empty);

                }
            }
        }