public GlobalXMessage ParseMessage(WebexTeamsMessage message) { var mappedMessage = _mapper.Map <GlobalXMessage>(message); if (mappedMessage.RoomType == RoomType.Direct) { mappedMessage.MessageParts = new[] { new MessagePart { MessageType = MessageType.Text, Text = message.Text } }; } else { var xmlDocument = TryParseXml(message.Html); var parts = new List <MessagePart>(); foreach (XmlNode node in xmlDocument.DocumentElement.ChildNodes) { parts.AddRange(ParseMessagePart(node)); } mappedMessage.MessageParts = parts.ToArray(); } return(mappedMessage); }
internal void TestUnsuccessfulParseMessage(WebexTeamsMessage input, Type exceptionType, string message) { this.Given(x => GivenAWebexTeamsMessage(input)) .When(x => WhenParsingAMessage()) .Then(x => ThenItShouldThrowAnExceptionOfType(exceptionType)) .And(x => ThenTheExceptionMessageShouldContain(message)) .BDDfy(); }
internal void TestParseMessage(WebexTeamsMessage input, GlobalXMessage output) { this.Given(x => GivenAWebexTeamsMessage(input)) .When(x => WhenParsingAMessage()) .Then(x => ThenItShouldReturnAGlobalXMessage(output)) .And(x => ThenItShouldNotThrowAnException()) .BDDfy(); }
private async void WhenProcessingAWebhookCallback(string messageId, WebexTeamsMessage apiResponse, GlobalXMessage parsedMessage, WebexTeamsPerson sender) { _apiService.GetMessageAsync(messageId).Returns(Task.FromResult(apiResponse)); _messageParser .ParseMessage(Arg.Is <WebexTeamsMessage>(x => x.Id == apiResponse.Id && x.Html == apiResponse.Html)) .Returns(parsedMessage); _apiService.GetPersonAsync(apiResponse.PersonId).Returns(Task.FromResult(sender)); _result = await _subject.ProcessMessageWebhookCallbackAsync(_callbackBody); }
internal void TestSendMessage(GlobalXMessage input, CreateMessageRequest parsedInput, WebexTeamsMessage apiResponse, GlobalXMessage parsedApiResponse, Person sender, GlobalXMessage output) { this.Given(x => GivenAGlobalXMessage(input)) .And(x => GivenServicesReturnExpectedValues(parsedInput, apiResponse, parsedApiResponse, sender)) .When(x => WhenSendingAMessage()) .Then(x => ThenItShouldCallApiService()) .And(x => ThenItShouldReturnAMessage(output)) .BDDfy(); }
internal void TestSendBadParentMessage(GlobalXMessage input, WebexTeamsMessage apiResponse) { this.Given(x => GivenAGlobalXMessage(input)) .And(x => GivenApiServiceThrowsInvalidParentExceptionForBadParent()) .And(x => GivenMessageParserReturnsCreateMessageRequest()) .And(x => GivenApiServiceReturnsGoodParent()) .And(x => GivenApiServiceReturnsCorrectResult(apiResponse)) .And(x => GivenServicesReturnSomeValues()) .When(x => WhenSendingAMessage()) .Then(x => ThenThereShouldBeTwoCallsToSendMessage()) .BDDfy(); }
internal void TestProcessMessageWebhookCallback(string body, string messageId, WebexTeamsMessage apiResponse, WebexTeamsPerson sender, GlobalXMessage output) { this.Given(x => GivenACallbackBody(body)) .When(x => WhenProcessingAWebhookCallback(messageId, apiResponse, output, sender)) .Then(x => ThenItShouldReturnTheGlobalXMessage(output)) .BDDfy(); }
private void GivenAWebexTeamsMessage(WebexTeamsMessage message) { _webexTeamsMessage = message; }
private void GivenServicesReturnExpectedValues(CreateMessageRequest parsedInput, WebexTeamsMessage apiResponse, GlobalXMessage parsedApiResponse, Person sender) { _messageParser.ParseCreateMessageRequest(_input).Returns(parsedInput); _apiService.SendMessageAsync(parsedInput).Returns(Task.FromResult(apiResponse)); _messageParser.ParseMessage(apiResponse).Returns(parsedApiResponse); _apiService.GetPersonAsync(apiResponse.PersonId).Returns(Task.FromResult(sender)); }
private void GivenApiServiceReturnsCorrectResult(WebexTeamsMessage apiResponse) { _apiService.SendMessageAsync(Arg.Is <CreateMessageRequest>(x => x.ParentId == "goodParentId")) .Returns(apiResponse); }