Adf.Test.Domain.DomainObjectTestExtensions.CompareProperties C# (CSharp) Method

CompareProperties() public static method

public static CompareProperties ( this domainObject ) : void
domainObject this
return void
        public static void CompareProperties(this IDomainObject domainObject)
        {
            // Fetch all properties using reflection
            PropertyInfo[] propertyInfos = domainObject.GetType().GetProperties();
            foreach (PropertyInfo propertyInfo in propertyInfos.Where(p => p.CanRead && p.CanWrite))
            {
                // Read and write some stuff
                object val = GenerateRandomValue(propertyInfo);
                if (val == null)
                    Console.WriteLine(@"Skipping property {0} because the type {1} is unknown.", propertyInfo.Name, propertyInfo.PropertyType);
                else
                {
                    propertyInfo.SetValue(domainObject, val, null);

                    // Now, read back the value, and check if it's the same
                    object val2 = propertyInfo.GetValue(domainObject, null);
                    Assert.AreEqual(val, val2, "The value inserted and retrieved for property {0} are not the same.", propertyInfo.Name);
                }
            }
        }