This is a migrated thread and some comments may be shown as answers.

[Solved] Testing a property Data Type

1 Answer 70 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
sitefinitysteve asked on 02 Dec 2010, 09:27 PM
Given the following method...

public void CheckProperty(string className, string propertyName) {
            MetaPersistentType metaPersistentType = this.Container.PersistentTypes.FirstOrDefault(pt => pt.Name.Equals(className));
            Assert.IsNotNull(metaPersistentType);
             
            MetaMember metaMember = metaPersistentType.Members.FirstOrDefault(mm => mm.PropertyName.Equals(propertyName));
            Assert.IsNotNull(metaMember, "Can't find Property:" + propertyName + " in " + className);
            Assert.IsInstanceOfType(metaMember, typeof(MetaPrimitiveMember), String.Format("Type mismatch on class {0}, property {1}, maybe it's a collection instead?", className, propertyName));
        }

Is there a way to use this to validate a datatype for the property?  I might have been staring at it too long, but I can't seem to find a property on the meta objects...

Steve

1 Answer, 1 is accepted

Sort by
0
Zoran
Telerik team
answered on 08 Dec 2010, 10:18 AM
Hello Steve,

 If you would like to validate the type of the property you should go with the following approach:

MetaMember metaMember = metaPersistentType.Members.FirstOrDefault(mm => mm.PropertyName.Equals(propertyName));
 
MetaType memberType = metaMember.MemberType;
 
Assert.AreEqual(typeof(string).FullName, memberType.FullName);

Greetings,
Zoran
the Telerik team
Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
Tags
General Discussions
Asked by
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Zoran
Telerik team
Share this question
or