public void OrderFileValidator_EnumParseableValidator_WhenNonValid(OrderFileValidatorTestData testData)
        {
            var result = validator.Validate(testData.OrderFileContract);

            var errors         = result.Errors.WherePropertyName(testData.PropertyName);
            var logErrors      = errors.ToList();
            var expectedErrors = errors
                                 .WhereErrorMessage(testData.ExpectedMessage)
                                 .WhereRuleValidator(testData.RuleValidator);

            var message = FormatMessage(testData.ExpectedMessage, logErrors);

            Assert.IsTrue(expectedErrors.Any(), message);
        }
        public static TestCaseData CreateValidEnumParseableValidatorTestCaseData <TEnum>(string testName, Expression <Func <OrderFileContract, string> > expression, OrderFileContract orderFileContract)
            where TEnum : struct, IConvertible
        {
            var property = GetProperty(expression, orderFileContract);
            var testData = new OrderFileValidatorTestData
            {
                RuleValidator     = typeof(EnumParseableValidator <TEnum>).Name,
                PropertyName      = property.PropertyName,
                OrderFileContract = orderFileContract
            };

            return(new TestCaseData(testData)
                   .SetName($"{testName} when property '{property.PropertyName}' value '{property.PropertyValue ?? "NULL" }' must be valid'"));
        }
예제 #3
0
        public static TestCaseData CreateIsEmptyValidatorTestCaseData(string testName, Expression <Func <OrderFileContract, string> > expression, OrderFileContract orderFileContract)
        {
            var property = GetProperty(expression, orderFileContract);
            var testData = new OrderFileValidatorTestData
            {
                RuleValidator     = nameof(IsEmptyValidator),
                ExpectedMessage   = $"'{property.PropertyDisplayName}' with value '{property.PropertyValue}' must be empty.",
                PropertyName      = property.PropertyName,
                OrderFileContract = orderFileContract
            };

            return(new TestCaseData(testData)
                   .SetName($"{testName} when property '{property.PropertyName}' value '{property.PropertyValue ?? "NULL" }' must return '{testData.ExpectedMessage}'"));
        }
        public static TestCaseData CreateMaximumLengthValidatorTestCaseData(string testName, Expression <Func <OrderFileContract, string> > expression, OrderFileContract orderFileContract)
        {
            var property = GetProperty(expression, orderFileContract);
            var testData = new OrderFileValidatorTestData
            {
                RuleValidator     = nameof(MaximumLengthValidator),
                ExpectedMessage   = $"The length of '{property.PropertyDisplayName}' must be {property.PropertyValue.Length - 1} characters or fewer. You entered {property.PropertyValue.Length} characters.",
                PropertyName      = property.PropertyName,
                OrderFileContract = orderFileContract
            };

            return(new TestCaseData(testData)
                   .SetName($"{testName} when property '{property.PropertyName}' value '{property.PropertyValue ?? "NULL" }' must return '{testData.ExpectedMessage}'"));
        }
예제 #5
0
        public static TestCaseData CreateLengthValidatorValidatorTestCaseData(string testName, Expression <Func <OrderFileContract, string> > expression, int min, int max, OrderFileContract orderFileContract)
        {
            var property = GetProperty(expression, orderFileContract);
            var testData = new OrderFileValidatorTestData
            {
                RuleValidator     = nameof(LengthValidator),
                ExpectedMessage   = $"'{property.PropertyDisplayName}' must be between {min} and {max} characters. You entered {property.PropertyValue?.Length ?? 0} characters.",
                PropertyName      = property.PropertyName,
                OrderFileContract = orderFileContract
            };

            return(new TestCaseData(testData)
                   .SetName($"{testName} when property '{property.PropertyName}' value '{property.PropertyValue ?? "NULL" }' must return '{testData.ExpectedMessage}'"));
        }
        public static TestCaseData CreateEnumParseableValidatorTestCaseData <TEnum>(string testName, Expression <Func <OrderFileContract, string> > expression, OrderFileContract orderFileContract)
            where TEnum : struct, IConvertible
        {
            var property = GetProperty(expression, orderFileContract);
            var testData = new OrderFileValidatorTestData
            {
                RuleValidator     = typeof(EnumParseableValidator <TEnum>).Name,
                ExpectedMessage   = $"'{property.PropertyDisplayName}' value '{property.PropertyValue}' must be assignable to typeof<{typeof(TEnum)}> enum.",
                PropertyName      = property.PropertyName,
                OrderFileContract = orderFileContract
            };

            return(new TestCaseData(testData)
                   .SetName($"{testName} when property '{property.PropertyName}' value '{property.PropertyValue ?? "NULL" }' must return '{testData.ExpectedMessage}'"));
        }
        public static TestCaseData CreateWhenFixedIncomeEnumsMustBeTestCases <TEnum>(string testName, Expression <Func <OrderFileContract, string> > expression, OrderFileContract orderFileContract, string validValue)
            where TEnum : struct, IConvertible
        {
            var property = GetProperty(expression, orderFileContract);
            var testData = new OrderFileValidatorTestData
            {
                RuleValidator     = nameof(EqualValidator),
                ExpectedMessage   = $"'{property.PropertyDisplayName}' must be equal to '{validValue}'. When fixed income.",
                PropertyName      = property.PropertyName,
                OrderFileContract = orderFileContract
            };

            return(new TestCaseData(testData)
                   .SetName($"{testName} when property '{property.PropertyName}' value '{property.PropertyValue ?? "NULL" }' must not be equal to '{property.PropertyValue}'"));
        }
        public static TestCaseData CreateNonValidEnumParseableValidatorTestCaseData <TEnum>(string testName, Expression <Func <OrderFileContract, string> > expression, OrderFileContract orderFileContract)
            where TEnum : struct, IConvertible
        {
            var property = GetProperty(expression, orderFileContract);
            var testData = new OrderFileValidatorTestData
            {
                RuleValidator     = nameof(NotEqualValidator),
                PropertyName      = property.PropertyName,
                OrderFileContract = orderFileContract,
                ExpectedMessage   = $"'{property.PropertyDisplayName}' must not be equal to '{property.PropertyValue}'."
            };

            return(new TestCaseData(testData)
                   .SetName($"{testName} when property '{property.PropertyName}' value '{property.PropertyValue ?? "NULL" }' must not be equal to '{property.PropertyValue}'"));
        }
예제 #9
0
        public static TestCaseData CreateIsDecimalStringValidatorTestCaseData(string testName, Expression <Func <OrderFileContract, string> > expression, OrderFileContract orderFileContract, string additionalMessage)
        {
            var property = GetProperty(expression, orderFileContract);
            var testData = new OrderFileValidatorTestData
            {
                RuleValidator = nameof(IsDecimalStringValidator),

                ExpectedMessage   = $"'{property.PropertyDisplayName}' value '{property.PropertyValue}' must be a valid decimal type.{additionalMessage}",
                PropertyName      = property.PropertyName,
                OrderFileContract = orderFileContract
            };

            return(new TestCaseData(testData)
                   .SetName($"{testName} when property '{property.PropertyName}' value '{property.PropertyValue ?? "NULL" }' must return '{testData.ExpectedMessage}'. {additionalMessage ?? "AdditionalMessage is NULL"}"));
        }