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(); } }
public void CreateExceptionCopiesAllProperties() { CapturedException exception = CommonTestHelpers.Factory.CreateCapturedException(); var result = PayloadFactory.Create(exception); TestCapturedException(exception, result); }
public void ExceptionMessage() { string exceptionMessage = $"Exception {Guid.NewGuid()}"; CapturedException item = new CapturedException(new Exception(exceptionMessage)); Assert.AreEqual(exceptionMessage, item.Message); }
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)); }
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); }
internal static void AssertValid(this CapturedException thisObj) { thisObj.Should().NotBeNull(); thisObj.Code?.AssertValid(); thisObj.Stacktrace?.AssertValid(); thisObj.Type.AssertValid(); }
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); }; }
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)); }
private bool Equals(CapturedException other) { return(this.RecordedStateId == other.RecordedStateId && this.RecordedEventId == other.RecordedEventId && Equals(this.RecordedEventArgument, other.RecordedEventArgument) && Equals(this.RecordedException, other.RecordedException)); }
public void ExceptionType() { CapturedException item = new CapturedException(new FileNotFoundException()); Assert.AreEqual(typeof(FileNotFoundException).FullName, item.Type); }
public void NullExceptionThrowsException() { CapturedException item = new CapturedException(null); }
private void TestCapturedException(CapturedException exception, KissLog.RestClient.Requests.CreateRequestLog.CapturedException result) { Assert.AreEqual(exception.Type, result.ExceptionType); Assert.AreEqual(exception.Message, result.ExceptionMessage); }
public void CreateExceptionThrowsExceptionForNullArgument() { CapturedException exception = null; var result = PayloadFactory.Create(exception); }
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 }); }