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);
        }
Пример #2
0
 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();
 }
Пример #3
0
 internal void TestParseMessage(WebexTeamsMessage input, GlobalXMessage output)
 {
     this.Given(x => GivenAWebexTeamsMessage(input))
     .When(x => WhenParsingAMessage())
     .Then(x => ThenItShouldReturnAGlobalXMessage(output))
     .And(x => ThenItShouldNotThrowAnException())
     .BDDfy();
 }
Пример #4
0
 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);
 }
Пример #5
0
 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();
 }
Пример #6
0
 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();
 }
Пример #7
0
 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();
 }
Пример #8
0
 private void GivenAWebexTeamsMessage(WebexTeamsMessage message)
 {
     _webexTeamsMessage = message;
 }
Пример #9
0
 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));
 }
Пример #10
0
 private void GivenApiServiceReturnsCorrectResult(WebexTeamsMessage apiResponse)
 {
     _apiService.SendMessageAsync(Arg.Is <CreateMessageRequest>(x => x.ParentId == "goodParentId"))
     .Returns(apiResponse);
 }