示例#1
0
        public void RaiseLogEvent_WithEvent_Logs()
        {
            LogEventArgs eventArgs = new LogEventArgs(null, false, 0, Categories.ArgumentValidation, Levels.Warning, "Message", string.Empty);

            UntaggedLogging.RaiseLogEvent(null, eventArgs);
            Assert.Equal(1, LoggedEvents.Count);
            Assert.Same(eventArgs, LoggedEvents[0]);
        }
示例#2
0
        public void LogTraceTag_ShouldLog(Levels.LogLevel logLevel)
        {
            FailOnErrors = false;

            UntaggedLogging.LogTraceTag(0, Categories.ArgumentValidation, Levels.LevelFromLogLevel(logLevel), "Test message");

            Assert.Equal(1, LoggedEvents.Count);
            Assert.Equal(Levels.LevelFromLogLevel(logLevel), LoggedEvents[0].Level);
        }
示例#3
0
文件: Code.cs 项目: tharshada/Omex
        public static bool Validate(bool state, uint?tagId, string errorMessage, params object[] parameters)
        {
            if (!state)
            {
                if (tagId != null)
                {
                    UntaggedLogging.LogTraceTag(tagId.Value, Categories.ArgumentValidation, Levels.Error, errorMessage, parameters);
                }
            }

            return(state);
        }
示例#4
0
文件: Code.cs 项目: tharshada/Omex
        public static bool ValidateArgument(Guid argumentValue, string argumentName, uint?tagId = null)
        {
            if (argumentValue.Equals(Guid.Empty))
            {
                if (tagId != null)
                {
                    UntaggedLogging.LogTraceTag(tagId.Value, Categories.ArgumentValidation, Levels.Error,
                                                ValidationFailed, ArgumentIsEmptyGuid, argumentName);
                }

                return(false);
            }

            return(true);
        }
示例#5
0
文件: Code.cs 项目: tharshada/Omex
        public static bool ValidateArgument <T>(T argumentValue, string argumentName, Func <T, bool> predicate, string errorMessage, uint?tagId)
        {
            if (!predicate(argumentValue))
            {
                if (tagId != null)
                {
                    UntaggedLogging.LogTraceTag(tagId.Value, Categories.ArgumentValidation, Levels.Error,
                                                ValidationFailed, errorMessage, argumentName);
                }

                return(false);
            }

            return(true);
        }
示例#6
0
文件: Code.cs 项目: tharshada/Omex
        public static bool ValidateArgument([NotNullWhen(true)] object?argumentValue, string argumentName, uint?tagId)
        {
            if (argumentValue == null)
            {
                if (tagId != null)
                {
                    UntaggedLogging.LogTraceTag(tagId.Value, Categories.ArgumentValidation, Levels.Error,
                                                ValidationFailed, ArgumentIsNull, argumentName);
                }

                return(false);
            }

            return(true);
        }
示例#7
0
        public void ReportExceptionTag_ShouldLog()
        {
            FailOnErrors = false;

            string message = "Should log exception";

            UntaggedLogging.ReportExceptionTag(0, Categories.ArgumentValidation, new ArgumentNullException(), message);

            Assert.Equal(1, LoggedEvents.Count);
            ReportExceptionEventArgs exceptionEventArgs = LoggedEvents[0] as ReportExceptionEventArgs;

            Assert.NotNull(exceptionEventArgs);
            Assert.Equal(message, exceptionEventArgs.Message);
            Assert.Equal(Levels.Error, exceptionEventArgs.Level);
            Assert.NotNull(exceptionEventArgs.Exception);
            Assert.Equal(typeof(ArgumentNullException), exceptionEventArgs.Exception.GetType());
            Assert.Equal(Categories.ArgumentValidation, exceptionEventArgs.CategoryId);
        }
示例#8
0
文件: Code.cs 项目: tharshada/Omex
        public static bool ValidateNotNullOrWhiteSpaceArgument([NotNullWhen(true)] string?argumentValue, string argumentName, uint?tagId = null)
        {
            if (string.IsNullOrWhiteSpace(argumentValue))
            {
                if (ValidateArgument(argumentValue, argumentName, tagId))
                {
                    if (tagId != null)
                    {
                        UntaggedLogging.LogTraceTag(tagId.Value, Categories.ArgumentValidation, Levels.Error,
                                                    ValidationFailed,
                                                    argumentName.Length == 0 ? ArgumentContainsEmptyString : ArgumentContainsWhiteSpaceString,
                                                    argumentName);
                    }
                }

                return(false);
            }

            return(true);
        }
示例#9
0
文件: Code.cs 项目: tharshada/Omex
        public static bool ValidateAny <T>([NotNullWhen(true)] IEnumerable <T>?argumentValue, string argumentName, uint?tagId)
        {
            if (!ValidateArgument(argumentValue, argumentName, tagId))
            {
                return(false);
            }

            if (!argumentValue.Any())
            {
                if (tagId != null)
                {
                    UntaggedLogging.LogTraceTag(tagId.Value, Categories.ArgumentValidation, Levels.Error,
                                                ValidationFailed, HasAnyErrorMessage, argumentName);
                }

                return(false);
            }

            return(true);
        }
示例#10
0
文件: Code.cs 项目: tharshada/Omex
        public static bool ValidateNotEmptyAndAllNotNull <T>([NotNullWhen(true)] ICollection <T>?argumentValue, string argumentName, uint?tagId)
            where T : class
        {
            if (!ValidateArgument(argumentValue, argumentName, tagId))
            {
                return(false);
            }

            if (!argumentValue.Any() || argumentValue.Any(x => x == null))
            {
                if (tagId != null)
                {
                    UntaggedLogging.LogTraceTag(tagId.Value, Categories.ArgumentValidation, Levels.Error,
                                                ValidationFailed, AllErrorMessage, argumentName);
                }

                return(false);
            }

            return(true);
        }
示例#11
0
        /// <summary>
        /// Checks that the enumerable argument is not null and doesn't contain any nulls
        /// </summary>
        /// <remarks>Be careful to not pass enumerables that can be enumerated only once</remarks>
        /// <typeparam name="T">Type of the enumerable</typeparam>
        /// <param name="argumentValue">The argument value.</param>
        /// <param name="argumentName">Name of the argument.</param>
        /// <param name="tagId">Tag Id to log, leave null if no logging is needed</param>
        /// <returns>True if the argument <paramref name="argumentValue"/> is not null and contains only non-null elements; false otherwise.</returns>
        public static bool ValidateAllNotNull <T>(IEnumerable <T> argumentValue, string argumentName, uint?tagId)
            where T : class
        {
            if (!ValidateArgument(argumentValue, argumentName, tagId))
            {
                return(false);
            }

            if (argumentValue.Any(x => x == null))
            {
                if (tagId != null)
                {
                    UntaggedLogging.LogTraceTag(tagId.Value, Categories.ArgumentValidation, Levels.Error,
                                                ValidationFailed, AllErrorMessage, argumentName);
                }

                return(false);
            }

            return(true);
        }
示例#12
0
 public void RaiseLogEvent_WithoutEvent_DoesNotLog()
 {
     UntaggedLogging.RaiseLogEvent(null, null);
     Assert.Empty(LoggedEvents);
 }