public void GetSenderColorUnknownContactTest()
        {
            IConversation conversation = DummyConversationDataGenerator.GetSingleConversation(DummyPhoneNumberId.UnknownEagle);
            IConversationMessage incomingMessage = conversation.GetMessage(0);
            MockDisplayOptions displayOptions = new MockDisplayOptions();

            ConversationRendererRichText_Accessor renderer = new ConversationRendererRichText_Accessor(displayOptions, conversation);
            System.Windows.Media.Color incomingMessageColor = renderer.GetSenderDisplayColor(incomingMessage);

            Assert.IsNotNull(incomingMessageColor);
        }
        public void GetSenderColorMergedConversationTest()
        {
            IConversation conversation = DummyConversationDataGenerator.GetMergedConversation(DummyContactId.Davola);
            IConversationMessage cellIncomingMessage = conversation.GetMessage(0);
            IConversationMessage iPhoneIncomingMessage = conversation.GetMessage(11);
            MockDisplayOptions displayOptions = new MockDisplayOptions();

            ConversationRendererRichText_Accessor renderer = new ConversationRendererRichText_Accessor(displayOptions, conversation);
            System.Windows.Media.Color cellColor = renderer.GetSenderDisplayColor(cellIncomingMessage);
            System.Windows.Media.Color iPhoneColor = renderer.GetSenderDisplayColor(iPhoneIncomingMessage);

            Assert.AreEqual(cellColor, iPhoneColor);
        }
        public void MultiDayConversationTest()
        {
            IConversation conversation = GetMultiDayConversation();
            IDisplayOptions displayOptions = new MockDisplayOptions();

            ConversationRendererRichText_Accessor renderer = new ConversationRendererRichText_Accessor(displayOptions, conversation);

            List<Paragraph> paragraphsActual = renderer.RenderMessagesAsParagraphs(ConversationRendererRichText.RenderAllMessages);

            List<Paragraph> paragraphsExpected = GetMultiDayConversationRenderingExpected(conversation, renderer);

            VerifyParagraphListsEqual(paragraphsExpected, paragraphsActual);

            paragraphsActual = renderer.RenderMessagesAsParagraphs(ConversationRendererRichText.RenderAllMessages);
            Assert.AreEqual(0, paragraphsActual.Count);
        }
        public void NoMessageConversationTest()
        {
            IConversation conversation = DummyConversationDataGenerator.GetSingleConversation(DummyPhoneNumberId.NeverTexterCell);
            IDisplayOptions displayOptions = new MockDisplayOptions();

            ConversationRendererRichText renderer = new ConversationRendererRichText(displayOptions, conversation);

            List<Paragraph> paragraphsActual = renderer.RenderMessagesAsParagraphs(ConversationRendererRichText.RenderAllMessages);
            Assert.AreEqual(1, paragraphsActual.Count);

            Paragraph paragraphExpected = new Paragraph(new Italic(new Run(ConversationRendererRichText_Accessor._noConversationMessage)));
            VerifyParagraphsEqual(paragraphExpected, paragraphsActual[0]);

            //
            // Calling RenderMessages after messages have been rendered should return empty list.
            //

            paragraphsActual = renderer.RenderMessagesAsParagraphs(ConversationRendererRichText.RenderAllMessages);
            Assert.AreEqual(0, paragraphsActual.Count);
        }
        public void SingleMessageConversationTest()
        {
            IConversation conversation = DummyConversationDataGenerator.GetSingleConversation(DummyPhoneNumberId.UnknownEagle);
            IDisplayOptions displayOptions = new MockDisplayOptions();

            ConversationRendererRichText_Accessor renderer = new ConversationRendererRichText_Accessor(displayOptions, conversation);

            List<Paragraph> paragraphsActual = renderer.RenderMessagesAsParagraphs(ConversationRendererRichText.RenderAllMessages);
            Assert.AreEqual(1, paragraphsActual.Count);

            IConversationMessage message = conversation.GetMessage(0);

            Paragraph paragraphExpected = new Paragraph();
            paragraphExpected.Inlines.Add(ConversationRendererRichText_Accessor.DateAsInline(message.Timestamp));
            paragraphExpected.Inlines.Add(new LineBreak());
            paragraphExpected.Inlines.AddRange(renderer.ConversationMessageToInlines(message));

            VerifyParagraphsEqual(paragraphExpected, paragraphsActual[0]);

            paragraphsActual = renderer.RenderMessagesAsParagraphs(ConversationRendererRichText.RenderAllMessages);
            Assert.AreEqual(0, paragraphsActual.Count);
        }
        public void RenderIncrementallyTest()
        {
            IConversation conversation = GetMultiDayConversation();
            IDisplayOptions displayOptions = new MockDisplayOptions();

            ConversationRendererRichText_Accessor renderer = new ConversationRendererRichText_Accessor(displayOptions, conversation);

            List<Paragraph> paragraphsActual = new List<Paragraph>();

            const int MessageRenderSize = 1;

            List<Paragraph> paragraphsCurrent;
            while (renderer.HasUnprocessedMessages)
            {
                paragraphsCurrent = renderer.RenderMessagesAsParagraphs(MessageRenderSize);
                paragraphsActual.AddRange(paragraphsCurrent);
            }

            List<Paragraph> paragraphsExpected = GetMultiDayConversationRenderingExpected(conversation, renderer);

            VerifyParagraphListsEqual(paragraphsExpected, paragraphsActual);
        }
        public void RenderSingleMessageHideTimeTest()
        {
            IConversation conversation = DummyConversationDataGenerator.GetSingleConversation(DummyPhoneNumberId.UnknownEagle);
            IConversationMessage message = conversation.GetMessage(0);
            MockDisplayOptions displayOptions = new MockDisplayOptions();

            displayOptions.TimeDisplayFormat = TimeDisplayFormat.HideTime;

            ConversationRendererRichText_Accessor renderer = new ConversationRendererRichText_Accessor(displayOptions, conversation);

            List<Inline> inlineListExpected = new List<Inline>();
            Span messagePrefix = new Span();
            messagePrefix.Inlines.Add(new Bold(new Run("Unknown Sender")));
            messagePrefix.Inlines.Add(new Run(": "));
            inlineListExpected.Add(messagePrefix);
            inlineListExpected.Add(new ConversationContentRun(message.MessageContents));

            List<Inline> inlineListActual = new List<Inline>();
            inlineListActual.AddRange(renderer.ConversationMessageToInlines(message));

            VerifyInlineListsMatch(inlineListExpected, inlineListActual);
        }
        public void RenderMessageWithAttachmentTest()
        {
            string renderedExpected = @"<p>
            <span class=""date"">Sunday, Sep 9, 2012</span><br />
            <span style=""color:rgb(0,0,210);""><span class=""senderName"">Frankie Coolpics</span> <span class=""timestamp"">(<span dir=""ltr"" lang=""en"">8:34:15 PM</span>)</span>: </span>Check this shit out!<br />
            <a href=""FrankieCoolpics_attachments\IMG_0036.JPG"" target=""_blank""><img class=""attachmentImage"" src=""FrankieCoolpics_attachments\IMG_0036.JPG"" /></a><br />
            <span style=""color:rgb(210,0,0);""><span class=""senderName"">Me</span> <span class=""timestamp"">(<span dir=""ltr"" lang=""en"">8:34:30 PM</span>)</span>: </span>Crazy!
            </p>
            ";
            IDisplayOptionsReadOnly displayOptions = new MockDisplayOptions();
            AttachmentExportLocator attachmentExportLocator = new AttachmentExportLocator( @"C:\backup\export");
            attachmentExportLocator.AddFileExportLocation(@"C:\fakepath\backup\082308302382", @"C:\backup\export\FrankieCoolpics_attachments\IMG_0036.JPG");
            IConversation conversation = DummyConversationDataGenerator.GetSingleConversation(DummyPhoneNumberId.FrankieCoolPicsCell);
            IConversationRenderer renderer = new ConversationRendererHtml(displayOptions, conversation, attachmentExportLocator);

            string renderedActual = renderer.RenderMessagesAsString(ConversationRendererBase.RenderAllMessages);
            Assert.AreEqual(renderedExpected, renderedActual);
        }
        private void VerifyRenderedMessagesMatchExpected(Color color, string cssAttributeExpected)
        {
            IDisplayOptionsReadOnly displayOptions = new MockDisplayOptions();
            IConversation conversation = DummyConversationDataGenerator.GetSingleConversation(DummyPhoneNumberId.ObamaCell);
            ConversationRendererHtml_Accessor renderer = new ConversationRendererHtml_Accessor(displayOptions, conversation, new AttachmentExportLocator(null));

            string cssAttributeActual = renderer.ColorToCssAttribute(color);
            Assert.AreEqual(cssAttributeExpected, cssAttributeActual);
        }
        private void VerifyRenderedMessagesMatchExpected(DummyPhoneNumberId phoneNumberId, string renderedExpected)
        {
            IDisplayOptionsReadOnly displayOptions = new MockDisplayOptions();
            IConversation conversation = DummyConversationDataGenerator.GetSingleConversation(phoneNumberId);
            IConversationRenderer renderer = new ConversationRendererHtml(displayOptions, conversation, new AttachmentExportLocator(null));

            string renderedActual = renderer.RenderMessagesAsString(ConversationRendererBase.RenderAllMessages);
            Assert.AreEqual(renderedExpected, renderedActual);
        }
        private ConversationWindowModel GetPopulatedConversationWindowModel()
        {
            IDisplayOptions displayOptions = new MockDisplayOptions();
            IPhoneSelectOptions phoneSelectOptions = new MockPhoneSelectOptions();
            ConversationWindowModel model = new ConversationWindowModel(displayOptions, phoneSelectOptions);
            IConversationManager conversationManager = GetConversationManager(displayOptions);
            model.ConversationManager = conversationManager;

            return model;
        }
        private ConversationWindowModel GetEmptyPopulatedConversationWindowModel()
        {
            IDisplayOptions displayOptions = new MockDisplayOptions();
            IPhoneSelectOptions phoneSelectOptions = new MockPhoneSelectOptions();
            ConversationWindowModel model = new ConversationWindowModel(displayOptions, phoneSelectOptions);
            model.ConversationManager = DummyConversationDataGenerator.GetConversationManagerEmpty();

            return model;
        }