public void CanDeserializePostYaml()
 {
     var postSerializer = new PostDeserializer();
     var serializedPost = postSerializer.Serialize(Post);
     Assert.IsNotNull(serializedPost);
     Assert.AreEqual("Lorem Ipsum Dolor", serializedPost.Title);
     Assert.AreEqual("5/18/2013", serializedPost.DateCreated.ToShortDateString());
     Assert.AreEqual("5/18/2013", serializedPost.DateEdited.ToShortDateString());
     Assert.AreEqual("Lorem ipsum dolor sit amet, consectetur <b>adipiscing</b> elit. Sed orci ante, tincidunt vitae hendrerit aliquam, molestie in nulla. Vestibulum sit amet mollis libero. Curabitur sit amet porta dui. Proin lectus urna, vulputate ac laoreet ut, scelerisque id neque. Etiam posuere metus et justo vestibulum egestas a id arcu. Suspendisse commodo ipsum ac nisi volutpat posuere facilisis dui pretium. Mauris mollis, felis quis laoreet faucibus, felis eros imperdiet ipsum, et congue mauris erat ac justo. Duis molestie venenatis magna, et convallis elit fermentum sed. Nulla tortor diam, auctor non suscipit at, sagittis ut est. Nam purus felis, hendrerit sit amet sodales sit amet, feugiat at sapien. Donec sed tellus nisl, id suscipit massa. Curabitur iaculis, dui ac mattis cursus, enim eros imperdiet lacus, eget egestas orci dui ut nibh. Aenean in sapien ipsum.", serializedPost.Content);
     Assert.AreEqual(3, serializedPost.Tags.Count());
     Assert.IsTrue(serializedPost.Tags.Contains("ASP.Net"));
     Assert.IsTrue(serializedPost.Tags.Contains("C#"));
     Assert.IsTrue(serializedPost.Tags.Contains("IronRuby"));
 }
 public void CanLocatePostsWithinThePostsFolder()
 {
     var resources = Assembly.GetExecutingAssembly().GetManifestResourceNames();
     foreach (var resource in resources)
     {
         var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource);
         if (stream != null)
         {
             var reader = new StreamReader(stream);
             var content = reader.ReadToEnd();
             var deserializer = new PostDeserializer();
             var instance = deserializer.Serialize(content);
             Assert.IsTrue(!string.IsNullOrEmpty(instance.Title));
         }
     }
 }
        public void CanSerializePostInstance()
        {
            var post = new Post
                {
                    Title = "Lorem Ipsum Dolor",
                    DateCreated = DateTime.Parse("5/18/2013"),
                    DateEdited = DateTime.Parse("5/18/2013"),
                    Content = "Lorem ipsum dolor sit amet, consectetur <b>adipiscing</b> elit. Sed orci ante, tincidunt vitae hendrerit aliquam, molestie in nulla. Vestibulum sit amet mollis libero. Curabitur sit amet porta dui. Proin lectus urna, vulputate ac laoreet ut, scelerisque id neque. Etiam posuere metus et justo vestibulum egestas a id arcu. Suspendisse commodo ipsum ac nisi volutpat posuere facilisis dui pretium. Mauris mollis, felis quis laoreet faucibus, felis eros imperdiet ipsum, et congue mauris erat ac justo. Duis molestie venenatis magna, et convallis elit fermentum sed. Nulla tortor diam, auctor non suscipit at, sagittis ut est. Nam purus felis, hendrerit sit amet sodales sit amet, feugiat at sapien. Donec sed tellus nisl, id suscipit massa. Curabitur iaculis, dui ac mattis cursus, enim eros imperdiet lacus, eget egestas orci dui ut nibh. Aenean in sapien ipsum.", 
                    Tags = new[]{ "ASP.Net","C#" }
                };
            var serializer = new PostSerializer();
            var serializedString = serializer.Serialize(post);

            var postSerializer = new PostDeserializer();
            var serializedPost = postSerializer.Serialize(serializedString);
            Assert.IsNotNull(serializedPost);

            Assert.IsTrue(!string.IsNullOrEmpty(serializedString));
            Assert.IsTrue(serializedString.IndexOf("Lorem ipsum dolor sit amet, consectetur <b>adipiscing</b> elit. Sed orci ante, tincidunt vitae hendrerit aliquam, molestie in nulla. Vestibulum sit amet mollis libero. Curabitur sit amet porta dui. Proin lectus urna, vulputate ac laoreet ut, scelerisque id neque. Etiam posuere metus et justo vestibulum egestas a id arcu. Suspendisse commodo ipsum ac nisi volutpat posuere facilisis dui pretium. Mauris mollis, felis quis laoreet faucibus, felis eros imperdiet ipsum, et congue mauris erat ac justo. Duis molestie venenatis magna, et convallis elit fermentum sed. Nulla tortor diam, auctor non suscipit at, sagittis ut est. Nam purus felis, hendrerit sit amet sodales sit amet, feugiat at sapien. Donec sed tellus nisl, id suscipit massa. Curabitur iaculis, dui ac mattis cursus, enim eros imperdiet lacus, eget egestas orci dui ut nibh. Aenean in sapien ipsum.", StringComparison.Ordinal) >= 0);
            Assert.IsTrue(serializedString.IndexOf("ASP.Net", StringComparison.Ordinal) >= 0);
            Assert.IsTrue(serializedString.IndexOf("C#", StringComparison.Ordinal) >= 0);
        }
Ejemplo n.º 4
0
 public List<Post> GetPosts(string basePath)
 {
     var postList = new List<Post>();
     var deserializer = new PostDeserializer();
     var files = Directory.GetFiles(basePath, "*.yml").ToList();
     files.ForEach(file =>
         {
             var fileContent = GetFileContent(file);
             try
             {
                 var instance = deserializer.Serialize(fileContent);
                 instance.PostUrl = UrlGenerator.UrlFriendly(Path.GetFileNameWithoutExtension(file));
                 postList.Add(instance);
             }
             // ReSharper disable EmptyGeneralCatchClause
             catch (Exception)
             // ReSharper restore EmptyGeneralCatchClause
             {
                 
             }
         });
     return postList;
 }
Ejemplo n.º 5
0
        public List <Post> GetPosts(string basePath)
        {
            var postList     = new List <Post>();
            var deserializer = new PostDeserializer();
            var files        = Directory.GetFiles(basePath, "*.yml").ToList();

            files.ForEach(file =>
            {
                var fileContent = GetFileContent(file);
                try
                {
                    var instance     = deserializer.Serialize(fileContent);
                    instance.PostUrl = UrlGenerator.UrlFriendly(Path.GetFileNameWithoutExtension(file));
                    postList.Add(instance);
                }
                // ReSharper disable EmptyGeneralCatchClause
                catch (Exception)
                // ReSharper restore EmptyGeneralCatchClause
                {
                }
            });
            return(postList);
        }