예제 #1
0
        public void ReportFailure(string message, Exception exception)
        {
            string completeMessage = $"Unexpected {message}";

            completeMessage = VerificationUtils.AppendExceptionToFailureMessage(completeMessage, exception);

            string       stackTrace = VerificationUtils.BuildStackTraceForAggregateAssertion();
            AtataContext context    = AtataContext.Current;

            context.AssertionResults.Add(AssertionResult.ForWarning(completeMessage, stackTrace));
            context.Log.Warn(completeMessage);

            context.WarningReportStrategy.Report(completeMessage, stackTrace);
        }
        public static TOwner HaveChecked <TData, TOwner>(this IFieldVerificationProvider <TData, CheckBoxList <TData, TOwner>, TOwner> should, TData value)
            where TOwner : PageObject <TOwner>
        {
            should.CheckNotNull(nameof(should));

            IEnumerable <TData> expectedIndividualValues = should.Component.GetIndividualValues(value);
            string expectedIndividualValuesAsString      = should.Component.ConvertIndividualValuesToString(expectedIndividualValues, true);

            string expectedMessage = new StringBuilder().
                                     Append("have checked").
                                     AppendIf(expectedIndividualValues.Count() > 1, ":").
                                     Append($" {expectedIndividualValuesAsString}").ToString();

            AtataContext.Current.Log.Start(new VerificationLogSection(should.Component, $"{should.GetShouldText()} {expectedMessage}"));

            IEnumerable <TData> actualIndividualValues = null;
            Exception           exception = null;

            bool doesSatisfy = AtataContext.Current.Driver.Try().Until(
                _ =>
            {
                try
                {
                    actualIndividualValues = should.Component.GetIndividualValues(should.Component.Get());
                    int intersectionsCount = expectedIndividualValues.Intersect(actualIndividualValues).Count();
                    bool result            = should.IsNegation ? intersectionsCount == 0 : intersectionsCount == expectedIndividualValues.Count();
                    exception = null;
                    return(result);
                }
                catch (Exception e)
                {
                    exception = e;
                    return(false);
                }
            },
                should.GetRetryOptions());

            if (!doesSatisfy)
            {
                throw VerificationUtils.CreateAssertionException(
                          should,
                          expectedMessage,
                          should.Component.ConvertIndividualValuesToString(actualIndividualValues, true),
                          exception);
            }

            AtataContext.Current.Log.EndSection();

            return(should.Owner);
        }
예제 #3
0
        public static TOwner ExistSoft <TComponent, TOwner>(this IUIComponentVerificationProvider <TComponent, TOwner> should)
            where TComponent : UIComponent <TOwner>
            where TOwner : PageObject <TOwner>
        {
            should.CheckNotNull(nameof(should));

            string expectedMessage = "exist";

            AtataContext.Current.Log.Start(new VerificationLogSection(should.Component, $"{should.GetShouldText()} {expectedMessage}"));

            SearchOptions searchOptions = new SearchOptions
            {
                IsSafely      = false,
                Timeout       = should.Timeout ?? AtataContext.Current.VerificationTimeout,
                RetryInterval = should.RetryInterval ?? AtataContext.Current.VerificationRetryInterval
            };

            try
            {
                StaleSafely.Execute(
                    options =>
                {
                    if (should.IsNegation)
                    {
                        should.Component.Missing(options);
                    }
                    else
                    {
                        should.Component.Exists(options);
                    }
                },
                    searchOptions);
            }
            catch (Exception exception)
            {
                AtataContext.Current.Log.Info("NOT Exists!");
                StringBuilder messageBuilder = new StringBuilder().
                                               Append($"Invalid {should.Component.ComponentFullName} presence.").
                                               AppendLine().
                                               Append($"Expected: {should.GetShouldText()} {expectedMessage}");

                Exception ex = VerificationUtils.CreateAssertionException(messageBuilder.ToString(), exception);
                ExceptionResults.AddExecptionMessage(ex.Message);
            }
            AtataContext.Current.Log.Info("component styles: " + should.Component.Content);
            AtataContext.Current.Log.EndSection();

            return(should.Owner);
        }
        public static TOwner Satisfy <TData, TOwner>(this IDataVerificationProvider <IEnumerable <IDataProvider <TData, TOwner> >, TOwner> should, Predicate <IEnumerable <TData> > predicate, string message, params TData[] args)
            where TOwner : PageObject <TOwner>
        {
            should.CheckNotNull(nameof(should));
            predicate.CheckNotNull(nameof(predicate));

            string expectedMessage = (args != null && args.Any())
                ? message?.FormatWith(VerificationUtils.ToString(args))
                : message;

            string verificationConstraintMessage = $"{should.GetShouldText()} {expectedMessage}";

            AtataContext.Current.Log.Start(new VerificationLogSection(should.VerificationKind, should.DataProvider.Component, should.DataProvider.ProviderName, verificationConstraintMessage));

            IEnumerable <TData> actual    = null;
            Exception           exception = null;

            bool doesSatisfy = AtataContext.Current.Driver.Try().Until(
                _ =>
            {
                try
                {
                    actual      = should.DataProvider.Value?.Select(x => x.Value).ToArray();
                    bool result = predicate(actual) != should.IsNegation;
                    exception   = null;
                    return(result);
                }
                catch (Exception e)
                {
                    exception = e;
                    return(false);
                }
            },
                should.GetRetryOptions());

            if (!doesSatisfy)
            {
                string actualMessage = exception == null?VerificationUtils.ToString(actual) : null;

                string failureMessage = VerificationUtils.BuildFailureMessage(should, expectedMessage, actualMessage);

                should.ReportFailure(failureMessage, exception);
            }

            AtataContext.Current.Log.EndSection();

            return(should.Owner);
        }
예제 #5
0
        /// <summary>
        /// Verifies that collection satisfies the specified predicate.
        /// </summary>
        /// <typeparam name="TData">The type of the data.</typeparam>
        /// <typeparam name="TOwner">The type of the owner.</typeparam>
        /// <param name="should">The verification provider.</param>
        /// <param name="predicate">The predicate.</param>
        /// <param name="message">The message that should sound in a way of "{Something} should {message}".</param>
        /// <param name="args">The message arguments.</param>
        /// <returns>The owner instance.</returns>
        public static TOwner Satisfy <TData, TOwner>(
            this IDataVerificationProvider <IEnumerable <IObjectProvider <TData> >, TOwner> should,
            Predicate <IEnumerable <TData> > predicate,
            string message,
            params TData[] args)
        {
            should.CheckNotNull(nameof(should));
            predicate.CheckNotNull(nameof(predicate));

            string expectedMessage = (args != null && args.Any())
                ? message?.FormatWith(Stringifier.ToString(args))
                : message;

            void ExecuteVerification()
            {
                IEnumerable <TData> actual    = null;
                Exception           exception = null;

                bool doesSatisfy = VerificationUtils.ExecuteUntil(
                    () =>
                {
                    try
                    {
                        actual      = should.DataProvider.Value?.Select(x => x.Value).ToArray();
                        bool result = predicate(actual) != should.IsNegation;
                        exception   = null;
                        return(result);
                    }
                    catch (Exception e)
                    {
                        exception = e;
                        return(false);
                    }
                },
                    should.GetRetryOptions());

                if (!doesSatisfy)
                {
                    string actualMessage = exception == null?Stringifier.ToString(actual) : null;

                    string failureMessage = VerificationUtils.BuildFailureMessage(should, expectedMessage, actualMessage);

                    should.ReportFailure(failureMessage, exception);
                }
            }

            return(VerificationUtils.Verify(should, ExecuteVerification, expectedMessage));
        }
        public static TOwner Satisfy <TData, TOwner>(this IDataVerificationProvider <TData, TOwner> should, Predicate <TData> predicate, string message, params TData[] args)
            where TOwner : PageObject <TOwner>
        {
            should.CheckNotNull(nameof(should));
            predicate.CheckNotNull(nameof(predicate));

            string verificationConstraintMessage = VerificationUtils.BuildConstraintMessage(should, message, args);

            AtataContext.Current.Log.ExecuteSection(
                new VerificationLogSection(should.VerificationKind, should.DataProvider.Component, should.DataProvider.ProviderName, verificationConstraintMessage),
                () =>
            {
                TData actual        = default;
                Exception exception = null;

                bool doesSatisfy = AtataContext.Current.Driver.Try().Until(
                    _ =>
                {
                    try
                    {
                        actual      = should.DataProvider.Value;
                        bool result = predicate(actual) != should.IsNegation;
                        exception   = null;
                        return(result);
                    }
                    catch (Exception e)
                    {
                        exception = e;
                        return(false);
                    }
                },
                    should.GetRetryOptions());

                if (!doesSatisfy)
                {
                    string expectedMessage = VerificationUtils.BuildExpectedMessage(message, args?.Cast <object>().ToArray());
                    string actualMessage   = exception == null ? Stringifier.ToString(actual) : null;

                    string failureMessage = VerificationUtils.BuildFailureMessage(should, expectedMessage, actualMessage);

                    should.ReportFailure(failureMessage, exception);
                }
            });

            return(should.Owner);
        }
            public TOwner Throw()
            {
                string expectedMessage = $"throw exception";

                void ExecuteVerification()
                {
                    Exception exception = null;

                    bool doesSatisfy = VerificationUtils.ExecuteUntil(
                        () =>
                    {
                        try
                        {
                            var actual = DataProvider.Value;

                            if (actual is Action actualAsAction)
                            {
                                actualAsAction.Invoke();
                            }

                            exception = null;

                            return(true);
                        }
                        catch (Exception e)
                        {
                            exception = e;
                            return(false);
                        }
                    },
                        GetRetryOptions());

                    if (!doesSatisfy)
                    {
                        string actualMessage = exception.ToString();

                        string failureMessage = VerificationUtils.BuildFailureMessage(this, expectedMessage, actualMessage);

                        ReportFailure(failureMessage, null);
                    }
                }

                return(VerificationUtils.Verify(this, ExecuteVerification, expectedMessage));
            }
        public static TOwner Satisfy <TData, TOwner>(this IDataVerificationProvider <TData, TOwner> should, Predicate <TData> predicate, string message, params TData[] args)
            where TOwner : PageObject <TOwner>
        {
            should.CheckNotNull(nameof(should));
            predicate.CheckNotNull(nameof(predicate));

            string verificationConstraintMessage = VerificationUtils.BuildConstraintMessage(should, message, args);

            AtataContext.Current.Log.Start(new VerificationLogSection(should.DataProvider.Component, should.DataProvider.ProviderName, verificationConstraintMessage));

            TData     actual    = default(TData);
            Exception exception = null;

            bool doesSatisfy = AtataContext.Current.Driver.Try().Until(
                _ =>
            {
                try
                {
                    actual      = should.DataProvider.Value;
                    bool result = predicate(actual) != should.IsNegation;
                    exception   = null;
                    return(result);
                }
                catch (Exception e)
                {
                    exception = e;
                    return(false);
                }
            },
                should.GetRetryOptions());

            if (!doesSatisfy)
            {
                string expectedMessage = VerificationUtils.BuildExpectedMessage(message, args?.Cast <object>().ToArray());
                throw VerificationUtils.CreateAssertionException(should, expectedMessage, VerificationUtils.ToString(actual), exception);
            }

            AtataContext.Current.Log.EndSection();

            return(should.Owner);
        }
예제 #9
0
        public void ReportFailure(string message, Exception exception)
        {
            string completeMessage = $"Wrong {message}";

            string completeMessageWithException = VerificationUtils.AppendExceptionToFailureMessage(completeMessage, exception);
            string stackTrace = VerificationUtils.BuildStackTraceForAggregateAssertion();

            AtataContext context = AtataContext.Current;

            context.AssertionResults.Add(AssertionResult.ForFailure(completeMessageWithException, stackTrace));

            if (context.AggregateAssertionLevel == 0)
            {
                throw VerificationUtils.CreateAssertionException(completeMessage, exception);
            }
            else
            {
                context.Log.Error(completeMessage);
                context.AggregateAssertionStrategy.ReportFailure(completeMessageWithException, stackTrace);
            }
        }
예제 #10
0
        public void ReportFailure(string message, Exception exception)
        {
            string completeMessage = $"Unexpected {message}";
            string completeMessageWithException = VerificationUtils.AppendExceptionToFailureMessage(completeMessage, exception);

            string       stackTrace = VerificationUtils.BuildStackTraceForAggregateAssertion();
            AtataContext context    = AtataContext.Current;

            if (context != null)
            {
                context.AssertionResults.Add(AssertionResult.ForWarning(completeMessageWithException, stackTrace));
                context.Log.Warn(completeMessageWithException);

                context.WarningReportStrategy.Report(completeMessageWithException, stackTrace);
            }
            else
            {
                throw new InvalidOperationException(
                          $"Cannot report warning to {nameof(AtataContext)}.{nameof(AtataContext.Current)} as current context is null.",
                          VerificationUtils.CreateAssertionException(completeMessage, exception));
            }
        }
        public static TOwner ContainHavingContent <TControl, TOwner>(this IDataVerificationProvider <IEnumerable <TControl>, TOwner> should, TermMatch match, params string[] expected)
            where TControl : Control <TOwner>
            where TOwner : PageObject <TOwner>
        {
            expected.CheckNotNullOrEmpty(nameof(expected));

            return(should.Satisfy(
                       actual =>
            {
                if (actual == null)
                {
                    return false;
                }

                var actualValues = actual.Select(x => x.Content.Value).ToArray();
                return should.IsNegation
                        ? expected.Any(expectedValue => actualValues.Any(actualValue => match.IsMatch(actualValue, expectedValue)))
                        : expected.All(expectedValue => actualValues.Any(actualValue => match.IsMatch(actualValue, expectedValue)));
            },
                       $"contain having content that {match.ToString(TermCase.MidSentence)} {VerificationUtils.ToString(expected)}"));
        }
        public static TOwner Contain <TOwner>(this IDataVerificationProvider <IEnumerable <IDataProvider <string, TOwner> >, TOwner> should, TermMatch match, params string[] expected)
            where TOwner : PageObject <TOwner>
        {
            expected.CheckNotNullOrEmpty(nameof(expected));

            return(should.Satisfy(
                       actual => actual != null && should.IsNegation
                    ? expected.Any(expectedValue => actual.Any(actualValue => match.IsMatch(actualValue, expectedValue)))
                    : expected.All(expectedValue => actual.Any(actualValue => match.IsMatch(actualValue, expectedValue))),
                       $"contain having value that {match.ToString(TermCase.MidSentence)} {VerificationUtils.ToString(expected)}"));
        }