Exemplo n.º 1
0
        public void IsMatchForParameterThrowsExceptionWithNullParameter()
        {
            var value    = Guid.NewGuid().ToString();
            var priority = Environment.TickCount;

            var sut = new ParameterPredicateCreationRule(type => true, () => value, priority);

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

            action.Should().Throw <ArgumentNullException>();
        }
Exemplo n.º 2
0
        public void CreateForTypeThrowsException()
        {
            var type     = typeof(Person);
            var value    = Guid.NewGuid().ToString();
            var priority = Environment.TickCount;

            var sut = new ParameterPredicateCreationRule(item => true, () => value, priority);

            Action action = () => sut.Create(null !, type);

            action.Should().Throw <NotSupportedException>();
        }
Exemplo n.º 3
0
        public void CreateForPropertyThrowsException()
        {
            var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName)) !;
            var value        = Guid.NewGuid().ToString();
            var priority     = Environment.TickCount;

            var sut = new ParameterPredicateCreationRule(item => true, () => value, priority);

            Action action = () => sut.Create(null !, propertyInfo);

            action.Should().Throw <NotSupportedException>();
        }
Exemplo n.º 4
0
        public void IsMatchForTypeReturnsFalse()
        {
            var type     = typeof(Person);
            var value    = Guid.NewGuid().ToString();
            var priority = Environment.TickCount;

            var sut = new ParameterPredicateCreationRule(item => true, () => value, priority);

            var actual = sut.IsMatch(type);

            actual.Should().BeFalse();
        }
Exemplo n.º 5
0
        public void IsMatchForPropertyReturnsFalse()
        {
            var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName)) !;
            var value        = Guid.NewGuid().ToString();
            var priority     = Environment.TickCount;

            var sut = new ParameterPredicateCreationRule(item => true, () => value, priority);

            var actual = sut.IsMatch(propertyInfo);

            actual.Should().BeFalse();
        }
Exemplo n.º 6
0
        public void IsMatchForParameterReturnsPredicateResult(bool isMatch)
        {
            var parameterInfo = typeof(Person).GetConstructors()
                                .First(x => x.GetParameters().FirstOrDefault()?.Name == "firstName").GetParameters().First();
            var value    = Guid.NewGuid().ToString();
            var priority = Environment.TickCount;

            var sut = new ParameterPredicateCreationRule(item => isMatch, () => value, priority);

            var actual = sut.IsMatch(parameterInfo);

            actual.Should().Be(isMatch);
        }
Exemplo n.º 7
0
        public void CreateForParameterReturnsLiteralValue()
        {
            var parameterInfo = typeof(Person).GetConstructors()
                                .First(x => x.GetParameters().FirstOrDefault()?.Name == "firstName").GetParameters().First();
            var value    = Guid.NewGuid().ToString();
            var priority = Environment.TickCount;

            var sut = new ParameterPredicateCreationRule(item => true, value, priority);

            var actual = sut.Create(null !, parameterInfo);

            actual.Should().Be(value);
        }
Exemplo n.º 8
0
        /// <summary>
        ///     Adds a new <see cref="PropertyPredicateCreationRule" /> to the configuration.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="predicate">The predicate that matches on a parameter.</param>
        /// <param name="value">The static value returned by the rule.</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 AddCreationRule(this IBuildConfiguration configuration,
                                                          Predicate <ParameterInfo> predicate,
                                                          object value,
                                                          int priority)
        {
            configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));

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

            var rule = new ParameterPredicateCreationRule(predicate, value, priority);

            configuration.CreationRules.Add(rule);

            return(configuration);
        }