Exemplo n.º 1
0
        private SetFieldCollectionCommand GetCommandFor(string fieldName)
        {
            if (_commands.ContainsKey(fieldName))
            {
                return((SetFieldCollectionCommand)_commands[fieldName]);
            }

            var setFieldCollectionCommand = new SetFieldCollectionCommand(_newObject, fieldName);

            _commands[fieldName] = setFieldCollectionCommand;
            return(setFieldCollectionCommand);
        }
Exemplo n.º 2
0
        public void Should_set_a_field_collection()
        {
            const string collectionName = "collectionField";
            var          command        = new SetFieldCollectionCommand(_object, collectionName);

            command.Add(1);
            command.Add(10);

            command.Execute();

            var expected = new object[] { 1, 10 };

            Assert.AreEqual(expected, _object.PropertyForTestingPurpose);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Configures the builder to set a collection passing all elements at once
        /// </summary>
        public FluentBuilder <T> WithCollection <TCollectionProperty, TElement>(Expression <Func <T, TCollectionProperty> > expression, params TElement[] newElements)
            where TCollectionProperty : IEnumerable <TElement>
        {
            var fieldName = GetMemberQuery.GetMemberNameFor(expression);

            var cmd = new SetFieldCollectionCommand(_newObject, fieldName);

            foreach (var element in newElements)
            {
                cmd.Add(element);
            }

            _commands[fieldName] = cmd;
            return(this);
        }