<commit_before>﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Xml;
using BlogML;
using BlogML.Xml;
using MbUnit.Framework;
using Moq;
using Subtext.ImportExport;

namespace UnitTests.Subtext.BlogMl
{
    [TestFixture]
    public class BlogMLWriterTests
    {
        [Test]
        public void Write_WithSourceReturningBlog_WritesBlogInfoToWriter()
        {
            // arrange
            var stringWriter = new StringWriter();
            var xmlWriter = new XmlTextWriter(stringWriter);
            var source = new Mock<IBlogMLSource>();
            var dateTime = DateTime.ParseExact("20090123", "yyyyMMdd", CultureInfo.InvariantCulture);
            source.Setup(s => s.GetBlog()).Returns(new BlogMLBlog { Title = "Subtext Blog", RootUrl = "http://subtextproject.com/", SubTitle = "A test blog", DateCreated = dateTime});
            var writer = new BlogMLWriter(source.Object, false /*embedAttachments*/);

            // act
            ((IBlogMLWriter)writer).Write(xmlWriter);

            // assert
            string output = stringWriter.ToString();
            Assert.Contains(output, @"<title type=""text""><![CDATA[Subtext Blog]]></title>");
            Assert.Contains(output, @"<sub-title type=""text""><![CDATA[A test blog]]></sub-title>");
            Assert.Contains(output, @"root-url=""http://subtextproject.com/""");
            Assert.Contains(output, @"date-created=""2009-01-23T08:00:00""");
        }

        [Test]
        public void Write_WithSourceReturningBlogWithNullSubtitle_RendersEmptyStringForUrl()<commit_msg>Applying patch for issue 242. Thx alexander.beletsky<commit_after>﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Xml;
using BlogML;
using BlogML.Xml;
using MbUnit.Framework;
using Moq;
using Subtext.ImportExport;

namespace UnitTests.Subtext.BlogMl
{
    [TestFixture]
    public class BlogMLWriterTests
    {

        private static string DateCreated(DateTime dateTime)
        {
            return String.Format(@"date-created=""{0}""", dateTime.ToUniversalTime().ToString("s"));
        }

        [Test]
        public void Write_WithSourceReturningBlog_WritesBlogInfoToWriter()
        {
            // arrange
            var stringWriter = new StringWriter();
            var xmlWriter = new XmlTextWriter(stringWriter);
            var source = new Mock<IBlogMLSource>();
            var dateTime = DateTime.ParseExact("20090123", "yyyyMMdd", CultureInfo.InvariantCulture);
            source.Setup(s => s.GetBlog()).Returns(new BlogMLBlog { Title = "Subtext Blog", RootUrl = "http://subtextproject.com/", SubTitle = "A test blog", DateCreated = dateTime});
            var writer = new BlogMLWriter(source.Object, false /*embedAttachments*/);

            // act
            ((IBlogMLWriter)writer).Write(xmlWriter);

            // assert
            string output = stringWriter.ToString();
            Assert.Contains(output, @"<title type=""text""><![CDATA[Subtext Blog]]></title>");
            Assert.Contains(output, @"<sub-title type=""text""><![CDATA[A test blog]]></sub-title>");
            Assert.Contains(output, @"root-url=""http://subtextproject.com/""");
            Assert.Contains(output, DateCreated(dateTime));
        }

        [Test]
        public void Write_WithSourceReturningBlogWithNullSubtitle_RendersEmptyStringForUrl()
{'fraction_non_alphanumeric': 0.12993373667530972, 'fraction_numerical': 0.00979544799769519, 'mean_word_length': 3.02784222737819, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7551722', 'n_tokens_mistral': 1013, 'n_tokens_neox': 950, 'n_words': 199}