private async Task DeleteActivityInternal(ConversationReference cr, IEnumerable <DeleteActivityHandler> updateHandlers, Func <Task> callAtBottom) { BotAssert.ConversationReferenceNotNull(cr); if (updateHandlers == null) { throw new ArgumentException(nameof(updateHandlers)); } if (updateHandlers.Count() == 0) // No middleware to run. { if (callAtBottom != null) { await callAtBottom(); } return; } // Default to "No more Middleware after this". async Task next() { // Remove the first item from the list of middleware to call, // so that the next call just has the remaining items to worry about. IEnumerable <DeleteActivityHandler> remaining = updateHandlers.Skip(1); await DeleteActivityInternal(cr, remaining, callAtBottom).ConfigureAwait(false); } // Grab the current middleware, which is the 1st element in the array, and execute it. DeleteActivityHandler toCall = updateHandlers.First(); await toCall(this, cr, next); }
/// <summary> /// Adds a response handler for delete activity operations. /// </summary> /// <param name="handler">The handler to add to the context object.</param> /// <returns>The updated context object.</returns> /// <exception cref="ArgumentNullException"><paramref name="handler"/> is <c>null</c>.</exception> /// <remarks>When the context's <see cref="DeleteActivityAsync(ConversationReference, CancellationToken)"/> /// or <see cref="DeleteActivityAsync(string, CancellationToken)"/> is called, /// the adapter calls the registered handlers in the order in which they were /// added to the context object. /// </remarks> public ITurnContext OnDeleteActivity(DeleteActivityHandler handler) { if (handler == null) { throw new ArgumentNullException(nameof(handler)); } _onDeleteActivity.Add(handler); return(this); }
public async void ReturnNull_InvalidId() { _unitOfWork.Setup(mock => mock.ActivityRepository.DeleteActivityResearcher(It.IsAny <int>())) .Returns(false); var command = new DeleteActivityCommand(1); var handler = new DeleteActivityHandler(_unitOfWork.Object); var returnValue = await handler.Handle(command, new CancellationToken()); Assert.False((bool)returnValue); }
public async void ReturnFalse_IfExceptionOccurs() { var exc = new Exception(); _unitOfWork.Setup(mock => mock.ActivityRepository.ReadAllActivityForResearcher(It.IsAny <int>())) .Throws(exc); var command = new DeleteActivityCommand(10); var handler = new DeleteActivityHandler(_unitOfWork.Object); var returnValue = await handler.Handle(command, new CancellationToken()); Assert.False((bool)returnValue); }
public ITurnContext OnDeleteActivity(DeleteActivityHandler handler) { return(_adapter.OnDeleteActivity(handler)); }
public ITurnContext OnDeleteActivity(DeleteActivityHandler handler) => _innerTurnContext.OnDeleteActivity(handler);
public ITurnContext OnDeleteActivity(DeleteActivityHandler handler) { throw new NotImplementedException(); }
public ITurnContext OnDeleteActivity(DeleteActivityHandler handler) { return(_innerTurnContext.OnDeleteActivity(handler)); }