AddPropertyValue() public method

Adds a property value to this bag.
public AddPropertyValue ( string propertyName, object value ) : void
propertyName string Name of the property.
value object The value.
return void
Beispiel #1
0
        public void Adding_the_same_property_twice_should_cause_exception()
        {
            var propertyName = "MyProperty";
            var firstValue = 1;
            var secondValue = 2;

            var bag = new PropertyBag("testing");
            bag.AddPropertyValue(propertyName, firstValue);

            Action act = ()=>bag.AddPropertyValue(propertyName, secondValue);
            act.ShouldThrow<ArgumentException>().WithMessage("An item with the same key has already been added.");
        }
Beispiel #2
0
        public void Adding_the_same_property_twice_should_cause_exception()
        {
            var propertyName = "MyProperty";
            var firstValue = 1;
            var secondValue = 2;

            var bag = new PropertyBag("testing");
            bag.AddPropertyValue(propertyName, firstValue);

            Action act = ()=>bag.AddPropertyValue(propertyName, secondValue);
            act.ShouldThrow<ArgumentException>();
        }
Beispiel #3
0
        public void Calling_AddPropertyValue_should_add_the_property_info()
        {
            var thePropName = "MyProperty";
            var thePropValue = "Hello world";

            var bag = new PropertyBag("testing");
            bag.AddPropertyValue(thePropName, thePropValue);

            bag.Properties.Should().Contain(p => p.Key == thePropName && (String)p.Value == thePropValue);
        }
        /// <summary>
        /// Converts a command or event into a property bag.
        /// </summary>
        public PropertyBag Convert(object obj)
        {
            Type type = obj.GetType();
            var document = new PropertyBag(type);

            foreach (PropertyInfo propertyInfo in type.GetProperties(PublicInstanceProperties))
            {
                document.AddPropertyValue(propertyInfo.Name, propertyInfo.GetValue(obj, null));
            }

            return document;
        }
Beispiel #5
0
        /// <summary>
        /// Converts a command or event into a property bag.
        /// </summary>
        public PropertyBag Convert(object obj)
        {
            Type type      = obj.GetType();
            var  eventName = TypeResolver.EventNameFor(type);
            var  document  = new PropertyBag(eventName);

            foreach (PropertyInfo propertyInfo in type.GetProperties(PublicInstanceProperties))
            {
                document.AddPropertyValue(propertyInfo.Name, propertyInfo.GetValue(obj, null));
            }

            return(document);
        }
Beispiel #6
0
        public void The_number_of_properties_should_be_equal_to_the_number_of_calls_to_AddPropertyValue()
        {
            var callCount = 5;
            var bag = new PropertyBag("testing");

            for(int i =0; i<callCount; i++)
            {
                var name = "prop" + i;
                var value = i;

                bag.AddPropertyValue(name, value);
            }

            bag.Properties.Count.Should().Be(callCount);
        }
        public void Restoration_of_an_event_from_a_property_bag_containing_nulls_should_not_fail()
        {
            try
            {
                var converter = new PropertyBagConverter { TypeResolver = new SimpleEventTypeResolver() };

                var bag = new PropertyBag(typeof(TestEvent).AssemblyQualifiedName);
                bag.AddPropertyValue("SomeString", null);

                var obj = converter.Convert(bag);

                obj.Should().NotBeNull();
                obj.Should().BeOfType<TestEvent>();

                ((TestEvent) obj).SomeString.Should().BeNull();
            }
            catch(Exception e)
            {
                Assert.Fail(e.ToString());
            }
        }