public async Task InterceptOnDelete() { bool adapterCalled = false; void ValidateDelete(ConversationReference r) { adapterCalled = true; Assert.Fail("Should not be called."); } SimpleAdapter a = new SimpleAdapter(ValidateDelete); TurnContext c = new TurnContext(a, new Activity()); bool wasCalled = false; c.OnDeleteActivity(async(context, convRef, next) => { Assert.IsNotNull(convRef, "Null activity passed in"); wasCalled = true; // Do Not Call Next }); await c.DeleteActivity("1234"); Assert.IsTrue(wasCalled); // Interceptor was called Assert.IsFalse(adapterCalled); // Adapter was not }
public async Task InterceptAndMutateOnDelete() { bool adapterCalled = false; void ValidateDelete(ConversationReference r) { Assert.IsTrue(r.ActivityId == "mutated"); adapterCalled = true; } SimpleAdapter a = new SimpleAdapter(ValidateDelete); TurnContext c = new TurnContext(a, new Activity()); c.OnDeleteActivity(async(context, convRef, next) => { Assert.IsNotNull(convRef, "Null activity passed in"); Assert.IsTrue(convRef.ActivityId == "1234", "Incorrect Activity Id"); convRef.ActivityId = "mutated"; await next(); }); await c.DeleteActivity("1234"); Assert.IsTrue(adapterCalled); // Adapter was called + valided the change }
public async Task DeleteOneActivityToAdapter() { bool deleteCalled = false; void ValidateDelete(ConversationReference r) { Assert.IsNotNull(r); Assert.IsTrue(r.ActivityId == "12345"); deleteCalled = true; } SimpleAdapter a = new SimpleAdapter(ValidateDelete); TurnContext c = new TurnContext(a, TestMessage.Message()); await c.DeleteActivity("12345"); Assert.IsTrue(deleteCalled); }