public void AddSameValueForSameKeyDoesNotDuplicateValue()
    {
        var dictionary = new MultiValueDictionary<string, string>();

        dictionary.AddValue("Key", "Value1");
        dictionary.AddValue("Key", "Value1");

        Assert.Contains("Key", dictionary.Keys);
        IEnumerable<string> values = dictionary["Key"];
        Assert.Single(values);
        Assert.Contains("Value1", values);
    }
    public void AddTwoValuesForSameKey()
    {
        var dictionary = new MultiValueDictionary<string, string>();

        dictionary.AddValue("Key", "Value1");
        dictionary.AddValue("Key", "Value2");

        Assert.Contains("Key", dictionary.Keys);
        IEnumerable<string> values = dictionary["Key"];
        Assert.Contains("Value1", values);
        Assert.Contains("Value2", values);
    }
    public void AddSameValueForSameKeyDoesNotDuplicateValue()
    {
        var dictionary = new MultiValueDictionary <string, string>();

        dictionary.AddValue("Key", "Value1");
        dictionary.AddValue("Key", "Value1");

        Assert.Contains("Key", dictionary.Keys);
        IEnumerable <string> values = dictionary["Key"];

        Assert.Single(values);
        Assert.Contains("Value1", values);
    }
    public void AddTwoValuesForSameKey()
    {
        var dictionary = new MultiValueDictionary <string, string>();

        dictionary.AddValue("Key", "Value1");
        dictionary.AddValue("Key", "Value2");

        Assert.Contains("Key", dictionary.Keys);
        IEnumerable <string> values = dictionary["Key"];

        Assert.Contains("Value1", values);
        Assert.Contains("Value2", values);
    }
Example #5
0
        public static MultiValueDictionary<string, string> GetTraits(IMethodInfo method)
        {
            var traits = new MultiValueDictionary<string, string>();

            foreach (IAttributeInfo attribute in method.GetCustomAttributes(typeof(TraitAttribute)))
                traits.AddValue(attribute.GetPropertyValue<string>("Name"),
                                attribute.GetPropertyValue<string>("Value"));

            foreach (IAttributeInfo attribute in method.Class.GetCustomAttributes(typeof(TraitAttribute)))
                traits.AddValue(attribute.GetPropertyValue<string>("Name"),
                                attribute.GetPropertyValue<string>("Value"));

            return traits;
        }
    public void RemoveValue()
    {
        var dictionary = new MultiValueDictionary <string, string>();

        dictionary.AddValue("Key", "Value1");
        dictionary.AddValue("Key", "Value2");

        dictionary.RemoveValue("Key", "Value1");

        Assert.Contains("Key", dictionary.Keys);
        IEnumerable <string> values = dictionary["Key"];

        Assert.DoesNotContain("Value1", values);
        Assert.Contains("Value2", values);
    }
    public void CanEnumerateKeysAndValuesWithDelegate()
    {
        string result = "";
        var dictionary = new MultiValueDictionary<string, string>();
        dictionary.AddValue("Key1", "Value1");
        dictionary.AddValue("Key2", "Value2");
        dictionary.AddValue("Key2", "Value1");
        dictionary.AddValue("Key3", "Value7");

        dictionary.ForEach((key, value) => result += key + ": " + value + "\r\n");

        Assert.Equal("Key1: Value1\r\n" +
                     "Key2: Value2\r\n" +
                     "Key2: Value1\r\n" +
                     "Key3: Value7\r\n", result);
    }
Example #8
0
    private static MultiValueDictionary <string, string> MakeTraits(string name, string value)
    {
        var result = new MultiValueDictionary <string, string>();

        result.AddValue(name, value);
        return(result);
    }
    public void RemoveValueForUnknownValueDoesNotThrow()
    {
        var dictionary = new MultiValueDictionary <string, string>();

        dictionary.AddValue("Key", "Value1");

        Assert.DoesNotThrow(() => dictionary.RemoveValue("Key", "Value2"));
    }
    public void AddSingleValue()
    {
        var dictionary = new MultiValueDictionary<string, string>();

        dictionary.AddValue("Key", "Value");

        Assert.Contains("Key", dictionary.Keys);
        Assert.Contains("Value", dictionary["Key"]);
    }
    public void AddSingleValue()
    {
        var dictionary = new MultiValueDictionary <string, string>();

        dictionary.AddValue("Key", "Value");

        Assert.Contains("Key", dictionary.Keys);
        Assert.Contains("Value", dictionary["Key"]);
    }
    public void RemoveKey()
    {
        var dictionary = new MultiValueDictionary<string, string>();
        dictionary.AddValue("Key", "Value");

        dictionary.Remove("Key");

        Assert.DoesNotContain("Key", dictionary.Keys);
    }
    public void CanEnumerateKeysAndValuesWithDelegate()
    {
        string result     = "";
        var    dictionary = new MultiValueDictionary <string, string>();

        dictionary.AddValue("Key1", "Value1");
        dictionary.AddValue("Key2", "Value2");
        dictionary.AddValue("Key2", "Value1");
        dictionary.AddValue("Key3", "Value7");

        dictionary.ForEach((key, value) => result += key + ": " + value + "\r\n");

        Assert.Equal(@"Key1: Value1
Key2: Value2
Key2: Value1
Key3: Value7
", result);
    }
    public void RemoveKey()
    {
        var dictionary = new MultiValueDictionary <string, string>();

        dictionary.AddValue("Key", "Value");

        dictionary.Remove("Key");

        Assert.DoesNotContain("Key", dictionary.Keys);
    }
    public void RemovingLastValueFromKeyRemovesKey()
    {
        var dictionary = new MultiValueDictionary <string, string>();

        dictionary.AddValue("Key", "Value1");

        dictionary.RemoveValue("Key", "Value1");

        Assert.DoesNotContain("Key", dictionary.Keys);
    }
        /// <summary>
        /// Enumerates the traits across all the loaded assemblies.
        /// </summary>
        public MultiValueDictionary<string, string> EnumerateTraits()
        {
            var results = new MultiValueDictionary<string, string>();

            foreach (TestAssembly testAssembly in testAssemblies)
                foreach (TestClass testClass in testAssembly.EnumerateClasses())
                    foreach (TestMethod testMethod in testClass.EnumerateTestMethods())
                        testMethod.Traits.ForEach((name, value) => results.AddValue(name, value));

            return results;
        }
        private static MultiValueDictionary<string, string> GetTraitsFromAttributes(IEnumerable<IAttributeInfo> attributes, MultiValueDictionary<string, string> traits)
        {
            foreach (var attributeInfo in attributes)
            {
                var name = attributeInfo.GetPropertyValue<string>("Name");
                var value = attributeInfo.GetPropertyValue<string>("Value");
                if (name != null && value != null)
                    traits.AddValue(name, value);
            }

            return traits;
        }
Example #18
0
        void UpdateTraitsFilter()
        {
            filterTraits.Clear();

            if (listTraits.SelectedIndices.Count > 0)
            {
                foreach (ListViewItem item in listTraits.SelectedItems)
                {
                    filterTraits.AddValue(item.Group.Name, item.Text);
                }
            }
        }
Example #19
0
        private static MultiValueDictionary <string, string> GetTraitsFromAttributes(IEnumerable <IAttributeInfo> attributes, MultiValueDictionary <string, string> traits)
        {
            foreach (var attributeInfo in attributes)
            {
                var name  = attributeInfo.GetPropertyValue <string>("Name");
                var value = attributeInfo.GetPropertyValue <string>("Value");
                if (name != null && value != null)
                {
                    traits.AddValue(name, value);
                }
            }

            return(traits);
        }
Example #20
0
        /// <summary>
        /// Creates a <see cref="TestAssembly"/> which is a complete object model over
        /// the tests inside of instance of <see cref="IExecutorWrapper"/>.
        /// </summary>
        /// <param name="executorWrapper">The executor wrapper</param>
        /// <returns>The fully populated object model</returns>
        public static TestAssembly Build(IExecutorWrapper executorWrapper)
        {
            Guard.ArgumentNotNull("executorWrapper", executorWrapper);

            List<TestClass> classes = new List<TestClass>();

            foreach (XmlNode classNode in executorWrapper.EnumerateTests().SelectNodes("//class"))
            {
                List<TestMethod> methods = new List<TestMethod>();
                string typeName = classNode.Attributes["name"].Value;

                foreach (XmlNode testNode in classNode.SelectNodes("method"))
                {
                    string methodName = testNode.Attributes["method"].Value;
                    string displayName = null;
                    string skipReason = null;

                    if (testNode.Attributes["name"] != null)
                        displayName = testNode.Attributes["name"].Value;
                    if (testNode.Attributes["skip"] != null)
                        skipReason = testNode.Attributes["skip"].Value;

                    var traits = new MultiValueDictionary<string, string>();
                    foreach (XmlNode traitNode in testNode.SelectNodes("traits/trait"))
                        traits.AddValue(traitNode.Attributes["name"].Value,
                                        traitNode.Attributes["value"].Value);

                    TestMethod testMethod = new TestMethod(methodName,
                                                           displayName ?? typeName + "." + methodName,
                                                           traits);

                    methods.Add(testMethod);

                    if (!String.IsNullOrEmpty(skipReason))
                        testMethod.RunResults.Add(new TestSkippedResult(testMethod.DisplayName, skipReason));
                }

                classes.Add(new TestClass(typeName, methods));
            }

            return new TestAssembly(executorWrapper, classes);
        }
 public static MultiValueDictionary <string, string> SafelyGetTraits(this ITypeInfo typeInfo)
 {
     try
     {
         // GetTraits relies on our attribute parsing to get at a property
         // value. Unless that value is set in the attribute constructor
         // via a named parameter (property) or a parameter with a name
         // similar to the required property, we'll return null, and that
         // can cause exceptions. If we get an exception, fail as nicely
         // as we can, with an empty collection of traits
         var multiValueDictionary = new MultiValueDictionary <string, string>();
         foreach (var attributeInfo in typeInfo.GetCustomAttributes(typeof(TraitAttribute)))
         {
             multiValueDictionary.AddValue(attributeInfo.GetPropertyValue <string>("Name"), attributeInfo.GetPropertyValue <string>("Value"));
         }
         return(multiValueDictionary);
     }
     catch (Exception)
     {
         return(new MultiValueDictionary <string, string>());
     }
 }
    public void RemovingLastValueFromKeyRemovesKey()
    {
        var dictionary = new MultiValueDictionary<string, string>();
        dictionary.AddValue("Key", "Value1");

        dictionary.RemoveValue("Key", "Value1");

        Assert.DoesNotContain("Key", dictionary.Keys);
    }
    public void RemoveValueForUnknownValueDoesNotThrow()
    {
        var dictionary = new MultiValueDictionary<string, string>();
        dictionary.AddValue("Key", "Value1");

        Assert.DoesNotThrow(() => dictionary.RemoveValue("Key", "Value2"));
    }
    public void RemoveValue()
    {
        var dictionary = new MultiValueDictionary<string, string>();
        dictionary.AddValue("Key", "Value1");
        dictionary.AddValue("Key", "Value2");

        dictionary.RemoveValue("Key", "Value1");

        Assert.Contains("Key", dictionary.Keys);
        IEnumerable<string> values = dictionary["Key"];
        Assert.DoesNotContain("Value1", values);
        Assert.Contains("Value2", values);
    }
Example #25
0
 private static MultiValueDictionary<string, string> MakeTraits(string name, string value)
 {
     var result = new MultiValueDictionary<string, string>();
     result.AddValue(name, value);
     return result;
 }