コード例 #1
0
        public void HandleUnexpectedLogsCorrectly()
        {
            try
            {
                throw new ApplicationException("Troll in the Dungeon");
            }
            catch (Exception e)
            {
                const string expectedMessage = "Caught unexpected 'ApplicationException': 'Troll in the Dungeon'";

                var testLogger = new TestLogger(expectedMessage);
                ErrorPolicy.HandleUnexpected(e, testLogger);

                testLogger.MessageSeen.Should().BeTrue();
                testLogger.SeenCount.Should().Be(1);
                testLogger.FullMessage.Should().Be(expectedMessage);
            }
        }
コード例 #2
0
#pragma warning default CA1063  // Implement IDisposable correctly.

        /// <summary>
        /// Attempt to query the backlog length of the queue.
        /// </summary>
        /// <param name="count">The (approximate) count of items in the Channel.</param>
        /// <returns>true if it managed to get count.</returns>
        public bool TryGetCount(out int count)
        {
            // get this using the reflection
            try
            {
                var prop = _sendChannel.GetType()
                           .GetProperty("ItemsCountForDebugger", BindingFlags.Instance | BindingFlags.NonPublic);
                if (prop != null)
                {
                    count = (int)prop.GetValue(_sendChannel);
                    return(true);
                }
            }
            catch (Exception e)
            {
                ErrorPolicy.HandleUnexpected(e, Logger);
            }

            count = default(int);
            return(false);
        }