Exemplo n.º 1
0
        public void PriorityReturnsConstructorValue()
        {
            var priority = Environment.TickCount;

            var sut = new PropertyPredicateExecuteOrderRule(x => x.DeclaringType == typeof(string), priority);

            sut.Priority.Should().Be(priority);
        }
Exemplo n.º 2
0
        public void AddWithExecuteOrderRuleThrowsExceptionWithNullConfiguration()
        {
            var rule = new PropertyPredicateExecuteOrderRule(x => x.Name == "FirstName", Environment.TickCount);

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

            action.Should().Throw <ArgumentNullException>();
        }
Exemplo n.º 3
0
        public void IsMatchThrowsExceptionWithNullProperty()
        {
            var priority = Environment.TickCount;
            var sut      = new PropertyPredicateExecuteOrderRule(x => x.Name == nameof(Person.FirstName), priority);

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

            action.Should().Throw <ArgumentNullException>();
        }
Exemplo n.º 4
0
        public void AddWithExecuteOrderRuleAddsRuleToConfiguration()
        {
            var rule = new PropertyPredicateExecuteOrderRule(x => x.Name == "FirstName", Environment.TickCount);

            var sut = new BuildConfiguration();

            sut.Add(rule);

            sut.ExecuteOrderRules.Should().Contain(rule);
        }
Exemplo n.º 5
0
        public void ToStringDoesNotReturnTypeName()
        {
            var priority = Environment.TickCount;

            var sut = new PropertyPredicateExecuteOrderRule(x => x.DeclaringType == typeof(string), priority);

            var actual = sut.ToString();

            actual.ToString(CultureInfo.CurrentCulture).Should().NotBe(sut.GetType().FullName);
        }
Exemplo n.º 6
0
        public void IsMatchReturnsTrueWhenPropertyMatchesBaseTypeProperty()
        {
            var priority = Environment.TickCount;
            var property = typeof(Person).GetProperty(nameof(Entity.Id)) !;

            var sut = new PropertyPredicateExecuteOrderRule(x => x.ReflectedType == typeof(Person), priority);

            var actual = sut.IsMatch(property);

            actual.Should().BeTrue();
        }
Exemplo n.º 7
0
        public void IsMatchReturnsTrueWhenPropertyMatches()
        {
            var priority = Environment.TickCount;
            var property = typeof(Person).GetProperty(nameof(Person.FirstName)) !;

            var sut = new PropertyPredicateExecuteOrderRule(x => x.Name == nameof(Person.FirstName), priority);

            var actual = sut.IsMatch(property);

            actual.Should().BeTrue();
        }
Exemplo n.º 8
0
        public void IsMatchReturnsFalseWhenPropertyTypeDoesNotMatch()
        {
            var priority = Environment.TickCount;
            var property = typeof(Person).GetProperty(nameof(Person.LastName)) !;

            var sut = new PropertyPredicateExecuteOrderRule(x => x.PropertyType == typeof(DateTimeOffset), priority);

            var actual = sut.IsMatch(property);

            actual.Should().BeFalse();
        }
Exemplo n.º 9
0
        public void IsMatchReturnsFalseForParameter()
        {
            var priority      = Environment.TickCount;
            var parameterInfo = typeof(Person).GetConstructors()
                                .First(x => x.GetParameters().FirstOrDefault()?.Name == "firstName").GetParameters().First();

            var sut = new PropertyPredicateExecuteOrderRule(x => x.DeclaringType == typeof(string), priority);

            var actual = sut.IsMatch(parameterInfo);

            actual.Should().BeFalse();
        }
Exemplo n.º 10
0
        public void IsMatchReturnsTrueWhenInheritedPropertyMatchesPropertyOnDeclaredType()
        {
            var priority = Environment.TickCount;
            var property = typeof(Person).GetProperty(nameof(Person.Id)) !;

            var sut = new PropertyPredicateExecuteOrderRule(x =>
                                                            x.ReflectedType == typeof(Person) && x.Name == nameof(Person.Id) && x.PropertyType == typeof(Guid),
                                                            priority);

            var actual = sut.IsMatch(property);

            actual.Should().BeTrue();
        }
Exemplo n.º 11
0
        /// <summary>
        ///     Adds a new <see cref="PropertyPredicateExecuteOrderRule" /> to the configuration.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="predicate">The predicate that matches on a property.</param>
        /// <param name="priority">The priority of the rule.</param>
        /// <returns>The configuration.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="configuration" /> parameter is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="predicate" /> parameter is <c>null</c>.</exception>
        public static IBuildConfiguration AddExecuteOrderRule(
            this IBuildConfiguration configuration,
            Predicate <PropertyInfo> predicate,
            int priority)
        {
            configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));

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

            var rule = new PropertyPredicateExecuteOrderRule(predicate, priority);

            configuration.ExecuteOrderRules.Add(rule);

            return(configuration);
        }