public async Task <EventResult> ProcessEvent(Event evnt) { await this.logger.LogVerboseAsync($"Starting to process check event: {evnt.Id} - {evnt?.SourceType}"); LoopEventResult result; var stopwatch = new Stopwatch(); try { stopwatch.Start(); result = await this.eventRouter.RouteEvent(evnt) as LoopEventResult; stopwatch.Stop(); } catch (Exception ex) { stopwatch.Stop(); result = new LoopEventResult(false) { Succeeded = false }; this.logger.LogError($"Event run failed: {evnt.Id} - Type: {evnt.SourceType}", ex); } // Mark Error or Completed result.ExecutionTime = (int)stopwatch.Elapsed.TotalMilliseconds; return(result); }
public async Task CheckEventTask_CreateNextEvents(bool shouldContinue, bool succeeded, int?previousEventSourceId, EventSourceType previousEventSourceType, EventSourceType expectedNextSourceType) { // Arrange var eventResult = new LoopEventResult(shouldContinue) { Succeeded = succeeded }; var previousEventId = 22; var previousEvent = new Event { SourceType = previousEventSourceType, SourceId = previousEventSourceId, Id = previousEventId }; this.eventSourceServiceMock.Setup( m => m.CreateNextEvents(eventResult.SourceIds, eventResult.Types, It.IsAny <int>(), previousEvent.Id, previousEvent.HourId)) .Returns(Task.Delay(5)); // Act await this.checkEventTask.CreateNextEvents(eventResult, previousEvent); // Assert // Grab next types var nextTypes = shouldContinue ? new[] { expectedNextSourceType } : new[] { previousEventSourceType }; // Returned from Static helper, or previous var nextSourceIds = previousEventSourceId.HasValue ? new int[] { previousEventSourceId.Value } : null; var shouldCreateNextEvents = succeeded ? Times.Once() : Times.Never(); this.eventSourceServiceMock.Verify(m => m.CreateNextEvents(nextSourceIds, nextTypes, It.IsAny <int>(), previousEvent.Id, previousEvent.HourId), shouldCreateNextEvents); }
public async Task CheckEventTask_ProcessEvent(bool shouldContinue, EventStatus expectedStatus) { // Arrange -- eventTaskFactory Route Event - returns result, update event with status, return result var evnt = new Event { Id = 123, SourceType = EventSourceType.CheckAllPrerequisitesComplete }; var eventResult = new LoopEventResult(shouldContinue); this.eventRouter.Setup(f => f.RouteEvent(evnt)).ReturnsAsync(eventResult); var updatedEvnt = new Event { Id = evnt.Id, Status = expectedStatus }; // Act var result = await this.checkEventTask.ProcessEvent(evnt); // Assert Assert.That(result.Succeeded, Is.True); // Success should always be true unless the event errors }
public async Task CheckEventTask_CreateNextEvents_Unsuccessful(bool succeeded, bool expectedResult) { // Arrange var eventResult = new LoopEventResult(true) { Succeeded = succeeded }; var previousEvent = new Event { SourceType = EventSourceType.DeployServerDatabases, SourceId = 3, Id = 22 }; this.eventSourceServiceMock.Setup( m => m.CreateNextEvents(eventResult.SourceIds, eventResult.Types, It.IsAny <int>(), previousEvent.Id, previousEvent.HourId)) .Returns(Task.Delay(5)); // Act await this.checkEventTask.CreateNextEvents(eventResult, previousEvent); // Assert // Grab next types var shouldCreateNextEvents = expectedResult ? Times.Once() : Times.Never(); this.eventSourceServiceMock.Verify(m => m.CreateNextEvents(It.IsAny <IList <int> >(), It.IsAny <IList <EventSourceType> >(), It.IsAny <int>(), previousEvent.Id, previousEvent.HourId), shouldCreateNextEvents); }