/// <summary>
        /// Constructs an assertion failure.
        /// </summary>
        /// <param name="native">The native unmanged object describing the failure.</param>
        /// <param name="stringResolver">A service to resolve unmanaged unicode strings.</param>
        public MbUnitCppAssertionFailure(NativeAssertionFailure native, IStringResolver stringResolver)
        {
            description        = stringResolver.GetString(native.DescriptionId);
            message            = stringResolver.GetString(native.MessageId);
            hasActualValue     = native.ActualValue.IsValid;
            hasExpectedValue   = native.ExpectedValue.IsValid;
            hasUnexpectedValue = native.UnexpectedValue.IsValid;
            line = native.Line;

            if (hasActualValue)
            {
                actualValue = NativeValueParser.Parse(stringResolver.GetString(native.ActualValue.ValueId), native.ActualValue.ValueType);
            }

            if (hasExpectedValue)
            {
                expectedValue = NativeValueParser.Parse(stringResolver.GetString(native.ExpectedValue.ValueId), native.ExpectedValue.ValueType);
            }

            if (hasUnexpectedValue)
            {
                unexpectedValue = NativeValueParser.Parse(stringResolver.GetString(native.UnexpectedValue.ValueId), native.UnexpectedValue.ValueType);
            }

            diffing = hasActualValue && (native.ActualValue.ValueType == NativeValueType.String) &&
                      ((hasExpectedValue && (native.ExpectedValue.ValueType == NativeValueType.String)) ||
                       (hasUnexpectedValue && (native.UnexpectedValue.ValueType == NativeValueType.String)));

            extraLabeledValues = GenericCollectionUtils.ToArray(GetExtraLabeledValues(native, stringResolver));
        }
 private void ValidateExpressionWithArray(IStringResolver res, string[] vals)
 {
     foreach (var val in vals)
     {
         Assert.IsTrue(res.IsMatch(val), "Unable to parse {0}", val);
     }
 }
示例#3
0
        public KeyValuePair <string, string>[] GetMetadata(IStringResolver resolver)
        {
            if (metadata == null)
            {
                metadata = GenericCollectionUtils.ToArray(EnumerateMetadata(resolver));
            }

            return(metadata);
        }
示例#4
0
 /// <summary>
 /// Constructs an MbUnitCpp tests.
 /// </summary>
 /// <param name="testInfoData">Information about the test.</param>
 /// <param name="resolver"></param>
 public MbUnitCppTest(TestInfoData testInfoData, IStringResolver resolver)
     : base(testInfoData.Name, testInfoData.FakeCodeElement)
 {
     this.testInfoData = testInfoData;
     Id         = testInfoData.GetId();
     Kind       = GetKind(testInfoData.Kind);
     IsTestCase = !testInfoData.HasChildren;
     Metadata.AddAll(testInfoData.GetMetadata(resolver));
 }
示例#5
0
 /// <summary>
 /// Constructs an MbUnitCpp tests.
 /// </summary>
 /// <param name="testInfoData">Information about the test.</param>
 /// <param name="resolver"></param>
 public MbUnitCppTest(TestInfoData testInfoData, IStringResolver resolver)
     : base(testInfoData.Name, testInfoData.FakeCodeElement)
 {
     this.testInfoData = testInfoData;
     Id = testInfoData.GetId();
     Kind = GetKind(testInfoData.Kind);
     IsTestCase = !testInfoData.HasChildren;
     Metadata.AddAll(testInfoData.GetMetadata(resolver));
 }
示例#6
0
        private IEnumerable <KeyValuePair <string, string> > EnumerateMetadata(IStringResolver resolver)
        {
            string data    = resolver.GetString(native.MetadataId);
            var    matches = Regex.Matches(data, @"(?<key>\w+)=\{(?<value>[\w\s]+)\}");

            foreach (Match match in matches)
            {
                yield return(new KeyValuePair <string, string>(match.Groups["key"].Value, match.Groups["value"].Value));
            }
        }
        /// <summary>
        /// Initialize a new instance of the <see cref="WrapHandler"/> class with an exception message resolver
        /// and the type of <see cref="Exception"/> to use.
        /// </summary>
        /// <param name="exceptionMessageResolver">The exception message resolver.</param>
        /// <param name="wrapExceptionType">The type of <see cref="Exception"/> to use to wrap.</param>
        public WrapHandler(IStringResolver exceptionMessageResolver, Type wrapExceptionType)
        {
            if (wrapExceptionType == null) throw new ArgumentNullException("wrapExceptionType");
            if (!typeof(Exception).IsAssignableFrom(wrapExceptionType))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.ExceptionTypeNotException, wrapExceptionType.Name), "wrapExceptionType");
            }

            this.exceptionMessageResolver = exceptionMessageResolver;
            this.wrapExceptionType = wrapExceptionType;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FaultContractExceptionHandler"/> class.
        /// </summary>
        /// <param name="exceptionMessageResolver">The exception message resolver.</param>
        /// <param name="faultContractType">Type of the fault contract.</param>
        /// <param name="attributes">A collection of nam value paries that specify the mapping
        /// between the properties of the FaultContract class and the values in the <see cref="Exception"/>
        /// instance. You can specify something like: FaultPropertyName = "{Message}" where {Message}
        /// points to the Message property value of the current exception. You can also specify a
        /// {Guid} value that will load the current exception handlingInstanceId value.
        /// See <see cref="HandleException"/>. NOTICE that names and values are case sensitive.</param>
        /// <exception cref="ArgumentNullException"/>
        public FaultContractExceptionHandler(IStringResolver exceptionMessageResolver, Type faultContractType, NameValueCollection attributes)
        {
            if (faultContractType == null)
            {
                throw new ArgumentNullException("faultContractType");
            }

            this.faultContractType = faultContractType;
            this.attributes = attributes;
            this.exceptionMessageResolver = exceptionMessageResolver;
            this.exceptionMessage = this.exceptionMessageResolver.GetString();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FaultContractExceptionHandler"/> class.
        /// </summary>
        /// <param name="exceptionMessageResolver">The exception message resolver.</param>
        /// <param name="faultContractType">Type of the fault contract.</param>
        /// <param name="attributes">A collection of nam value paries that specify the mapping
        /// between the properties of the FaultContract class and the values in the <see cref="Exception"/>
        /// instance. You can specify something like: FaultPropertyName = "{Message}" where {Message}
        /// points to the Message property value of the current exception. You can also specify a
        /// {Guid} value that will load the current exception handlingInstanceId value.
        /// See <see cref="HandleException"/>. NOTICE that names and values are case sensitive.</param>
        /// <exception cref="ArgumentNullException"/>
        public FaultContractExceptionHandler(IStringResolver exceptionMessageResolver, Type faultContractType, NameValueCollection attributes)
        {
            if (faultContractType == null)
            {
                throw new ArgumentNullException("faultContractType");
            }

            this.faultContractType        = faultContractType;
            this.attributes               = attributes;
            this.exceptionMessageResolver = exceptionMessageResolver;
            this.exceptionMessage         = this.exceptionMessageResolver.GetString();
        }
示例#10
0
 public WrapHandler(IStringResolver exceptionMessageResolver, Type wrapExceptionType)
 {
     if (wrapExceptionType == null)
     {
         throw new ArgumentNullException("wrapExceptionType");
     }
     if (!typeof(Exception).IsAssignableFrom(wrapExceptionType))
     {
         throw new ArgumentException(string.Format(Resources.Culture, Resources.ExceptionTypeNotException, wrapExceptionType.Name), "wrapExceptionType");
     }
     this.exceptionMessageResolver = exceptionMessageResolver;
     this.wrapExceptionType        = wrapExceptionType;
 }
示例#11
0
        public WarBuilderDrawer(
            Graphics graphics,
            WarBuilderIcons icons,
            WarBuilderBrushes brushes = null,
            Font contentFont          = null)
        {
            _graphics    = graphics;
            _icons       = icons;
            _brushes     = brushes ?? new WarBuilderBrushes();
            _fontContent = contentFont ?? new Font(FontFamily.GenericSansSerif, 24);

            _stringResolver = new AlexGamesStringResolver(icons);
        }
示例#12
0
 public ReplaceHandler(IStringResolver exceptionMessageResolver, Type replaceExceptionType)
 {
     if (replaceExceptionType == null)
     {
         throw new ArgumentNullException("replaceExceptionType");
     }
     if (!typeof(Exception).IsAssignableFrom(replaceExceptionType))
     {
         throw new ArgumentException(string.Format(Resources.Culture, Resources.ExceptionTypeNotException, replaceExceptionType.Name), "replaceExceptionType");
     }
     this.exceptionMessageResolver = exceptionMessageResolver;
     this.replaceExceptionType     = replaceExceptionType;
 }
示例#13
0
        /// <summary>
        /// Create <see cref="ExceptionPolicyDefinition"/> to implement exception shielding for component.
        /// 1. rethrow all exceptions derived from component base exception <typeparamref name="TBaseException"/>
        /// 2. rethrow <see cref="OperationCanceledException"/>
        /// 3. wrap generic exceptions to component specific exception <typeparamref name="TBaseException"/>
        /// </summary>
        /// <param name="policyDefinitionName">Policy definition name</param>
        /// <param name="wrapExceptionMessage">string resolver to be used in case of wrapping generic exception to component specific exception</param>
        /// <param name="wrapExceptionBeforeHandlers">additional handlers <see cref="IExceptionHandler"/> which will be executed before wrapping generic exception to component specific exception</param>
        /// <param name="additionalPolicyEntries">additional <see cref="ExceptionPolicyEntry"/> which will be added to policy definition before default ones</param>
        /// <typeparam name="TBaseException">Type of base class for component specific exceptions</typeparam>
        /// <returns>Policy definition <see cref="ExceptionPolicyDefinition"/></returns>
        public static ExceptionPolicyDefinition CreateShieldingForComponent <TBaseException>(
            string policyDefinitionName          = null,
            IStringResolver wrapExceptionMessage = null,
            IEnumerable <IExceptionHandler> wrapExceptionBeforeHandlers = null,
            IEnumerable <ExceptionPolicyEntry> additionalPolicyEntries  = null) where TBaseException : Exception
        {
            if (policyDefinitionName == null)
            {
                policyDefinitionName = "ShieldingFor" + typeof(TBaseException).FullName;
            }

            List <IExceptionHandler> handlers = wrapExceptionBeforeHandlers?.ToList() ?? new List <IExceptionHandler>();

            WrapHandler wrapHandler = wrapExceptionMessage == null
                                          ? new WrapHandler(
                "Unhandled exception. See inner for details",
                typeof(TBaseException))
                                          : new WrapHandler(wrapExceptionMessage, typeof(TBaseException));

            handlers.Add(wrapHandler);

            List <ExceptionPolicyEntry> policyEntries = additionalPolicyEntries?.ToList()
                                                        ?? new List <ExceptionPolicyEntry>();

            policyEntries.Add(
                new ExceptionPolicyEntry(
                    typeof(TBaseException),
                    PostHandlingAction.NotifyRethrow,
                    Enumerable.Empty <IExceptionHandler>()));

            policyEntries.Add(
                new ExceptionPolicyEntry(
                    typeof(OperationCanceledException),
                    PostHandlingAction.NotifyRethrow,
                    Enumerable.Empty <IExceptionHandler>()));

            policyEntries.Add(
                new ExceptionPolicyEntry(typeof(Exception), PostHandlingAction.ThrowNewException, handlers));

            ExceptionPolicyDefinition result = new ExceptionPolicyDefinition(policyDefinitionName, policyEntries);

            return(result);
        }
示例#14
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="native">The native structure that holds data.</param>
 public TestStepResult(NativeTestStepResult native, IStringResolver stringResolver)
 {
     this.native         = native;
     this.stringResolver = stringResolver;
 }
示例#15
0
        public KeyValuePair<string, string>[] GetMetadata(IStringResolver resolver)
        {
            if (metadata == null)
                metadata = GenericCollectionUtils.ToArray(EnumerateMetadata(resolver));

            return metadata;
        }
示例#16
0
 /// <summary>
 /// Construct root, for subclasses.
 /// </summary>
 /// <param name="appender"></param>
 /// <param name="prevKey"></param>
 /// <param name="asset"></param>
 /// <param name="culturePolicy"></param>
 /// <param name="stringResolver"></param>
 /// <param name="resourceResolver"></param>
 /// <param name="stringFormat"></param>
 /// <param name="formatProvider"></param>
 /// <param name="logger"></param>
 /// <param name="functions"></param>
 public LinkedTo(ILineFactory appender, ILine prevKey, IAsset asset = null, ICulturePolicy culturePolicy = null, IStringResolver stringResolver = null, IResourceResolver resourceResolver = null, IStringFormat stringFormat = null, IFormatProvider formatProvider = null, ILogger logger = null, IFunctions functions = null) :
     base(appender, prevKey, asset, culturePolicy, stringResolver, resourceResolver, stringFormat, formatProvider, logger, functions)
 {
 }
 private static IEnumerable<Pair<string, object>> GetExtraLabeledValues(NativeAssertionFailure native, IStringResolver stringResolver)
 {
     foreach (NativeLabeledValue item in new[] { native.Extra_0, native.Extra_1 })
     {
         if (item.IsValid)
         {
             yield return new Pair<string, object>(
                 stringResolver.GetString(item.LabelId),
                  NativeValueParser.Parse(stringResolver.GetString(item.ValueId), item.ValueType));
         }
     }
 }
 /// <summary>
 /// Create localization resolver.
 /// </summary>
 /// <param name="lineFactory"></param>
 /// <param name="stringResolver"></param>
 /// <returns>new key</returns>
 /// <exception cref="LineException">If part append fails</exception>
 public static ILineStringResolver StringResolver(this ILineFactory lineFactory, IStringResolver stringResolver)
 => lineFactory.Create <ILineStringResolver, IStringResolver>(null, stringResolver);
 private static IEnumerable <Pair <string, object> > GetExtraLabeledValues(NativeAssertionFailure native, IStringResolver stringResolver)
 {
     foreach (NativeLabeledValue item in new[] { native.Extra_0, native.Extra_1 })
     {
         if (item.IsValid)
         {
             yield return(new Pair <string, object>(
                              stringResolver.GetString(item.LabelId),
                              NativeValueParser.Parse(stringResolver.GetString(item.ValueId), item.ValueType)));
         }
     }
 }
 /// <summary>
 /// Append localization resolver.
 /// </summary>
 /// <param name="line"></param>
 /// <param name="stringResolver"></param>
 /// <returns>new key</returns>
 /// <exception cref="LineException">If part append fails</exception>
 public static ILineStringResolver StringResolver(this ILine line, IStringResolver stringResolver)
 => line.Append <ILineStringResolver, IStringResolver>(stringResolver);
示例#21
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="native">The native structure that holds data.</param>
 public TestStepResult(NativeTestStepResult native, IStringResolver stringResolver)
 {
     this.native = native;
     this.stringResolver = stringResolver;
 }
示例#22
0
        public static void DrawBrickLay(this string target, Graphics graphics, Rectangle rect, Font font, Brush brush, IStringResolver resolver)
        {
            string[] words = target.Split(' ');

            float fontHeight = graphics.MeasureString(words[0], font).Height;

            float curX = 0;
            float curY = 0;

            foreach (string word in words)
            {
                PointF wordPoint = new PointF(curX, curY);
                SizeF  wordSize  = resolver.MesureString(graphics, word, font);

                if (curX + wordSize.Width > rect.Size.Width)
                {
                    curX      = 0;
                    curY      = curY + fontHeight;
                    wordPoint = new PointF(curX, curY);
                }

                PointF wordPointOffset = new PointF(rect.X + wordPoint.X, rect.Y + wordPoint.Y);
                resolver.DrawString(graphics, word, font, brush, wordPointOffset);
                curX += wordSize.Width;
            }
        }
        /// <summary>
        /// Constructs an assertion failure.
        /// </summary>
        /// <param name="native">The native unmanged object describing the failure.</param>
        /// <param name="stringResolver">A service to resolve unmanaged unicode strings.</param>
        public MbUnitCppAssertionFailure(NativeAssertionFailure native, IStringResolver stringResolver)
        {
            description = stringResolver.GetString(native.DescriptionId);
            message = stringResolver.GetString(native.MessageId);
            hasActualValue = native.ActualValue.IsValid;
            hasExpectedValue = native.ExpectedValue.IsValid;
            hasUnexpectedValue = native.UnexpectedValue.IsValid;
            line = native.Line;

            if (hasActualValue)
                actualValue = NativeValueParser.Parse(stringResolver.GetString(native.ActualValue.ValueId), native.ActualValue.ValueType);

            if (hasExpectedValue)
                expectedValue = NativeValueParser.Parse(stringResolver.GetString(native.ExpectedValue.ValueId), native.ExpectedValue.ValueType);

            if (hasUnexpectedValue)
                unexpectedValue = NativeValueParser.Parse(stringResolver.GetString(native.UnexpectedValue.ValueId), native.UnexpectedValue.ValueType);

            diffing = hasActualValue && (native.ActualValue.ValueType == NativeValueType.String) &&
                ((hasExpectedValue && (native.ExpectedValue.ValueType == NativeValueType.String)) ||
                (hasUnexpectedValue && (native.UnexpectedValue.ValueType == NativeValueType.String)));

            extraLabeledValues = GenericCollectionUtils.ToArray(GetExtraLabeledValues(native, stringResolver));
        }
示例#24
0
 private IEnumerable<KeyValuePair<string, string>> EnumerateMetadata(IStringResolver resolver)
 {
     string data = resolver.GetString(native.MetadataId);
     var matches = Regex.Matches(data, @"(?<key>\w+)=\{(?<value>[\w\s]+)\}");
     
     foreach (Match match in matches)
     {
         yield return new KeyValuePair<string, string>(match.Groups["key"].Value, match.Groups["value"].Value);
     }
 }