public void PriorityReturnsConstructorValue() { var priority = Environment.TickCount; var expression = new Regex("FirstName"); var value = Guid.NewGuid().ToString(); var sut = new RegexCreationRule(typeof(string), expression, value, priority); sut.Priority.Should().Be(priority); }
public void CreateWithParameterThrowsExceptionWithNullParameter() { var expression = new Regex("FirstName"); var value = Guid.NewGuid().ToString(); var priority = Environment.TickCount; var sut = new RegexCreationRule(typeof(string), expression, value, priority); Action action = () => sut.Create(null !, (ParameterInfo)null !); action.Should().Throw <ArgumentNullException>(); }
public void IsMatchWithPropertyThrowsExceptionWithNullProperty() { var expression = new Regex("FirstName"); var value = Guid.NewGuid().ToString(); var priority = Environment.TickCount; var sut = new RegexCreationRule(typeof(string), expression, value, priority); Action action = () => sut.IsMatch((PropertyInfo)null !); action.Should().Throw <ArgumentNullException>(); }
public void IsMatchForTypeReturnsFalse() { var expression = new Regex("FirstName"); var value = Guid.NewGuid().ToString(); var priority = Environment.TickCount; var sut = new RegexCreationRule(typeof(string), expression, value, priority); var actual = sut.IsMatch(typeof(string)); actual.Should().BeFalse(); }
public void IsMatchForPropertyReturnsWhetherPropertyMatchesStringExpression(string expression, bool expected) { var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName)) !; var priority = Environment.TickCount; var sut = new RegexCreationRule(typeof(string), expression, expected, priority); var actual = sut.IsMatch(propertyInfo); actual.Should().Be(expected); }
public void CreateWithTypeThrowsException() { var expression = new Regex("FirstName"); var value = Guid.NewGuid().ToString(); var priority = Environment.TickCount; var sut = new RegexCreationRule(typeof(string), expression, value, priority); Action action = () => sut.Create(null !, typeof(string)); action.Should().Throw <NotSupportedException>(); }
public void CreateWithPropertyReturnsValueFromValueGenerator() { var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName)) !; var expression = new Regex("FirstName"); var expected = Guid.NewGuid().ToString(); var priority = Environment.TickCount; var sut = new RegexCreationRule(typeof(string), expression, () => expected, priority); var actual = sut.Create(null !, propertyInfo); actual.Should().Be(expected); }
public void IsMatchForPropertyReturnsWhetherPropertyMatches(Type declaringType, string propertyName, bool expected) { var propertyInfo = declaringType.GetProperty(propertyName) !; var expression = new Regex("FirstName"); var priority = Environment.TickCount; var sut = new RegexCreationRule(typeof(string), expression, expected, priority); var actual = sut.IsMatch(propertyInfo); actual.Should().Be(expected); }
public void CreateWithParameterReturnsValueFromValueGenerator() { var parameterInfo = typeof(Person).GetConstructors() .First(x => x.GetParameters().FirstOrDefault()?.Name == "firstName").GetParameters().First(); var expression = new Regex("FirstName"); var expected = Guid.NewGuid().ToString(); var priority = Environment.TickCount; var sut = new RegexCreationRule(typeof(string), expression, () => expected, priority); var actual = sut.Create(null !, parameterInfo); actual.Should().Be(expected); }
public void IsMatchForParameterReturnsWhetherParameterMatches(Type declaringType, string parameterName, bool expected) { var parameterInfo = declaringType.GetConstructors() .First(x => x.GetParameters().Any(y => y.Name == parameterName)).GetParameters() .First(x => x.Name == parameterName); var expression = new Regex("FirstName", RegexOptions.IgnoreCase); var priority = Environment.TickCount; var sut = new RegexCreationRule(typeof(string), expression, expected, priority); var actual = sut.IsMatch(parameterInfo); actual.Should().Be(expected); }
/// <summary> /// Adds a new <see cref="RegexCreationRule" /> to the configuration. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="targetType">The target type that matches the rule.</param> /// <param name="expression">The expression that matches a property name.</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="expression" /> parameter is <c>null</c>.</exception> public static IBuildConfiguration AddCreationRule(this IBuildConfiguration configuration, Type targetType, Regex expression, object value, int priority) { configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); targetType = targetType ?? throw new ArgumentNullException(nameof(targetType)); expression = expression ?? throw new ArgumentNullException(nameof(expression)); var rule = new RegexCreationRule(targetType, expression, value, priority); configuration.CreationRules.Add(rule); return(configuration); }
/// <summary> /// Adds a new <see cref="RegexCreationRule" /> to the configuration. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="targetType">The target type that matches the rule.</param> /// <param name="expression">The expression that matches a property name.</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="expression" /> parameter is <c>null</c> or empty.</exception> public static IBuildConfiguration AddCreationRule(this IBuildConfiguration configuration, Type targetType, string expression, object value, int priority) { configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); if (string.IsNullOrEmpty(expression)) { throw new ArgumentNullException(nameof(expression)); } var rule = new RegexCreationRule(targetType, expression, value, priority); configuration.CreationRules.Add(rule); return(configuration); }