Beispiel #1
0
        public int CountRings(IEnumerable <ObjectEntry> objects)
        {
            PropertySpec prop = LevelData.GetObjectDefinition(ObjectID).CustomProperties.SingleOrDefault(a => a.Name == "Count");

            if (prop != null)
            {
                return(objects.Where(a => a.ID == ObjectID).Sum(a => (int)prop.GetValue(a)));
            }
            else
            {
                return(objects.Count(a => a.ID == ObjectID));
            }
        }
Beispiel #2
0
        public void GetValue_PropertyHasNoPublicGetter_ThrowInvalidOperationException()
        {
            // Setup
            var target = new ClassWithProperties();

            var propertySpec = new PropertySpec(target.GetType().GetProperty("DoublePropertyWithOnlyPublicSet"));

            // Call
            TestDelegate call = () => propertySpec.GetValue(target);

            // Assert
            string message = Assert.Throws <InvalidOperationException>(call).Message;

            Assert.AreEqual("Property lacks public getter!", message);
        }
Beispiel #3
0
        public void GetValue_InstanceIsNull_ThrowArgumentException()
        {
            // Setup
            var target = new ClassWithProperties();

            var propertySpec = new PropertySpec(target.GetType().GetProperty("IntegerProperty"));

            // Call
            TestDelegate call = () => propertySpec.GetValue(null);

            // Assert
            var exception = Assert.Throws <ArgumentException>(call);

            Assert.IsInstanceOf <TargetException>(exception.InnerException);
        }
Beispiel #4
0
        public void GetValue_ProperInstanceType_ReturnPropertyValue()
        {
            // Setup
            var target = new ClassWithProperties
            {
                IntegerProperty = 5
            };

            var propertySpec = new PropertySpec(target.GetType().GetProperty("IntegerProperty"));

            // Call
            object value = propertySpec.GetValue(target);

            // Assert
            Assert.AreEqual(target.IntegerProperty, value);
        }