public async Task CheckFlow() { var operationId = Guid.NewGuid().ToString(); var messageCancellationService = new MessageCancellationService(); var firstCheck = await messageCancellationService.CheckIfOperationRequiresCancellationAsync(operationId); var firstCheckEnumerable = await messageCancellationService.GetAllMessagesToCancellAsync(); await messageCancellationService.RequestMessageCancellationAsync(operationId); var secondCheck = await messageCancellationService.CheckIfOperationRequiresCancellationAsync(operationId); var secondCheckEnumerable = await messageCancellationService.GetAllMessagesToCancellAsync(); await messageCancellationService.RemoveMessageFromCancellationAsync(operationId); var thirdCheck = await messageCancellationService.CheckIfOperationRequiresCancellationAsync(operationId); var thirdCheckEnumerable = await messageCancellationService.GetAllMessagesToCancellAsync(); Assert.False(firstCheck); Assert.True(secondCheck); Assert.False(thirdCheck); Assert.True(firstCheckEnumerable.Count() == 0); Assert.True(secondCheckEnumerable.Count() == 1); Assert.True(secondCheckEnumerable.FirstOrDefault() == operationId); Assert.True(thirdCheckEnumerable.Count() == 0); }
private static MessageWithSomeId PrepareServicesForInterception(out string operationId, out MessageCancellationService messageCancellationService, out MessageCancellationRegistry messageCancellationRegistry, out Mock <ILogFactory> logFactory) { operationId = Guid.NewGuid().ToString(); var message = new MessageWithSomeId() { MessageId = operationId }; messageCancellationService = new MessageCancellationService(); messageCancellationRegistry = new MessageCancellationRegistry(); messageCancellationRegistry.RegisterTypeWithMessageId <MessageWithSomeId>(x => x.MessageId.ToString()); messageCancellationService.RequestMessageCancellationAsync(operationId).Wait(); logFactory = new Mock <ILogFactory>(); logFactory.Setup(x => x.CreateLog(It.IsAny <object>())).Returns(new Mock <ILog>().Object); return(message); }