Пример #1
0
        /// <summary>
        /// Check that both negative indices as well as empty/null messages are caught and
        /// Result in ArgumentExceptions.
        /// </summary>
        public void EventHelperShouldThrowExceptionsForBadArguments(System.Type exceptionType, int indexValue, string message)
        {
            bool wantException = exceptionType != null;
            var  wrappedMsg    = message == null ? "null" : $"\"{message}\"";

            try
            {
                EventHelpers.CreateEventId(LogEventIds.LogEventIdSubsystem.Analysis, LogEventIds.LogEventIdLevel.Error, indexValue, message);
            }
            catch (Exception e)
            {
                if (!wantException)
                {
                    e.ShouldBeNull($"Should not have thrown exception for indexValue={indexValue}, message={wrappedMsg}");
                }
                e.ShouldBeOfType(exceptionType);
                return;
            }

            if (wantException)
            {
                // we shouldn't have gotten here, expected an exception, but didn't get one
                "No Exception".ShouldBeNull($"Missing {exceptionType.FullName} exception for indexValue={indexValue}, message={wrappedMsg}");
            }
        }
Пример #2
0
        /// <summary>
        /// Check that both EventHelper.CreateEventId and the EventId constructor proper create the same thing
        /// </summary>
        public void EventHelperShouldCreateExactSameEventViaAnyConstructor()
        {
            var subSystem = LogEventIds.LogEventIdSubsystem.Encode;
            var level     = LogEventIds.LogEventIdLevel.Debug;
            var index     = 22;
            var msgText   = "Some interesting text";

            int computedId   = ((int)level * 100000) + ((int)subSystem * 1000) + index;
            int ehComputedId = LogEventIds.GenerateId(level, subSystem, index);

            var ev1 = new EventId(computedId, msgText);
            var ev2 = EventHelpers.CreateEventId(subSystem, level, index, msgText);

            ehComputedId.ShouldBe(computedId, "LogEventIds.GenerateId != computed ID");
            ev1.GetLevelName().ShouldBe(ev2.GetLevelName());
            ev1.GetSubsystemName().ShouldBe(ev2.GetSubsystemName());
            ev1.Id.ShouldBe(ev2.Id);
            ev1.Name.ShouldBe(ev2.Name);
            ev1.GetHashCode().ShouldBe(ev2.GetHashCode());
        }