private static void Throw(
            Verification verification,
            VerifiableItem verifiableItem,
            TypeValidation typeValidation)
        {
            var verifiableItemTypeReadableString = verifiableItem.ItemType.ToStringReadable();

            WorkflowExtensions.ThrowImproperUseOfFramework(Invariant($"verificationName: {verification.Name}, isElementInEnumerable: {verifiableItem.ItemIsElementInEnumerable}, verifiableItemTypeName: {verifiableItemTypeReadableString}"));
        }
Exemplo n.º 2
0
        private static void ThrowIfMalformedRange(
            IReadOnlyList <VerificationParameter> verificationParameters)
        {
            // the public BeInRange/NotBeInRange is generic and guarantees that minimum and maximum are of the same type
            var rangeIsMalformed = CompareUsingDefaultComparer(verificationParameters[0].ParameterType, verificationParameters[0].Value, verificationParameters[1].Value) == CompareOutcome.Value1GreaterThanValue2;

            if (rangeIsMalformed)
            {
                var errorMessage = string.Format(CultureInfo.InvariantCulture, MalformedRangeExceptionMessage, verificationParameters[0].Name, verificationParameters[1].Name, verificationParameters[0].Value.ToStringInErrorMessage(), verificationParameters[1].Value.ToStringInErrorMessage());

                WorkflowExtensions.ThrowImproperUseOfFramework(errorMessage);
            }
        }
        private static void ThrowVerificationParameterUnexpectedType(
            string verificationName,
            Type verificationParameterType,
            string verificationParameterName,
            params Type[] expectedTypes)
        {
            var expectedTypesStrings = expectedTypes.Select(_ => _.ToStringReadable()).ToArray();

            var expectedTypesMessage = string.Join(", ", expectedTypesStrings);

            var exceptionMessage = string.Format(CultureInfo.InvariantCulture, VerificationParameterUnexpectedTypeErrorMessage, verificationName, verificationParameterName, verificationParameterName, verificationParameterType.ToStringReadable(), expectedTypesMessage);

            WorkflowExtensions.ThrowImproperUseOfFramework(exceptionMessage);
        }
        private static void ThrowSubjectUnexpectedType(
            Verification verification,
            VerifiableItem verifiableItem,
            params string[] expectedTypes)
        {
            var verifiableItemType = verifiableItem.ItemType;

            var verificationName = verification.Name;

            var isElementInEnumerable = verifiableItem.ItemIsElementInEnumerable;

            var expectedTypesMessage = string.Join(", ", expectedTypes.Select(_ => isElementInEnumerable ? Invariant($"IEnumerable<{_}>") : _));

            var valueTypeMessage = isElementInEnumerable ? Invariant($"IEnumerable<{verifiableItemType.ToStringReadable()}>") : verifiableItemType.ToStringReadable();

            var exceptionMessage = string.Format(CultureInfo.InvariantCulture, SubjectUnexpectedTypeErrorMessage, verificationName, valueTypeMessage, expectedTypesMessage);

            WorkflowExtensions.ThrowImproperUseOfFramework(exceptionMessage);
        }