コード例 #1
0
        internal static void AssertValid(this CapturedException thisObj)
        {
            thisObj.Should().NotBeNull();

            thisObj.Code?.AssertValid();
            thisObj.StackTrace?.AssertValid();

            if (string.IsNullOrEmpty(thisObj.Type))
            {
                thisObj.Message.AssertValid();
            }
            else
            {
                thisObj.Message?.AssertValid();
            }

            if (string.IsNullOrEmpty(thisObj.Message))
            {
                thisObj.Type.AssertValid();
            }
            else
            {
                thisObj.Type?.AssertValid();
            }
        }
コード例 #2
0
        public void CreateExceptionCopiesAllProperties()
        {
            CapturedException exception = CommonTestHelpers.Factory.CreateCapturedException();
            var result = PayloadFactory.Create(exception);

            TestCapturedException(exception, result);
        }
コード例 #3
0
        public void ExceptionMessage()
        {
            string            exceptionMessage = $"Exception {Guid.NewGuid()}";
            CapturedException item             = new CapturedException(new Exception(exceptionMessage));

            Assert.AreEqual(exceptionMessage, item.Message);
        }
コード例 #4
0
        public async Task LogsTheException()
        {
            KissLog.Tests.Common.CommonTestHelpers.ResetContext();

            var ex = new Exception($"Exception {Guid.NewGuid()}");

            FlushLogArgs flushLogArgs = null;

            KissLogConfiguration.Listeners.Add(new KissLog.Tests.Common.CustomLogListener(onFlush: (FlushLogArgs arg) =>
            {
                flushLogArgs = arg;
            }));

            var context = Helpers.MockHttpContext();

            var middleware = new KissLogMiddleware((innerHttpContext) =>
            {
                throw ex;
            });

            try
            {
                await middleware.Invoke(context.Object);
            }
            catch
            {
                // ignored
            }

            CapturedException capturedException = flushLogArgs.Exceptions.First();
            LogMessage        message           = flushLogArgs.MessagesGroups.First().Messages.First();

            Assert.AreEqual(ex.Message, capturedException.Message);
            Assert.IsTrue(message.Message.Contains(ex.Message));
        }
コード例 #5
0
        public void ExceptionString()
        {
            var ex = new NotImplementedException($"This method is not implemented {Guid.NewGuid()}");

            CapturedException item = new CapturedException(ex);

            Assert.AreEqual(ex.ToString(), item.ExceptionString);
        }
コード例 #6
0
        internal static void AssertValid(this CapturedException thisObj)
        {
            thisObj.Should().NotBeNull();

            thisObj.Code?.AssertValid();
            thisObj.Stacktrace?.AssertValid();
            thisObj.Type.AssertValid();
        }
コード例 #7
0
        public ExceptionCasesFacts()
        {
            this.testee = new StateMachine <StateMachine.States, StateMachine.Events>();

            this.testee.TransitionExceptionThrown += (sender, eventArgs) =>
            {
                this.capturedException = new CapturedException(
                    eventArgs.StateId,
                    eventArgs.EventId,
                    eventArgs.EventArgument,
                    eventArgs.Exception);
            };
        }
コード例 #8
0
        public async Task CapturesException_WhenEntryActionThrowsAnException()
        {
            var eventArguments = new object[] { 1, 2, "test" };
            var exception      = new Exception();

            var stateDefinitionsBuilder = new StateDefinitionsBuilder <States, Events>();

            stateDefinitionsBuilder
            .In(States.A)
            .On(Events.B).Goto(States.B);
            stateDefinitionsBuilder
            .In(States.B)
            .ExecuteOnEntry(() => throw exception);
            var stateDefinitions = stateDefinitionsBuilder.Build();

            var stateContainer = new StateContainer <States, Events>();
            var testee         = new StateMachineBuilder <States, Events>()
                                 .WithStateContainer(stateContainer)
                                 .Build();

            CapturedException capturedException = null;

            testee.TransitionExceptionThrown += (sender, eventArgs) =>
            {
                capturedException = new CapturedException(
                    eventArgs.StateId,
                    eventArgs.EventId,
                    eventArgs.EventArgument,
                    eventArgs.Exception);
            };

            await testee.EnterInitialState(stateContainer, stateDefinitions, States.A)
            .ConfigureAwait(false);

            await testee.Fire(Events.B, eventArguments, stateContainer, stateDefinitions)
            .ConfigureAwait(false);

            capturedException
            .Should()
            .Be(new CapturedException(States.A, Events.B, eventArguments, exception));
        }
コード例 #9
0
 private bool Equals(CapturedException other)
 {
     return(this.RecordedStateId == other.RecordedStateId && this.RecordedEventId == other.RecordedEventId && Equals(this.RecordedEventArgument, other.RecordedEventArgument) && Equals(this.RecordedException, other.RecordedException));
 }
コード例 #10
0
        public void ExceptionType()
        {
            CapturedException item = new CapturedException(new FileNotFoundException());

            Assert.AreEqual(typeof(FileNotFoundException).FullName, item.Type);
        }
コード例 #11
0
 public void NullExceptionThrowsException()
 {
     CapturedException item = new CapturedException(null);
 }
コード例 #12
0
 private void TestCapturedException(CapturedException exception, KissLog.RestClient.Requests.CreateRequestLog.CapturedException result)
 {
     Assert.AreEqual(exception.Type, result.ExceptionType);
     Assert.AreEqual(exception.Message, result.ExceptionMessage);
 }
コード例 #13
0
 public void CreateExceptionThrowsExceptionForNullArgument()
 {
     CapturedException exception = null;
     var result = PayloadFactory.Create(exception);
 }
コード例 #14
0
        internal static KissLog.RestClient.Requests.CreateRequestLog.CapturedException Create(CapturedException exception)
        {
            if (exception == null)
            {
                throw new ArgumentNullException(nameof(exception));
            }

            return(new KissLog.RestClient.Requests.CreateRequestLog.CapturedException
            {
                ExceptionType = exception.Type,
                ExceptionMessage = exception.Message
            });
        }