Example #1
0
        /// <summary>
        /// Ensure all <see cref="ConfigurableProperties"/> are loaded from an <see cref="IPropertyBag"/>, it mainly protects
        /// pipeline component authors from stupid copy/paste mistakes in <see cref="PipelineComponent"/>-derived classes.
        /// </summary>
        protected void VerifyAllPropertiesAreLoadedFromPropertyBag()
        {
            var propertyBag = new Mock <IPropertyBag>().Object;

            var sut = new T();

            sut.Load(propertyBag, 0);

            ConfigurableProperties
            .ForEach(
                p => Mock.Get(propertyBag).Verify(
                    pb => pb.Read(p.Name, out It.Ref <object> .IsAny, 0),
                    Times.Once,
                    $"{p.Name} property has not been read from IPropertyBag. Apply a [Browsable(false)] attribute to the property if it is intended."));
        }
Example #2
0
        /// <summary>
        /// Ensure <see cref="ConfigurableProperties"/> are saved to an <see cref="IPropertyBag"/>, it mainly protects pipeline
        /// component authors from stupid copy/paste mistakes in <see cref="PipelineComponent"/>-derived classes.
        /// </summary>
        protected void VerifyAllPropertiesAreSavedToPropertyBag()
        {
            var propertyBag = new Mock <IPropertyBag>().Object;

            var sut = new T();

            sut.Save(propertyBag, true, true);

            ConfigurableProperties
            .ForEach(
                p => Mock.Get(propertyBag).Verify(
                    pb => pb.Write(p.Name, ref It.Ref <object> .IsAny),
                    Times.Once,
                    $"{p.Name} property has not been written to IPropertyBag. Apply a [Browsable(false)] attribute to the property if it is intended. "
                    + "Notice that, for a string property, an empty string value should always be written even if it is null or empty."));
        }