Exemplo n.º 1
0
        private static void CompareNewWay(NameAndType expectedField, PropertyInfo propertyInfo)
        {
            var foundAttributes = CustomAttributeData.GetCustomAttributes(propertyInfo)
                                  .AsQueryable().OrderBy(a => a.ToString()).ToList();

            Assert.Equal(expectedField.ParameterAttributes.Count, foundAttributes.Count());//, "For Field: " + propertyInfo.Name);
            if (foundAttributes.Count() > 0)
            {
                for (int j = 0; j < foundAttributes.Count(); j++)
                {
                    //Assert.AreEqual(expectedField.Attributes[j], foundAttributes[j].ToString(), "For Field: " + propertyInfo.Name);
                    //Assert.True(foundAttributes[j].ToString().StartsWith(expectedField.ParameterAttributes[j].AttributeNameStartsWith));
                    Assert.StartsWith(expectedField.ParameterAttributes[j].AttributeNameStartsWith, foundAttributes[j].ToString());
                    var namedParameters = foundAttributes[j].NamedArguments.ToList();

                    namedParameters.Count.ShouldBe(expectedField.ParameterAttributes[j].NamedParameters.Count, "For Field: " + propertyInfo.Name + " For Attribute: " + foundAttributes[j]);

                    if (namedParameters.Count > 0)
                    {
                        var namedParametersAsStrings = new List <string>();
                        foreach (var namedParameter in namedParameters)
                        {
                            namedParametersAsStrings.Add(namedParameter.ToString());
                        }
                        foreach (var expectedParameter in expectedField.ParameterAttributes[j].NamedParameters)
                        {
                            Assert.True(namedParametersAsStrings.Contains(expectedParameter), "For Field: " + propertyInfo.Name + " For Attribute: " + foundAttributes[j] + "Expected Parameter: " + expectedParameter + " Found: " + namedParametersAsStrings.ParseList());
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static void CompareOldWay(NameAndType expectedField, PropertyInfo propertyInfo)
        {
            var foundAttributes = CustomAttributeData.GetCustomAttributes(propertyInfo)
                                  .AsQueryable().OrderBy(a => a.ToString()).ToList();

            foundAttributes.Count().ShouldBe(expectedField.Attributes.Count, "For Field: " + propertyInfo.Name);

            if (foundAttributes.Count() > 0)
            {
                for (int j = 0; j < foundAttributes.Count(); j++)
                {
                    foundAttributes[j].ToString().ShouldBe(expectedField.Attributes[j], "For Field: " + propertyInfo.Name);
                }
            }
        }