Beispiel #1
0
        public void Posts_Are_Imported()
        {
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { ImportFile, new MockFileData(ImportContent) }
            });

            var bloggerImporter = new BloggerImport(fileSystem, BaseSite, ImportFile);

            bloggerImporter.Import();

            string expectedPost = @"_posts\2000-09-07-Hello-World-1.md";

            Assert.True(fileSystem.File.Exists(BaseSite + expectedPost));

            var postContent = fileSystem.File.ReadAllText(BaseSite + expectedPost);
            var header      = postContent.YamlHeader();

            Assert.Equal("Hello World 1", header["title"].ToString());
            Assert.Equal(0, ((List <string>)header["tags"]).Count);

            string expectedPost2 = @"_posts\2000-09-07-Hello-World-2.md";

            Assert.True(fileSystem.File.Exists(BaseSite + expectedPost2));

            var postContent2 = fileSystem.File.ReadAllText(BaseSite + expectedPost2);
            var header2      = postContent2.YamlHeader();

            Assert.Equal("Hello World 2", header2["title"].ToString());
            var tags = (List <string>)header2["tags"];

            Assert.Equal(1, tags.Count);
            Assert.Equal("aTag", tags[0]);
        }
Beispiel #2
0
        protected override Task <int> Execute(ImportCommandArguments arguments)
        {
            Tracing.Info("import - import posts from external source");

            if (!Importers.Any(e => string.Equals(e, arguments.ImportType, StringComparison.InvariantCultureIgnoreCase)))
            {
                Tracing.Info("Requested import type not found: {0}", arguments.ImportType);

                return(Task.FromResult(1));
            }

            if (string.Equals("wordpress", arguments.ImportType, StringComparison.InvariantCultureIgnoreCase))
            {
                var wordpressImporter = new WordpressImport(FileSystem, arguments.Source, arguments.ImportFile);
                wordpressImporter.Import();
            }
            else if (string.Equals("blogger", arguments.ImportType, StringComparison.InvariantCultureIgnoreCase))
            {
                var bloggerImporter = new BloggerImport(FileSystem, arguments.Source, arguments.ImportFile);
                bloggerImporter.Import();
            }

            Tracing.Info("Import complete");

            return(Task.FromResult(0));
        }
Beispiel #3
0
        public void Error_on_write_is_traced()
        {
            Thread.CurrentThread.CurrentCulture   = CultureInfo.InvariantCulture;
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
            // arrange
            StringBuilder sb = new StringBuilder();

            Tracing.SetTrace((message, traceLevel) => { sb.AppendLine(message); });
            Tracing.SetMinimalLevel(TraceLevel.Debug);

            var fileSubstitute = Substitute.For <FileBase>();

            fileSubstitute.ReadAllText(ImportFile).Returns(ImportContent);
            fileSubstitute.When(f => f.WriteAllText(Arg.Any <string>(), Arg.Any <string>())).Do(x => { throw new Exception(); });

            var fileSystemSubstitute = Substitute.For <IFileSystem>();

            fileSystemSubstitute.File.Returns(fileSubstitute);

            // act
            var bloggerImporter = new BloggerImport(fileSystemSubstitute, BaseSite, ImportFile);

            bloggerImporter.Import();

            // assert
            Assert.Contains(@"Failed to write out 2000-09-07-Hello-World-1.md", sb.ToString());
            Assert.Contains("Exception of type 'System.Exception' was thrown.", sb.ToString());
            Assert.Contains(@"Failed to write out 2000-09-07-Hello-World-2.md", sb.ToString());
        }
Beispiel #4
0
#pragma warning restore 649

        public void Execute(IEnumerable <string> arguments)
        {
            Tracing.Info("import - import posts from external source");

            parameters.Parse(arguments);

            if (!Importers.Any(e => String.Equals(e, parameters.ImportType, StringComparison.InvariantCultureIgnoreCase)))
            {
                Tracing.Info("Requested import type not found: {0}", parameters.ImportType);
                return;
            }

            if (string.Equals("wordpress", parameters.ImportType, StringComparison.InvariantCultureIgnoreCase))
            {
                var wordpressImporter = new WordpressImport(fileSystem, parameters.Path, parameters.ImportPath);
                wordpressImporter.Import();
            }
            else if (string.Equals("blogger", parameters.ImportType, StringComparison.InvariantCultureIgnoreCase))
            {
                var bloggerImporter = new BloggerImport(fileSystem, parameters.Path, parameters.ImportPath);
                bloggerImporter.Import();
            }

            Tracing.Info("Import complete");
        }