public void IsMatchThrowsExceptionWithNullProperty()
        {
            var sut = new ExpressionIgnoreRule <Person>(x => x.FirstName);

            Action action = () => sut.IsMatch(null !);

            action.Should().Throw <ArgumentNullException>();
        }
Example #2
0
        public void AddWithIgnoreRuleThrowsExceptionWithNullConfiguration()
        {
            var rule = new ExpressionIgnoreRule <Person>(x => x.FirstName);

            Action action = () => BuildConfigurationExtensions.Add(null !, rule);

            action.Should().Throw <ArgumentNullException>();
        }
        public void IsMatchReturnsTrueWhenPropertyMatchesDerivedTypeProperty()
        {
            var property = typeof(Person).GetProperty(nameof(Person.Id)) !;

            var sut = new ExpressionIgnoreRule <Entity>(x => x.Id);

            var actual = sut.IsMatch(property);

            actual.Should().BeTrue();
        }
        public void IsMatchReturnsTrueWhenPropertyMatches()
        {
            var property = typeof(Person).GetProperty(nameof(Person.FirstName)) !;

            var sut = new ExpressionIgnoreRule <Person>(x => x.FirstName);

            var actual = sut.IsMatch(property);

            actual.Should().BeTrue();
        }
        public void IsMatchReturnsTrueWhenInheritedPropertyMatchesPropertyOnDeclaredType()
        {
            var property = typeof(Person).GetProperty(nameof(Person.Id)) !;

            var sut = new ExpressionIgnoreRule <Person>(x => x.Id);

            var actual = sut.IsMatch(property);

            actual.Should().BeTrue();
        }
        public void IsMatchReturnsFalseWhenPropertyNameDoesNotMatch()
        {
            var property = typeof(Person).GetProperty(nameof(Person.FirstName)) !;

            var sut = new ExpressionIgnoreRule <Person>(x => x.LastName);

            var actual = sut.IsMatch(property);

            actual.Should().BeFalse();
        }
Example #7
0
        public void AddWithIgnoreRuleAddsRuleToConfiguration()
        {
            var rule = new ExpressionIgnoreRule <Person>(x => x.FirstName);

            var sut = new BuildConfiguration();

            var config = sut.Add(rule);

            config.Should().Be(sut);

            sut.IgnoreRules.Should().Contain(rule);
        }
Example #8
0
        /// <summary>
        ///     Appends a new <see cref="IIgnoreRule" /> to the build configuration using the specified expression.
        /// </summary>
        /// <typeparam name="T">The type of instance that matches the rule.</typeparam>
        /// <param name="buildConfiguration">The build configuration to update.</param>
        /// <param name="expression">The expression that identifies a property on <typeparamref name="T" /></param>
        /// <returns>The build configuration with the new rule.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="buildConfiguration" /> parameter is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="expression" /> parameter is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">The <paramref name="expression" /> parameter does not represent a property.</exception>
        /// <exception cref="ArgumentException">
        ///     The <paramref name="expression" /> parameter does not match a property on the type
        ///     to generate.
        /// </exception>
        public static IBuildConfiguration Ignoring <T>(
            this IBuildConfiguration buildConfiguration,
            Expression <Func <T, object?> > expression)
        {
            buildConfiguration = buildConfiguration ?? throw new ArgumentNullException(nameof(buildConfiguration));

            expression = expression ?? throw new ArgumentNullException(nameof(expression));

            var rule = new ExpressionIgnoreRule <T>(expression);

            return(Add(buildConfiguration, rule));
        }
Example #9
0
        /// <summary>
        ///     Adds a new ignore rule to the configuration.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <typeparam name="T">The type that holds the property.</typeparam>
        /// <param name="expression">The expression that identifies a property on <typeparamref name="T" /></param>
        /// <returns>The configuration.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="configuration" /> parameter is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="expression" /> parameter is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">The <paramref name="expression" /> parameter does not represent a property.</exception>
        /// <exception cref="ArgumentException">
        ///     The <paramref name="expression" /> parameter does not match a property on the type
        ///     to generate.
        /// </exception>
        public static IBuildConfiguration AddIgnoreRule <T>(
            this IBuildConfiguration configuration,
            Expression <Func <T, object?> > expression)
        {
            configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));

            expression = expression ?? throw new ArgumentNullException(nameof(expression));

            var rule = new ExpressionIgnoreRule <T>(expression);

            configuration.IgnoreRules.Add(rule);

            return(configuration);
        }