コード例 #1
0
        /// <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));
        }
コード例 #2
0
 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));
            }
        }
コード例 #7
0
        /// <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;
        }
コード例 #8
0
        /// <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();
        }
コード例 #9
0
        /// <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)
 {
 }
コード例 #17
0
 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));
         }
     }
 }
コード例 #18
0
 /// <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);
コード例 #19
0
 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)));
         }
     }
 }
コード例 #20
0
 /// <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
ファイル: UTString.cs プロジェクト: hexthedev/CardCreator
        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;
            }
        }
コード例 #23
0
        /// <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);
     }
 }