public void CreateAttributeFromClassWrongName() { NhvmClassAttributename attributename = new NhvmClassAttributename(); attributename.Text = new string[] { "assertanimal" }; Assert.That(() => RuleAttributeFactory.CreateAttributeFromClass(typeof(Suricato), attributename), Throws.TypeOf <InvalidAttributeNameException>()); }
protected override void Initialize() { clazz = ReflectHelper.ClassForFullName( TypeNameParser.Parse(meta.name, meta.rootMapping.@namespace, meta.rootMapping.assembly).ToString()); classAttributes = meta.attributename == null ? new List <Attribute>(0) : new List <Attribute>(meta.attributename.Length); List <MemberInfo> lmembers = meta.property == null ? new List <MemberInfo>(0) : new List <MemberInfo>(meta.property.Length); if (meta.attributename != null) { log.Debug("Looking for class attributes"); foreach (NhvmClassAttributename attributename in meta.attributename) { log.Info("Attribute to look for = " + GetText(attributename)); Attribute classAttribute = RuleAttributeFactory.CreateAttributeFromClass(clazz, attributename); classAttributes.Add(classAttribute); } } if (meta.property != null) { foreach (NhvmProperty property in meta.property) { MemberInfo currentMember = TypeUtils.GetPropertyOrField(clazz, property.name); if (currentMember == null) { throw new InvalidPropertyNameException(property.name, clazz); } log.Info("Looking for rules for property : " + property.name); lmembers.Add(currentMember); // creation of member attributes foreach (object rule in property.Items) { Attribute thisAttribute = RuleAttributeFactory.CreateAttributeFromRule(rule, meta.rootMapping.assembly, meta.rootMapping.@namespace); if (thisAttribute != null) { log.Info(string.Format("Adding member {0} to dictionary with attribute {1}", currentMember.Name, thisAttribute)); if (!membersAttributesDictionary.ContainsKey(currentMember)) { membersAttributesDictionary.Add(currentMember, new List <Attribute>()); } membersAttributesDictionary[currentMember].Add(thisAttribute); } } } } members = lmembers.ToArray(); }
public void CreateAttributeFromClass() { NhvmClassAttributename attributename = new NhvmClassAttributename(); attributename.Text = new string[] { "AssertAnimal" }; Attribute found = RuleAttributeFactory.CreateAttributeFromClass(typeof(Suricato), attributename); Assert.IsNotNull(found); Assert.AreEqual(typeof(AssertAnimalAttribute), found.GetType()); attributename.Text = new string[] { "AssertAnimalAttribute" }; found = RuleAttributeFactory.CreateAttributeFromClass(typeof(Suricato), attributename); Assert.IsNotNull(found); Assert.AreEqual(typeof(AssertAnimalAttribute), found.GetType()); }