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>(); }
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>(); }
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>(); }
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(); }
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(); }
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); }
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); }
/// <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); }