public async Task InterceptOnDelete() { bool adapterCalled = false; void ValidateDelete(ConversationReference r) { adapterCalled = true; Assert.True(false); // Should not be called } var a = new SimpleAdapter(ValidateDelete); var c = new TurnContext(a, new Activity()); bool wasCalled = false; c.OnDeleteActivity((context, convRef, next) => { Assert.NotNull(convRef); // Null activity passed in wasCalled = true; // Do Not Call Next return(Task.FromResult <ResourceResponse[]>(null)); }); await c.DeleteActivityAsync("1234"); Assert.True(wasCalled); // Interceptor was called Assert.False(adapterCalled); // Adapter was not }
public async Task InterceptAndMutateOnDelete() { bool adapterCalled = false; void ValidateDelete(ConversationReference r) { Assert.True(r.ActivityId == "mutated"); adapterCalled = true; } var a = new SimpleAdapter(ValidateDelete); var c = new TurnContext(a, new Activity()); c.OnDeleteActivity(async(context, convRef, next) => { Assert.NotNull(convRef); // Null activity passed in Assert.True(convRef.ActivityId == "1234", "Incorrect Activity Id"); convRef.ActivityId = "mutated"; await next(); }); await c.DeleteActivityAsync("1234"); Assert.True(adapterCalled); // Adapter was called + valided the change }
public async Task DeleteOneActivityToAdapter() { bool deleteCalled = false; void ValidateDelete(ConversationReference r) { Assert.NotNull(r); Assert.True(r.ActivityId == "12345"); deleteCalled = true; } var a = new SimpleAdapter(ValidateDelete); var c = new TurnContext(a, TestMessage.Message()); await c.DeleteActivityAsync("12345"); Assert.True(deleteCalled); }