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(CollectionToString(args)) : message; string verificationConstraintMessage = $"{should.GetShouldText()} {expectedMessage}"; AtataContext.Current.Log.Start(new VerificationLogSection(should.DataProvider.Component, should.DataProvider.ProviderName, verificationConstraintMessage)); IEnumerable <TData> actual = null; bool doesSatisfy = AtataContext.Current.Driver.Try().Until( _ => { actual = should.DataProvider.Value?.Select(x => x.Value).ToArray(); return(predicate(actual) != should.IsNegation); }, should.Timeout, should.RetryInterval); if (!doesSatisfy) { throw should.CreateAssertionException(expectedMessage, CollectionToString(actual)); } AtataContext.Current.Log.EndSection(); return(should.Owner); }
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 = BuildVerificationConstraintMessage(should, message, args); AtataContext.Current.Log.Start(new VerificationLogSection(should.DataProvider.Component, should.DataProvider.ProviderName, verificationConstraintMessage)); TData actual = default(TData); bool doesSatisfy = AtataContext.Current.Driver.Try().Until( _ => { actual = should.DataProvider.Value; return(predicate(actual) != should.IsNegation); }, should.Timeout, should.RetryInterval); if (!doesSatisfy) { throw CreateAssertionException(should, actual, message, args); } AtataContext.Current.Log.EndSection(); return(should.Owner); }
public static TOwner Satisfy <TData, TOwner>(this IDataVerificationProvider <TData, TOwner> should, Predicate <TData> predicate, string message, params TData[] args) { should.CheckNotNull(nameof(should)); predicate.CheckNotNull(nameof(predicate)); void ExecuteVerification() { TData actual = default; Exception exception = null; bool doesSatisfy = ExecuteUntil( () => { 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); } } if (AtataContext.Current is null) { ExecuteVerification(); } else { string verificationConstraintMessage = VerificationUtils.BuildConstraintMessage(should, message, args); LogSection logSection = should.DataProvider.Component is null ? (LogSection) new ValueVerificationLogSection(should.VerificationKind, should.DataProvider.ProviderName, verificationConstraintMessage) : new VerificationLogSection(should.VerificationKind, should.DataProvider.Component, should.DataProvider.ProviderName, verificationConstraintMessage); AtataContext.Current.Log.ExecuteSection(logSection, ExecuteVerification); } 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(Stringifier.ToString(args)) : message; string verificationConstraintMessage = $"{should.GetShouldText()} {expectedMessage}"; AtataContext.Current.Log.ExecuteSection( 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 ? Stringifier.ToString(actual) : null; string failureMessage = VerificationUtils.BuildFailureMessage(should, expectedMessage, actualMessage); should.ReportFailure(failureMessage, exception); } }); return(should.Owner); }
/// <summary> /// Verifies that object 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> /// TODO: Atata v2. Change type of predicate from "Predicate" to "Func". public static TOwner Satisfy <TData, TOwner>( this IDataVerificationProvider <TData, TOwner> should, Predicate <TData> predicate, string message, params TData[] args) { should.CheckNotNull(nameof(should)); predicate.CheckNotNull(nameof(predicate)); void ExecuteVerification() { TData actual = default; Exception exception = null; bool doesSatisfy = VerificationUtils.ExecuteUntil( () => { 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 shortenExpectedMessage = null; bool isExpectedMessageShorten = !should.IsNegation && TryShortenExpectedMessage(message, out shortenExpectedMessage); string expectedMessage = VerificationUtils.BuildExpectedMessage( isExpectedMessageShorten ? shortenExpectedMessage : message, args?.Cast <object>().ToArray()); string actualMessage = exception == null?Stringifier.ToString(actual) : null; string failureMessage = VerificationUtils.BuildFailureMessage(should, expectedMessage, actualMessage, !isExpectedMessageShorten); should.ReportFailure(failureMessage, exception); } } return(VerificationUtils.Verify(should, ExecuteVerification, message, args)); }
/// <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 IDataVerificationProvider <TData, TOwner> WithSettings <TData, TOwner>(this IDataVerificationProvider <TData, TOwner> should, IVerificationProvider <TOwner> sourceVerificationProvider) where TOwner : PageObject <TOwner> { should.CheckNotNull(nameof(should)); sourceVerificationProvider.CheckNotNull(nameof(sourceVerificationProvider)); IDataVerificationProvider <TData, TOwner> resultVerificationProvider = sourceVerificationProvider.IsNegation && !should.IsNegation ? GetNegationVerificationProvider(should) : should; resultVerificationProvider.Timeout = sourceVerificationProvider.Timeout; resultVerificationProvider.RetryInterval = sourceVerificationProvider.RetryInterval; return(resultVerificationProvider); }
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.VerificationKind, 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()); 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); }