public async Task AllowInterceptionOfDeliveryOnSend() { bool responsesSent = false; void ValidateResponses(Activity[] activities) { responsesSent = true; Assert.Fail("Should not be called. Interceptor did not work"); } SimpleAdapter a = new SimpleAdapter(ValidateResponses); TurnContext c = new TurnContext(a, new Activity()); int count = 0; c.OnSendActivities(async(context, activities, next) => { Assert.IsNotNull(activities, "Null Array passed in"); count = activities.Count(); // Do not call next. return(null); }); await c.SendActivity(TestMessage.Message()); Assert.IsTrue(count == 1); Assert.IsFalse(responsesSent, "Responses made it to the adapter."); }
public async Task InterceptAndMutateOnSend() { bool foundIt = false; void ValidateResponses(Activity[] activities) { Assert.IsNotNull(activities); Assert.IsTrue(activities.Length == 1); Assert.IsTrue(activities[0].Id == "changed"); foundIt = true; } SimpleAdapter a = new SimpleAdapter(ValidateResponses); TurnContext c = new TurnContext(a, new Activity()); c.OnSendActivities(async(context, activities, next) => { Assert.IsNotNull(activities, "Null Array passed in"); Assert.IsTrue(activities.Count() == 1); Assert.IsTrue(activities[0].Id == "1234", "Unknown Id Passed In"); activities[0].Id = "changed"; return(await next()); }); await c.SendActivity(TestMessage.Message()); // Intercepted the message, changed it, and sent it on to the Adapter Assert.IsTrue(foundIt); }
public async Task SendActivity() { // Arrange var activity = new Activity(); // Act await _target.SendActivity(activity); // Assert A.CallTo(() => _adapter.SendActivity(activity)).MustHaveHappened(); }
public async Task TraceActivitiesDoNoSetResponded() { SimpleAdapter a = new SimpleAdapter(); TurnContext c = new TurnContext(a, new Activity()); Assert.IsFalse(c.Responded); // Send a Trace Activity, and make sure responded is NOT set. ITraceActivity trace = Activity.CreateTraceActivity("trace"); await c.SendActivity(trace); Assert.IsFalse(c.Responded); // Just to sanity check everything, send a Message and verify the // responded flag IS set. IMessageActivity msg = TestMessage.Message().AsMessageActivity(); await c.SendActivity(msg); Assert.IsTrue(c.Responded); }
public async Task SendAndSetResponded() { SimpleAdapter a = new SimpleAdapter(); TurnContext c = new TurnContext(a, new Activity()); Assert.IsFalse(c.Responded); var response = await c.SendActivity(TestMessage.Message("testtest")); Assert.IsTrue(c.Responded); Assert.IsTrue(response.Id == "testtest"); }
public async Task SendAndSetRespondedUsingIMessageActivity() { SimpleAdapter a = new SimpleAdapter(); TurnContext c = new TurnContext(a, new Activity()); Assert.IsFalse(c.Responded); IMessageActivity msg = TestMessage.Message().AsMessageActivity(); await c.SendActivity(msg); Assert.IsTrue(c.Responded); }
public async Task SendOneActivityToAdapter() { bool foundActivity = false; void ValidateResponses(Activity[] activities) { Assert.IsTrue(activities.Count() == 1, "Incorrect Count"); Assert.IsTrue(activities[0].Id == "1234"); foundActivity = true; } SimpleAdapter a = new SimpleAdapter(ValidateResponses); TurnContext c = new TurnContext(a, new Activity()); await c.SendActivity(TestMessage.Message()); Assert.IsTrue(foundActivity); }
public async Task CallOnSendBeforeDelivery() { SimpleAdapter a = new SimpleAdapter(); TurnContext c = new TurnContext(a, new Activity()); int count = 0; c.OnSendActivities(async(context, activities, next) => { Assert.IsNotNull(activities, "Null Array passed in"); count = activities.Count(); return(await next()); }); await c.SendActivity(TestMessage.Message()); Assert.IsTrue(count == 1); }
public async Task PassResourceResponsesThrough() { void ValidateResponses(Activity[] activities) { // no need to do anything. } SimpleAdapter a = new SimpleAdapter(ValidateResponses); TurnContext c = new TurnContext(a, new Activity()); string activityId = Guid.NewGuid().ToString(); var activity = TestMessage.Message(); activity.Id = activityId; var resourceResponse = await c.SendActivity(activity); Assert.IsTrue(resourceResponse.Id == activityId, "Incorrect response Id returned"); }
public async Task ThrowExceptionInOnSend() { SimpleAdapter a = new SimpleAdapter(); TurnContext c = new TurnContext(a, new Activity()); c.OnSendActivities(async(context, activities, next) => { throw new Exception("test"); }); try { await c.SendActivity(TestMessage.Message()); Assert.Fail("Should not get here"); } catch (Exception ex) { Assert.IsTrue(ex.Message == "test"); } }