Exemplo n.º 1
0
        /// <summary>
        /// Ends the latest log section.
        /// </summary>
        public void EndSection()
        {
            if (_sectionEndStack.Any())
            {
                LogSection section = _sectionEndStack.Pop();

                section.Stopwatch.Stop();

                string message = $"{section.Message} ({section.ElapsedTime.ToLongIntervalString()})";

                if (section.IsResultSet)
                {
                    message = AppendSectionResultToMessage(message, section.Result);
                }
                else if (section.Exception != null)
                {
                    message = AppendSectionResultToMessage(message, section.Exception);
                }

                LogEventInfo eventInfo = _logEventInfoFactory.Create(section.Level, message);
                eventInfo.SectionEnd = section;

                Log(eventInfo);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Ends the latest log section.
        /// </summary>
        public void EndSection()
        {
            if (sectionEndStack.Any())
            {
                LogSection section = sectionEndStack.Pop();

                section.Stopwatch.Stop();

                string message = $"{section.Message} ({section.ElapsedTime.ToLongIntervalString()})";

                if (section.IsResultSet)
                {
                    message = AppendSectionResultToMessage(message, section.Result);
                }
                else if (section.Exception != null)
                {
                    message = AppendSectionResultToMessage(message, section.Exception);
                }

                LogEventInfo eventInfo = new LogEventInfo
                {
                    Level      = section.Level,
                    Message    = message,
                    SectionEnd = section
                };

                Log(eventInfo);
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Starts the specified log section.
        /// </summary>
        /// <param name="section">The log section.</param>
        /// <example>This sample shows how to log the data insertion to some control in the scope of the control.
        /// <code>
        /// string value = "new_value";
        /// Log.Start(new DataAdditionLogSection(this, value));
        /// // TODO: Add a value to the control.
        /// Log.EndSection();
        /// </code>
        /// </example>
        public void Start(LogSection section)
        {
            section.CheckNotNull(nameof(section));

            LogEventInfo eventInfo = _logEventInfoFactory.Create(section.Level, section.Message);

            eventInfo.SectionStart = section;

            section.StartedAt = eventInfo.Timestamp;
            section.Stopwatch.Start();

            Log(eventInfo);

            _sectionEndStack.Push(section);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Ends the latest log section.
        /// </summary>
        public void EndSection()
        {
            if (sectionEndStack.Any())
            {
                LogSection section = sectionEndStack.Pop();

                TimeSpan duration = section.GetDuration();

                LogEventInfo eventInfo = new LogEventInfo
                {
                    Level      = section.Level,
                    Message    = $"Finished: {section.Message} ({duration.ToIntervalString()})",
                    SectionEnd = section
                };

                Log(eventInfo, true);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Ends the latest log section.
        /// </summary>
        public void EndSection()
        {
            if (sectionEndStack.Any())
            {
                LogSection section = sectionEndStack.Pop();

                TimeSpan duration = section.GetDuration();

                LogEventInfo eventInfo = new LogEventInfo
                {
                    Level      = section.Level,
                    Message    = $"Finished: {section.Message} ({Math.Floor(duration.TotalSeconds)}.{duration:fff}s)",
                    SectionEnd = section
                };

                Log(eventInfo, true);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Starts the specified log section.
        /// </summary>
        /// <param name="section">The log section.</param>
        /// <example>This sample shows how to log the data insertion to some control in the scope of the control.
        /// <code>
        /// string value = "new_value";
        /// Log.Start(new DataAdditionLogSection(this, value));
        /// // TODO: Add a value to the control.
        /// Log.EndSection();
        /// </code>
        /// </example>
        public void Start(LogSection section)
        {
            section.CheckNotNull(nameof(section));

            LogEventInfo eventInfo = new LogEventInfo
            {
                Level        = section.Level,
                Message      = section.Message,
                SectionStart = section
            };

            section.StartedAt = eventInfo.Timestamp;
            section.Stopwatch.Start();

            Log(eventInfo);

            sectionEndStack.Push(section);
        }
Exemplo n.º 8
0
        internal static TOwner Verify <TData, TOwner>(IDataVerificationProvider <TData, TOwner> should, Action verificationAction, string expectedMessage, params TData[] arguments)
        {
            if (AtataContext.Current is null)
            {
                verificationAction.Invoke();
            }
            else
            {
                string verificationConstraintMessage = BuildConstraintMessage(should, expectedMessage, arguments);

                LogSection logSection = should.DataProvider.Component is null
                    ? (LogSection) new ValueVerificationLogSection(should.Strategy.VerificationKind, should.DataProvider.ProviderName, verificationConstraintMessage)
                    : new VerificationLogSection(should.Strategy.VerificationKind, should.DataProvider.Component, should.DataProvider.ProviderName, verificationConstraintMessage);

                AtataContext.Current.Log.ExecuteSection(logSection, verificationAction);
            }

            return(should.Owner);
        }
Exemplo n.º 9
0
        public void ExecuteSection(LogSection section, Action action)
        {
            action.CheckNotNull(nameof(action));

            Start(section);

            try
            {
                action?.Invoke();
            }
            catch (Exception exception)
            {
                section.Exception = exception;
                throw;
            }
            finally
            {
                EndSection();
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Starts the specified log section.
        /// </summary>
        /// <param name="section">The log section.</param>
        /// <example>This sample shows how to log the data insertion to some control in the scope of the control.
        /// <code>
        /// string value = "new_value";
        /// Log.Start(new DataAdditionLogSection(this, value));
        /// // TODO: Add a value to the control.
        /// Log.EndSection();
        /// </code>
        /// </example>
        public void Start(LogSection section)
        {
            section.CheckNotNull(nameof(section));

            LogEventInfo eventInfo = new LogEventInfo
            {
                Level        = section.Level,
                Message      = section.Message,
                SectionStart = section
            };

            section.StartedAt = eventInfo.Timestamp;

            Log(eventInfo, false);

            eventInfo.Message = $"Starting: {eventInfo.Message}";

            Log(eventInfo, true);

            sectionEndStack.Push(section);
        }
Exemplo n.º 11
0
        public TResult ExecuteSection <TResult>(LogSection section, Func <TResult> function)
        {
            function.CheckNotNull(nameof(function));

            Start(section);

            try
            {
                TResult result = function.Invoke();
                section.Result = result;
                return(result);
            }
            catch (Exception exception)
            {
                section.Exception = exception;
                throw;
            }
            finally
            {
                EndSection();
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// Starts the specified log section.
 /// </summary>
 /// <param name="section">The log section.</param>
 /// <returns>The instance of the owner object.</returns>
 public TOwner Start(LogSection section)
 {
     logManager.Start(section);
     return(owner);
 }
Exemplo n.º 13
0
        /// <summary>
        /// Starts the specified log section.
        /// </summary>
        /// <param name="section">The log section.</param>
        /// <example>This sample shows how to log the data insertion to some control in the scope of the control.
        /// <code>
        /// string value = "new_value";
        /// Log.Start(new DataAdditionLogSection(this, value));
        /// // TODO: Add a value to the control.
        /// Log.EndSection();
        /// </code>
        /// </example>
        public void Start(LogSection section)
        {
            section.CheckNotNull(nameof(section));

            LogEventInfo eventInfo = new LogEventInfo
            {
                Level = section.Level,
                Message = section.Message,
                SectionStart = section
            };

            section.StartedAt = eventInfo.Timestamp;

            Log(eventInfo, false);

            eventInfo.Message = $"Starting: {eventInfo.Message}";

            Log(eventInfo, true);

            sectionEndStack.Push(section);
        }
Exemplo n.º 14
0
        public static TOwner Satisfy <TData, TOwner>(
            this IDataVerificationProvider <IEnumerable <IDataProvider <TData, TOwner> >, 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 = 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);
                }
            }

            if (AtataContext.Current is null)
            {
                ExecuteVerification();
            }
            else
            {
                string verificationConstraintMessage = $"{should.GetShouldText()} {expectedMessage}";

                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);
        }