public static IDynamicBuilder <T> WithMany <T, TElement>(this IDynamicBuilder <T> builder, Expression <Func <T, IEnumerable <TElement> > > enumerableProperty, int count, Func <int, TElement> elementFactory)
        {
            Assert.IsGreaterThan(count, 0, nameof(count));
            Assert.IsNotNull(elementFactory, nameof(elementFactory));
            var elements = Enumerable.Range(0, count).Select(elementFactory);

            return(WithValue(builder, enumerableProperty, elements));
        }
        public static IDynamicBuilder <T> WithTransformedValue <T, TProperty>(this IDynamicBuilder <T> builder, Expression <Func <T, TProperty> > property, Func <TProperty, TProperty> transformation)
        {
            Assert.IsNotNull(transformation, nameof(transformation));
            var value            = builder.GetOverwrittenValue(property);
            var transformedValue = transformation(value);

            return(WithValue(builder, property, transformedValue));
        }
 public static IDynamicBuilder <TParent> WithDependentChild <TParent, TChild>(
     this IDynamicBuilder <TParent> builder,
     Expression <Func <TParent, TChild> > childProperty,
     Func <TParent, IDynamicBuilder <TChild>, IDynamicBuilder <TChild> > buildChild)
     where TChild : class
 {
     Assert.IsNotNull(buildChild, nameof(buildChild));
     return(WithBuilderDependentChild(builder, childProperty, (parentBuilder, childBuilder) => buildChild(parentBuilder.Build(), childBuilder)));
 }
 public static IDynamicBuilder <TParent> WithChild <TParent, TChild>(
     this IDynamicBuilder <TParent> builder,
     Expression <Func <TParent, TChild> > childProperty,
     Func <IDynamicBuilder <TChild>, IDynamicBuilder <TChild> > buildChild)
     where TChild : class =>
 WithValue(builder, childProperty,
           Assert.IsNotNull(buildChild, nameof(buildChild)).Invoke(
               Build.Dynamically(
                   GetOverwrittenValue(builder, childProperty))).Build());
Beispiel #5
0
 void _controlBuilderWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     Thread.Sleep(1000);
     DynamicControl = new LowFareAvailabilityDynamicControlBuilder()
     {
         Flights = (Flights)e.Argument
     };
     e.Result = DynamicControl.Build();
 }
        public void SetUp()
        {
            this.genericDto = Mock.Of <IGenericDto <int> >(
                x => x.GenericType == 45);

            this.genericSubclassDto = Mock.Of <IGenericDtoExtends <byte> >(
                x => x.GenericType == 0x01 && x.Value == 0xff);

            this.dynamicBuilder = Dynamic.Builder;
        }
        public static IDynamicBuilder <T> WithValue <T, TProperty>(this IDynamicBuilder <T> builder, Expression <Func <T, TProperty> > property, TProperty value)
        {
            Assert.IsNotNull(builder, nameof(builder));
            Assert.IsNotNull(property, nameof(property));

            string name = ExtractMemberAccessor(property).Member.Name;

            builder.Overwrite(name, value);
            return(builder);
        }
Beispiel #8
0
            public void NullBuilder_ShouldThrow()
            {
                // arrange
                IDynamicBuilder <TestClass> builder = null;

                // act
                Action getOverwrittenValue = () => DynamicBuilderExtensions.GetOverwrittenValue(builder, e => e.StringProperty);

                // assert
                getOverwrittenValue.Should().Throw <ArgumentNullException>();
            }
Beispiel #9
0
            public void NullBuilder_ShouldThrow()
            {
                // arrange
                IDynamicBuilder <TestParentClass> builder = null;

                // act
                Action withChild = () => DynamicBuilderExtensions.WithChild(builder, p => p.Child, childBuilder => childBuilder.WithValue(c => c.Int32Property, 1));

                // assert
                withChild.Should().Throw <ArgumentNullException>();
            }
Beispiel #10
0
            public void NullBuilder_ShouldThrow()
            {
                // arrange
                IDynamicBuilder <TestClass> builder = null;

                // act
                Action withBuilderDependentElement = () => DynamicBuilderExtensions.WithBuilderDependentElement(builder, e => e.EnumerableProperty, p => 1);

                // assert
                withBuilderDependentElement.Should().Throw <ArgumentNullException>();
            }
Beispiel #11
0
            public void NullBuilder_ShouldThrow()
            {
                // arrange
                IDynamicBuilder <TestClass> builder = null;

                // act
                Action withBuilderDependentMany = () => DynamicBuilderExtensions.WithBuilderDependentMany(builder, e => e.EnumerableProperty, 2, (objBuilder, idx) => idx.ToString());

                // assert
                withBuilderDependentMany.Should().Throw <ArgumentNullException>();
            }
            public void NullBuilder_ShouldThrow()
            {
                // arrange
                IDynamicBuilder <TestClass> builder = null;

                // act
                Action withValue = () => DynamicBuilderExtensions.WithTransformedValue(builder, e => e.Int32Property, val => val);

                // assert
                withValue.Should().Throw <ArgumentNullException>();
            }
            public void NullBuilder_ShouldThrow()
            {
                // arrange
                IDynamicBuilder <TestClass> builder = null;

                // act
                Action withDefault = () => DynamicBuilderExtensions.WithDefault(builder, e => e.StringProperty);

                // assert
                withDefault.Should().Throw <ArgumentNullException>();
            }
Beispiel #14
0
            public void NullBuilder_ShouldThrow()
            {
                // arrange
                IDynamicBuilder <TestClass> builder = null;

                // act
                Action withDependentValue = () => DynamicBuilderExtensions.WithDependentValue(builder, e => e.MinValueProperty, db => 1);

                // assert
                withDependentValue.Should().Throw <ArgumentNullException>();
            }
            public void NullBuilder_ShouldThrow()
            {
                // arrange
                IDynamicBuilder <TestClass> builder = null;

                // act
                Action withOne = () => DynamicBuilderExtensions.WithSingle(builder, e => e.EnumerableProperty, 1);

                // assert
                withOne.Should().Throw <ArgumentNullException>();
            }
Beispiel #16
0
            public void NullBuilder_ShouldThrow()
            {
                // arrange
                IDynamicBuilder <TestClassParent> builder = null;

                // act
                Action withBuilderDependentChild = () => DynamicBuilderExtensions.WithBuilderDependentChild(builder, e => e.Child, (parentBuilder, childBuilder) => childBuilder
                                                                                                            .WithValue(c => c.ChildValueProperty, parentBuilder.GetOverwrittenValue(e => e.ParentValueProperty) + 1));

                // assert
                withBuilderDependentChild.Should().Throw <ArgumentNullException>();
            }
        public static TProperty GetOverwrittenValue <T, TProperty>(this IDynamicBuilder <T> builder, Expression <Func <T, TProperty> > property)
        {
            Assert.IsNotNull(builder, nameof(builder));
            Assert.IsNotNull(property, nameof(property));

            string name = ExtractMemberAccessor(property).Member.Name;

            return
                (builder.IsOverwritten(name)
                ? builder.GetOverwrittenValue <TProperty>(name)
                : default(TProperty));
        }
        public static IDynamicBuilder <TParent> WithBuilderDependentChild <TParent, TChild>(
            this IDynamicBuilder <TParent> builder,
            Expression <Func <TParent, TChild> > childProperty,
            Func <IDynamicBuilder <TParent>, IDynamicBuilder <TChild>, IDynamicBuilder <TChild> > buildChild)
            where TChild : class
        {
            Assert.IsNotNull(buildChild, nameof(buildChild));
            var childBuilder = Build.Dynamically(GetOverwrittenValue(builder, childProperty));
            var child        = buildChild(builder, childBuilder).Build();

            return(WithValue(builder, childProperty, child));
        }
Beispiel #19
0
            public void NullBuilder_ShouldThrow()
            {
                // arrange
                IDynamicBuilder <TestClass> builder = null;

                // act
                Action withDependentElements = () => DynamicBuilderExtensions.WithDependentElements(builder, e => e.EnumerableProperty, obj => new List <int> {
                    1, 2
                });

                // assert
                withDependentElements.Should().Throw <ArgumentNullException>();
            }
        public static IDynamicBuilder <T> WithElements <T, TElement>(this IDynamicBuilder <T> builder, Expression <Func <T, IEnumerable <TElement> > > enumerableProperty, IEnumerable <TElement> elements)
        {
            var value = builder.GetOverwrittenValue(enumerableProperty);

            if (value == null)
            {
                value = elements;
            }
            else
            {
                value = value.Concat(elements);
            }
            return(WithValue(builder, enumerableProperty, value));
        }
Beispiel #21
0
        /// <summary>
        /// Handles the DoWork event of the _worker control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data.</param>
        void _worker_DoWork(object sender, DoWorkEventArgs e)
        {
            Thread.Sleep(600);
            var reservation = (VolarisReservation)e.Argument;

            DynamicBuilder = new VolarisPreviousPrincingDynamicControlBuilder()
            {
                Reservation = reservation
            };
            _worker.ReportProgress(50);

            Thread.Sleep(600);
            e.Result = DynamicBuilder.Build();
        }
Beispiel #22
0
        public void SetUp()
        {
            var mock = Mock.Of <IDto>(
                x =>
                x.CardInfoId == 10 &&
                x.CardIssueLevel == 0xDE &&
                x.CardNumberDisplay == "1234567890" &&
                x.CardNumber == 1234567890 &&
                x.CardUpdated == new DateTime(2014, 7, 4));

            this.Sut    = Dynamic.Builder;
            this.Result = this.Sut.Create <IDto>(mock);
            this.Obj    = JsonConvert.SerializeObject(this.Result);
        }
        public static IDynamicBuilder <T> WithBuilderDependentElement <T, TElement>(this IDynamicBuilder <T> builder, Expression <Func <T, IEnumerable <TElement> > > enumerableProperty, Func <IDynamicBuilder <T>, TElement> getElement)
        {
            Assert.IsNotNull(builder, nameof(builder));
            Assert.IsNotNull(getElement, nameof(getElement));
            var element = getElement(builder);
            var value   = builder.GetOverwrittenValue(enumerableProperty);

            if (value == null)
            {
                value = new[] { element }
            }
            ;
            else
            {
                value = value.Concat(new[] { element });
            }
            return(WithBuilderDependentValue(builder, enumerableProperty, b => value));
        }
        public static IDynamicBuilder <T> WithElement <T, TElement>(this IDynamicBuilder <T> builder, Expression <Func <T, IEnumerable <TElement> > > enumerableProperty, TElement element)
        {
            var value = builder.GetOverwrittenValue(enumerableProperty);

            if (value == null)
            {
                value = new[] { element }
            }
            ;
            else if (value is ICollection <TElement> collection && !collection.IsReadOnly)
            {
                collection.Add(element);
            }
            else
            {
                value = value.Concat(new[] { element });
            }
            return(WithValue(builder, enumerableProperty, value));
        }
 public static IDynamicBuilder <T> WithEmpty <T, TElement>(this IDynamicBuilder <T> builder, Expression <Func <T, IEnumerable <TElement> > > property) =>
 WithValue(builder, property, Enumerable.Empty <TElement>());
 public static IDynamicBuilder <T> WithEmpty <T>(this IDynamicBuilder <T> builder, Expression <Func <T, string> > property) =>
 WithValue(builder, property, string.Empty);
 public static IDynamicBuilder <T> WithSingle <T, TElement>(this IDynamicBuilder <T> builder, Expression <Func <T, IEnumerable <TElement> > > enumerableProperty, TElement element) =>
 WithValue(builder, enumerableProperty, new[] { element }.AsEnumerable());
 public static IDynamicBuilder <T> WithBuilderDependentSingle <T, TElement>(this IDynamicBuilder <T> builder, Expression <Func <T, IEnumerable <TElement> > > enumerableProperty, Func <IDynamicBuilder <T>, TElement> getElement)
 {
     Assert.IsNotNull(getElement, nameof(getElement));
     return(WithBuilderDependentValue(builder, enumerableProperty, b => new[] { getElement(b) }));
 }
 public static IDynamicBuilder <T> Overwrite <T, TProperty>(this IDynamicBuilder <T> builder, string name, TProperty value)
 {
     builder.Overwrite(name, value);
     return(builder);
 }
 public static IDynamicBuilder <T> WithDependentElement <T, TElement>(this IDynamicBuilder <T> builder, Expression <Func <T, IEnumerable <TElement> > > enumerableProperty, Func <T, TElement> getElement)
 {
     Assert.IsNotNull(getElement, nameof(getElement));
     return(WithBuilderDependentElement(builder, enumerableProperty, b => getElement(b.Build())));
 }