public async Task Should_send_available_message_to_participants_and_service_bus_when_participant_joins()
        {
            MemoryCache.Remove(TestConference.Id);
            var confDetail = CreateConferenceDetailsResponse();

            VideoApiClientMock.Setup(x => x.GetConferenceDetailsByIdAsync(TestConference.Id)).ReturnsAsync(confDetail);

            _eventHandler = new JoinedEventHandler(EventHubContextMock.Object, ConferenceCache, LoggerMock.Object,
                                                   VideoApiClientMock.Object);

            var conference          = TestConference;
            var participantForEvent = conference.Participants.First(x => x.Role == Role.Individual);
            var participantCount    = conference.Participants.Count + 1; // plus one for admin

            var callbackEvent = new CallbackEvent
            {
                EventType     = EventType.Joined,
                EventId       = Guid.NewGuid().ToString(),
                ConferenceId  = conference.Id,
                ParticipantId = participantForEvent.Id,
                TimeStampUtc  = DateTime.UtcNow
            };

            await _eventHandler.HandleAsync(callbackEvent);

            EventHubClientMock.Verify(
                x => x.ParticipantStatusMessage(_eventHandler.SourceParticipant.Id, _eventHandler.SourceParticipant.Username, conference.Id,
                                                ParticipantState.Available), Times.Exactly(participantCount));

            VideoApiClientMock.Verify(x => x.GetConferenceDetailsByIdAsync(TestConference.Id), Times.Once);
        }
        public async Task Should_map_originators_when_message_is_not_from_user()
        {
            var conferenceId  = Guid.NewGuid();
            var loggedInUser  = "******";
            var otherUsername = "******";
            var messages      = Builder <InstantMessageResponse> .CreateListOfSize(5)
                                .TheFirst(2)
                                .With(x => x.From = loggedInUser).TheNext(3)
                                .With(x => x.From = otherUsername)
                                .Build().ToList();

            VideoApiClientMock.Setup(x => x.GetInstantMessageHistoryForParticipantAsync(conferenceId, loggedInUser))
            .ReturnsAsync(messages);

            var result = await Controller.GetConferenceInstantMessageHistoryForParticipantAsync(conferenceId, loggedInUser);

            MessageDecoder.Verify(x => x.IsMessageFromUser(
                                      It.Is <InstantMessageResponse>(m => m.From == loggedInUser), loggedInUser),
                                  Times.Exactly(2));

            MessageDecoder.Verify(x => x.IsMessageFromUser(
                                      It.Is <InstantMessageResponse>(m => m.From == otherUsername), loggedInUser),
                                  Times.Exactly(3));

            var typedResult = (OkObjectResult)result;

            typedResult.Should().NotBeNull();
            var responseModel = typedResult.Value as List <ChatResponse>;

            responseModel?.Count(x => x.FromDisplayName == "You").Should().Be(2);
        }
        public async Task Should_return_okay_code_when_chat_history_is_empty()
        {
            var conferenceId        = Guid.NewGuid();
            var participantUsername = "******";
            var messages            = new List <InstantMessageResponse>();

            VideoApiClientMock.Setup(x => x.GetInstantMessageHistoryForParticipantAsync(conferenceId, participantUsername))
            .ReturnsAsync(messages);

            var result = await Controller.GetConferenceInstantMessageHistoryForParticipantAsync(conferenceId, participantUsername);

            var typedResult = (OkObjectResult)result;

            typedResult.Should().NotBeNull();
            var responseModel = typedResult.Value as List <ChatResponse>;

            responseModel.Should().BeEmpty();
        }
        public async Task Should_return_okay_code_when_chat_history_is_found()
        {
            var conferenceId        = Guid.NewGuid();
            var participantUsername = "******";
            var messages            = Builder <InstantMessageResponse> .CreateListOfSize(5).Build().ToList();

            VideoApiClientMock.Setup(x => x.GetInstantMessageHistoryForParticipantAsync(conferenceId, participantUsername))
            .ReturnsAsync(messages);

            var result = await Controller.GetConferenceInstantMessageHistoryForParticipantAsync(conferenceId, participantUsername);

            var typedResult = (OkObjectResult)result;

            typedResult.Should().NotBeNull();
            var responseModel = typedResult.Value as List <ChatResponse>;

            responseModel.Should().NotBeNullOrEmpty();
            responseModel?.Count.Should().Be(messages.Count);
            responseModel?.Should().BeInAscendingOrder(r => r.Timestamp);
        }