public async Task ProccesRequest_HelpedAction_ShouldCallExecutorServiceWithAppropriateArgs() { // Arrange var action = new AttachmentActionDto("actionName", "some text"); var request = new InteractiveMessage { Actions = new List <AttachmentActionDto> { action } }; var paramsType = typeof(HelpedSlackActionParams); var actionParams = new HelpedSlackActionParams(); _slackParamsSelectServiceMock.Setup(m => m.Choose(It.IsAny <string>())) .Returns(paramsType); _mapperMock.Setup(m => m.Map(It.IsAny <object>(), It.IsAny <Type>(), It.IsAny <Type>())) .Returns(actionParams); _slackExecutorServiceMock.Setup(m => m.ExecuteAction(It.IsAny <Type>(), It.IsAny <object[]>())) .Returns(Task.CompletedTask); // Act await _service.ProcessRequest(request); // Assert _slackParamsSelectServiceMock.Verify(m => m.Choose(It.Is <string>(n => n == action.Name)), Times.Once); _slackParamsSelectServiceMock.VerifyNoOtherCalls(); _mapperMock.Verify(m => m.Map(It.Is <object>(r => r == request), It.Is <Type>(t => t == request.GetType()), It.Is <Type>(t => t == actionParams.GetType()))); _mapperMock.VerifyNoOtherCalls(); _slackExecutorServiceMock.Verify(m => m.ExecuteAction(It.Is <Type>(t => t == paramsType), It.IsAny <object[]>()), Times.Once); _slackExecutorServiceMock.VerifyNoOtherCalls(); }
public void Map__InteractiveMessage_To_MoreSlackActionParams__AllNecessaryFieldsAreMapped() { // Arrange const string questionId = "questionId"; const string answerId = "answerId"; var firstAction = new AttachmentActionDto("name", "text") { Value = JsonConvert.SerializeObject(new ShowMoreAnswersActionButtonParams { QuestionId = questionId, AnswerId = answerId }) }; var originalMessage = new OriginalMessageDto { Text = "attachmentText", TimeStamp = "1212132421", Attachments = new List <AttachmentDto>() }; var source = new InteractiveMessage { Actions = new List <AttachmentActionDto> { firstAction }, User = new ItemInfo { Id = "id", Name = "userName" }, Channel = new ItemInfo { Id = "channelId", Name = "channelName" }, OriginalMessage = originalMessage }; // Act var destination = _mapper.Map <InteractiveMessage, ShowMoreAnswersSlackActionParams>(source); // Assert Assert.Equal(source.User.Name, destination.User.Name); Assert.Equal(source.User.Id, destination.User.Id); Assert.Equal(source.Channel.Name, destination.Channel.Name); Assert.Equal(source.Channel.Id, destination.Channel.Id); Assert.Equal(questionId, destination.ButtonParams.QuestionId); Assert.Equal(answerId, destination.ButtonParams.AnswerId); Assert.Equal(source.OriginalMessage.Text, destination.OriginalMessage.Text); Assert.Equal(source.OriginalMessage.TimeStamp, destination.OriginalMessage.TimeStamp); Assert.Equal(source.OriginalMessage.Attachments, destination.OriginalMessage.Attachments); }
public void Map__InteractiveMessage_To_AskExpertsSlackActionParams__AllNecessaryFieldsAreMapped() { // Arrange var firstAction = new AttachmentActionDto("name", "text") { Value = "value" }; var originalMessage = new OriginalMessageDto { Text = "attachmentText", TimeStamp = "1212132421", Attachments = new List <AttachmentDto>() }; var source = new InteractiveMessage { Actions = new List <AttachmentActionDto> { firstAction }, User = new ItemInfo { Id = "id", Name = "userName" }, Channel = new ItemInfo { Id = "channelId", Name = "channelName" }, AttachmentId = 1, OriginalMessage = originalMessage }; // Act var destination = _mapper.Map <InteractiveMessage, AskExpertsSlackActionParams>(source); // Assert Assert.Equal(source.User.Name, destination.User.Name); Assert.Equal(source.User.Id, destination.User.Id); Assert.Equal(source.Channel.Name, destination.Channel.Name); Assert.Equal(source.Channel.Id, destination.Channel.Id); Assert.Equal(source.AttachmentId - 1, destination.AttachmentId); Assert.Equal(firstAction.Value, destination.ButtonParams.QuestionText); Assert.Equal(source.OriginalMessage.Text, destination.OriginalMessage.Text); Assert.Equal(source.OriginalMessage.TimeStamp, destination.OriginalMessage.TimeStamp); Assert.Equal(source.OriginalMessage.Attachments, destination.OriginalMessage.Attachments); }
public void Map__InteractiveMessage_To_AddAnswerSlackActionParams__AllNecessaryFieldsAreMapped() { // Arrange const string buttonValue = "value"; var firstAction = new AttachmentActionDto("name", "text") { Value = JsonConvert.SerializeObject(new AddAnswerActionButtonParams { QuestionId = buttonValue }) }; var originalMessage = new OriginalMessageDto { Text = "attachmentText", TimeStamp = "1212132421", Attachments = new List <AttachmentDto>() }; var source = new InteractiveMessage { TriggerId = "trigger", Actions = new List <AttachmentActionDto> { firstAction }, User = new ItemInfo { Id = "id", Name = "userName" }, OriginalMessage = originalMessage }; // Act var destination = _mapper.Map <InteractiveMessage, AddAnswerSlackActionParams>(source); // Assert Assert.Equal(source.TriggerId, destination.TriggerId); Assert.Equal(source.User.Name, destination.User.Name); Assert.Equal(source.User.Id, destination.User.Id); Assert.Equal(buttonValue, destination.ButtonParams.QuestionId); Assert.Equal(source.OriginalMessage.Text, destination.OriginalMessage.Text); Assert.Equal(source.OriginalMessage.TimeStamp, destination.OriginalMessage.TimeStamp); Assert.Equal(source.OriginalMessage.Attachments, destination.OriginalMessage.Attachments); }