示例#1
0
        public static string ApplyCase(string[] words, TermCase termCase)
        {
            words.CheckNotNull(nameof(words));

            if (!words.Any())
            {
                return(string.Empty);
            }

            if (termCase == TermCase.None)
            {
                return(string.Concat(words));
            }

            FormatterItem formatterItem;

            if (!Formatters.TryGetValue(termCase, out formatterItem))
            {
                throw ExceptionFactory.CreateForUnsupportedEnumValue(termCase, nameof(termCase));
            }

            string formattedValue = formatterItem.Formatter.Format(words);

            if (!string.IsNullOrWhiteSpace(formatterItem.StringFormat))
            {
                formattedValue = string.Format(formatterItem.StringFormat, formattedValue);
            }

            return(formattedValue);
        }
        private static Status ResolveLogStatus(LogEventInfo eventInfo)
        {
            switch (eventInfo.Level)
            {
            case LogLevel.Trace:
                return(Status.Debug);

            case LogLevel.Debug:
                return(Status.Debug);

            case LogLevel.Info:
                if (eventInfo.SectionEnd is VerificationLogSection)
                {
                    if (eventInfo.SectionEnd.Exception != null)
                    {
                        return(Status.Fail);
                    }
                    else if (!eventInfo.SectionEnd.Message.StartsWith("Wait", StringComparison.Ordinal))
                    {
                        var lastLogLevel = ExtentContext.ResolveFor(eventInfo.Context)
                                           .LastLogEvent.Level;

                        if (lastLogLevel != LogLevel.Error && lastLogLevel != LogLevel.Warn)
                        {
                            return(Status.Pass);
                        }
                    }
                }

                return(Status.Info);

            case LogLevel.Warn:
                return(Status.Warning);

            case LogLevel.Error:
                return(Status.Fail);

            case LogLevel.Fatal:
                return(Status.Fatal);

            default:
                throw ExceptionFactory.CreateForUnsupportedEnumValue(eventInfo.Level, $"{nameof(eventInfo)}.{nameof(LogEventInfo.Level)}");
            }
        }
        public static ILayerScopeContextResolver Create(FindAs findAs)
        {
            switch (findAs)
            {
            case FindAs.Parent:
                return(ParentResolver);

            case FindAs.Sibling:
                return(SiblingResolver);

            case FindAs.Ancestor:
                return(AncestorResolver);

            case FindAs.ShadowHost:
                return(ShadowHostResolver);

            default:
                throw ExceptionFactory.CreateForUnsupportedEnumValue(findAs, nameof(findAs));
            }
        }
示例#4
0
        /// <summary>
        /// Gets the content of the component using <see cref="ContentSource"/> value.
        /// </summary>
        /// <typeparam name="TOwner">The type of the owner page object.</typeparam>
        /// <param name="component">The component.</param>
        /// <param name="contentSource">The content source.</param>
        /// <returns>The content.</returns>
        public static string Get <TOwner>(IUIComponent <TOwner> component, ContentSource contentSource)
            where TOwner : PageObject <TOwner>, IPageObject <TOwner>
        {
            component.CheckNotNull(nameof(component));

            switch (contentSource)
            {
            case ContentSource.Text:
                return(component.Scope.Text);

            case ContentSource.TextContent:
                return(component.Attributes.TextContent);

            case ContentSource.InnerHtml:
                return(component.Attributes.InnerHtml);

            case ContentSource.Value:
                return(component.Attributes.Value);

            case ContentSource.ChildTextNodes:
                return(component.Script.ExecuteAgainst <string>(GetTextContentOfChildTextNodesScript));

            case ContentSource.ChildTextNodesTrimmed:
                return(component.Script.ExecuteAgainst <string>(GetTextContentOfChildTextNodesTrimmedScript));

            case ContentSource.ChildTextNodesTrimmedAndSpaceJoined:
                return(component.Script.ExecuteAgainst <string>(GetTextContentOfChildTextNodesTrimmedAndSpaceJoinedScript));

            case ContentSource.FirstChildTextNode:
                return(component.Script.ExecuteAgainst <string>(GetTextContentOfFirstChildTextNodeScript));

            case ContentSource.LastChildTextNode:
                return(component.Script.ExecuteAgainst <string>(GetTextContentOfLastChildTextNodeScript));

            default:
                throw ExceptionFactory.CreateForUnsupportedEnumValue(contentSource, nameof(contentSource));
            }
        }
示例#5
0
        private static Status ResolveLogStatus(LogEventInfo eventInfo)
        {
            switch (eventInfo.Level)
            {
            case LogLevel.Trace:
                return(Status.Debug);

            case LogLevel.Debug:
                return(Status.Debug);

            case LogLevel.Info:
                bool isEndOfVerificationLogSection = !(eventInfo.SectionEnd as VerificationLogSection)?.Message.StartsWith("Wait") ?? false;

                if (isEndOfVerificationLogSection)
                {
                    var lastLogLevel = ExtentContext.LastLogEventOfCurrentTest.Level;

                    if (lastLogLevel != LogLevel.Error && lastLogLevel != LogLevel.Warn)
                    {
                        return(Status.Pass);
                    }
                }

                return(Status.Info);

            case LogLevel.Warn:
                return(Status.Warning);

            case LogLevel.Error:
                return(Status.Fail);

            case LogLevel.Fatal:
                return(Status.Fatal);

            default:
                throw ExceptionFactory.CreateForUnsupportedEnumValue(eventInfo.Level, $"{nameof(eventInfo)}.{nameof(LogEventInfo.Level)}");
            }
        }
示例#6
0
        private static string ConvertToString(WaitBy waitBy)
        {
            switch (waitBy)
            {
            case WaitBy.Id:
                return("id");

            case WaitBy.Name:
                return("name");

            case WaitBy.Class:
                return("class");

            case WaitBy.Css:
                return("CSS selector");

            case WaitBy.XPath:
                return("XPath");

            default:
                throw ExceptionFactory.CreateForUnsupportedEnumValue(waitBy, nameof(waitBy));
            }
        }
        private static IUIComponent <TOwner> GetTargetComponent <TOwner>(IUIComponent <TOwner> component, ClearCacheTarget target)
            where TOwner : PageObject <TOwner>
        {
            switch (target)
            {
            case ClearCacheTarget.Self:
                return(component);

            case ClearCacheTarget.Parent:
                return(component.Parent ?? throw UIComponentNotFoundException.ForParentOf(component.ComponentFullName));

            case ClearCacheTarget.Grandparent:
                return(component.Parent?.Parent ?? throw UIComponentNotFoundException.ForGrandparentOf(component.ComponentFullName));

            case ClearCacheTarget.GreatGrandparent:
                return(component.Parent?.Parent?.Parent ?? throw UIComponentNotFoundException.ForGreatGrandparent(component.ComponentFullName));

            case ClearCacheTarget.PageObject:
                return(component.Owner);

            default:
                throw ExceptionFactory.CreateForUnsupportedEnumValue(target, nameof(target));
            }
        }