Пример #1
0
		public PostViewer(IList<Post> posts, int position, Post post)
		{
			Title = WindowTitle = "Post: " + post.Title;
			this.posts = posts;
			this.position = position;
			InitializeComponent();
			DataContext = post;

			Categories.DataContext = post.Categories;

			//TODO: ?? apperantely there is no good way to load the data into a Frame except via Uri
			string template = @"
<html>
<body>
{0}
</body>
</html>
";
			File.WriteAllText(post.PostId + ".html", string.Format(template, post.Content));

			postFrame.Source = new Uri(string.Format("file:///{0}/{1}.html", Environment.CurrentDirectory, post.PostId));

			Categories.ItemsSource = post.Categories;
			if (position == 0)
			{
				Prev.Opacity = 0.25d;
				Prev.IsEnabled = false;
			}
			if (position + 1 == posts.Count)
			{
				Next.Opacity = 0.25d;
				Next .IsEnabled = false;
			}
		}
Пример #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Request["post.id"] != null) SavePost();
     post = (Request.QueryString["id"] == null) ?
         post = new Post() :
         post = Post.Get(Convert.ToInt32(Request.QueryString["id"]));
 }
Пример #3
0
		public async Task EnsureSeedData()
		{
			if (await _userManager.FindByEmailAsync("*****@*****.**") == null)
			{
				// Add the user
				var newUser = new BlogUser()
				{
					UserName = "******",
					Email = "*****@*****.**"
				};

				await _userManager.CreateAsync(newUser, "123321");
			}

			if (!_contex.Categories.Any())
			{
				var category = new Category() {Name = "Main", Description = "Descr"};
				_contex.Categories.Add(category);

				var firstPost = new Post()
				{
					Category = category,
					Title = "First Post"
				};
				_contex.Posts.Add(firstPost);

				_contex.SaveChanges();
			}
		}
Пример #4
0
        public void PostWithCommentTest()
        {
            m.Post post = new m.Post();
            post.Key = "PostWithCommentTest";
            post.Title = "Post With Comment Test";
            post.Content = "This is a post that will have comments.";
            post.Save();

            post.Comments = new List<Model.Comment>();

            m.Comment comment = null;

            for (int pass = 1; pass < 4; pass++)
            {
                comment = new m.Comment();
                comment.PostID = post.ID;
                comment.Number = pass;
                comment.Content = string.Format("this is comment number {0}.", pass);
                comment.Save();

                post.Comments.Add(comment);

                AssertGoodRead(comment, comment.ID);
            }
            Assert.IsTrue(post.Comments.Count == 3, "Wrong number of comments in post");

            m.Post readPost = m.Post.Get(post.Key);
            Assert.IsTrue(readPost.Comments.Count == 3, "Wrong number of comments in readPost");
            for (int pass = 1; pass < 4; pass++)
            {
                AssertAreEqual(post.Comments[pass - 1], readPost.Comments[pass - 1]);
            }
        }
Пример #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["id"] == null && Request["comment.post_id"] == null) Response.Redirect("Default.aspx");

            if (Request["comment.post_id"] != null) SaveComment();

            post = Post.Get(Convert.ToInt32(Request["id"]));
        }
        public void AddWillPassThroughToInnerRepository()
        {
            var post = new Post();

            Repository.Add(post);

            InnerRepository.Verify(r => r.Add(post));
        }
        public void DeleteWillPassThroughToInnerRepository()
        {
            var post = new Post();

            Repository.Delete(post);

            InnerRepository.Verify(r => r.Delete(post));
        }
Пример #8
0
        public void Add(Post post)
        {
            post.DateCreated = DateTime.Now;
            post.ContentHTML = Markdown.ToHtml(post.Content);
            post.Url = GenerateUrl(post);

            Context.Posts.Add(post);
            Context.SaveChanges(); // todo move this line out of here.
        }
Пример #9
0
        public void CreateAndGetTest()
        {
            m.Post post = new m.Post();
            post.Title = "CreateAndGetTest Document";
            post.Key = "CreateAndGetTest";
            post.Content = "This is a test document.";
            post.Save();

            AssertGoodRead(post, "CreateAndGetTest");
        }
Пример #10
0
    protected void DetailsViewPostovi_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    {
        Model.Post post = Data.DAL.getPostAutor(User.Identity.Name);
        SqlDataSourcePostoviDetails.InsertParameters["idAutor"].DefaultValue = post.idAutor.ToString();
        Calendar datum = (Calendar)DetailsViewPostovi.FindControl("Calendar1");
        DateTime dt    = Convert.ToDateTime(datum.SelectedDate.ToShortDateString());
        TimeSpan ts    = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);

        dt = dt.Add(ts);
        SqlDataSourcePostoviDetails.InsertParameters["Datum"].DefaultValue = dt.ToShortTimeString();
    }
Пример #11
0
        public void Can_Not_Add_Post_Without_Title()
        {
            // arrange ..
            Post post = new Post();
            post.Body = "Testing body for the post";
            post.Author = _neededUser;
            post.Blog = _neededBlog;

            // act .. and assert
            _postRepository.Add(post);
        }
Пример #12
0
        /// <summary>
        /// Adds the passed in entity to the entity set
        /// </summary>
        /// A <exception cref="NullReferenceException"> will be thrown if the passed in entity is null</exception>
        /// <param name="entity">Entity to be added</param>
        public void Add(Post entity)
        {
            Contract.Requires<ArgumentNullException>(entity != null);
            Contract.Requires<ArgumentNullException>(entity.Author != null);
            Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(entity.Title));
            Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(entity.Body));

            entity.CreatedDate = DateTime.Now;
            entity.LastModifiedDate = DateTime.Now;

            _repository.Add(entity);
        }
Пример #13
0
        public void Can_handle_new_post()
        {
            var post = new Post {Content = "this web site is cool: http://google.com"};
            httpClient.Expect(x => x.DownloadString("http://google.com"))
                .Return("<link rel=\"pingback\" href=\"http://localhost:2011/pingback.rem\"/>");

            pingbackService.HandleNewPost(new PostAddedEventArgs(null,post));

            httpClient.AssertWasCalled(x => x.DownloadString(Arg<string>.Is.Anything));
            Assert.That(FakePingbackService.SourceUri,Is.Not.Null.Or.Not.Empty);
            Assert.That(FakePingbackService.TargetUri, Is.Not.Null.Or.Not.Empty);
        }
Пример #14
0
        public void Setup()
        {
            dm.ExecuteNonQuery("truncate table posts");
            dm.ExecuteNonQuery("truncate table comments");

            m.Post post = new m.Post();
            post.Key = "CorePostForCommentTest";
            post.Title = "Core Post For Comment Test";
            post.Content = "This is some content for the core post.";
            post.Save(); // this post has id 1
            Assert.IsTrue(post.ID == 1, "Cannot continue with tests.  Something wrong with core post.");
        }
Пример #15
0
        public void UpdateTest()
        {
            m.Post post = new m.Post();
            post.Title = "UpdateTest Document";
            post.Key = "UpdateTest";
            post.Content = "This is a test document for update.";
            post.Save();

            AssertGoodRead(post, "UpdateTest");

            post.Content = "Change the content for the update test document";
            post.Save();

            AssertGoodRead(post, "UpdateTest");
        }
Пример #16
0
        public void Update(Post p)
        {
            var post = Find(p.Id);

            if (!post.Published && p.Published)
                post.DateCreated = DateTime.Now;

            post.Title = p.Title;
            post.Published = p.Published;
            post.Content = p.Content;
            post.ContentHTML = Markdown.ToHtml(post.Content);
            post.Url = GenerateUrl(p);

            Context.SaveChanges(); // todo move this line out of here.
        }
Пример #17
0
        public void Can_Add_Valid_Post()
        {
            // arrange ..
            Post post = new Post();
            post.Body = "Testing body for the post";
            post.Title = "Title for post";
            post.Author = _neededUser;
            post.Blog = _neededBlog;

            // act ..
            _postRepository.Add(post);

            // Assert ..
            Assert.Greater(post.Id, 0);
        }
Пример #18
0
        public ActionResult Delete(Post model)
        {
            try
            {
                // TODO: Add delete logic here

                work.PostRepository.Delete(model.PostID);
                work.Save();

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Пример #19
0
        public void Can_Not_Add_Post_Without_Body()
        {
            // Arrange ...
            var repository = new Mock<IPostRepository>();
            var component = new PostComponent(repository.Object);

            Post post = new Post();
            post.Title = "This is a very simple title for my first post";
            post.Blog = new Blog();
            post.Author = new User();

            // Act ...
            component.Add(post);

            // Assert .. verify
            repository.Verify(c => c.Add(post), Times.Never());
        }
Пример #20
0
        public ActionResult Create(Post model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    work.PostRepository.Insert(model);
                    work.Save();
                }
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
 public void Update(Post post)
 {
     Inner.Update(post);
 }
 public void Delete(Post post)
 {
     Inner.Delete(post);
 }
 public void Add(Post post)
 {
     Inner.Add(post);
 }
        /// <summary>
        /// Executes the default install.
        /// </summary>
        public void Execute()
        {
            if (isInitialized)
            {
                return;
            }

            var blog = blogRepository.GetBlog();
            if (blog != null)
            {
                isInitialized = true;
                return;
            }

            var user = new User
                       	{
                       		UserName = "******",
                       		Password = "******",
                       		Email = "*****@*****.**",
                       		ID = 1
                       	};

            blog = new Blog
                   	{
                   		ID = 1,
                   		Title = "BlogSharp Blogs",
                   		Writers = new List<User> {user},
                   		Founder = user,
                   		Configuration = new BlogConfiguration {PageSize = 10},
                   		Host = "localhost",
                   		Name = "BlogSharp",
                   	};

            var tag = new Tag {ID = 1, Name = "Welcome", FriendlyName = "welcome"};
            var title = "Welcome to BlogSharp!";
            var post = new Post
                       	{
                       		ID = 1,
                       		Blog = blog,
                       		Publisher = user,
                       		Tags = new List<Tag> {tag},
                       		Title = title,
                       		Content = "Great blog post is here you are.",
                       		FriendlyTitle = generator.GenerateUrl("{0}", title),
                       		DateCreated = DateTime.Now,
                       		DatePublished = DateTime.Now
                       	};
            tag.Posts.Add(post);
            blog.Configuration = new BlogConfiguration {PageSize = 10};
            blog.Posts.Add(post);
            userRepository.SaveUser(user);
            blogRepository.SaveBlog(blog);
            postRepository.SavePost(post);
            isInitialized = true;
        }
Пример #25
0
 public void RemovePost_calls_underlyting_repository_to_delete()
 {
     var post = new Model.Post();
     postService.RemovePost(post);
     postRepository.AssertWasCalled(x => x.DeletePost(post));
 }
Пример #26
0
        public ActionResult Edit(Post model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    work.PostRepository.Update(model);
                    work.Save();
                }
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Пример #27
0
		public void AddPost(Post newPost)
		{
			_context.Add(newPost);
		}
Пример #28
0
        public void CanSaveAllEntities()
        {
            using (var session = factory.OpenSession())
            {
                using (var tran = session.BeginTransaction())
                {
                    var blog = new Blog();
                    var user = new User();
                    var post = new Post();
                    var tag = new Tag();
                    var postComment = new PostComment();

                    var configuration = new BlogConfiguration();
                    configuration.PageSize = 3;
                    configuration["osman"] = "mahmut";

                    user.UserName = "******";
                    user.Password = "******";
                    user.Email = "*****@*****.**";
                    user.Blogs.Add(blog);

                    blog.Configuration = configuration;
                    blog.Writers.Add(user);
                    blog.Title = "my blog";
                    blog.Name = "My Blog";
                    blog.Founder = user;
                    blog.Posts.Add(post);
                    blog.Host = "localhost";

                    post.Blog = blog;
                    post.Content = "hello";
                    post.Publisher = user;
                    post.DateCreated = DateTime.Now;
                    post.DatePublished = DateTime.Now.AddMinutes(3);
                    post.Title = "post title";
                    post.FriendlyTitle = post.Title.Replace(' ', '_').ToLower();
                    post.AddComment(postComment, null);

                    postComment.Post = post;
                    postComment.Date = DateTime.Now.AddMinutes(6);
                    postComment.Email = "*****@*****.**";
                    postComment.Name = "Some One";
                    postComment.Comment = "Some One wrote here!!";

                    tag.Name = "Tag";
                    tag.FriendlyName = "Tagged";
                    tag.Posts.Add(post);
                    post.Tags.Add(tag);

                    var blogVal = new BlogValidator();
                    blogVal.ValidateAndThrowException(blog);

                    var postVal = new PostValidator();
                    postVal.ValidateAndThrowException(post);

                    var postCommVal = new PostCommentValidator();
                    postCommVal.ValidateAndThrowException(postComment);

                    var userVal = new UserValidator();
                    userVal.ValidateAndThrowException(user);

                    var tagVal = new TagValidator();
                    tagVal.ValidateAndThrowException(tag);

                    session.Save(user);
                    session.Save(blog);
                    session.Save(post);
                    session.Save(postComment);
                    session.Save(tag);

                    tran.Commit();
                }
            }

            using (var session = factory.OpenSession())
            {
                var item = session.CreateCriteria(typeof (Blog)).UniqueResult<Blog>();
                var pageSize = item.Configuration.PageSize;
                Assert.That(pageSize, Is.EqualTo(3));
            }
        }
Пример #29
0
 private static Post FromReader(IDataReader reader)
 {
     Post post = new Post();
     post.ID = dm.ConvertIntColumn(reader, "id");
     post.Key = dm.ConvertStringColumn(reader, "key");
     post.Title = dm.ConvertStringColumn(reader, "title");
     post.Content = dm.ConvertStringColumn(reader, "content");
     post.Created = (DateTime)reader["created"];
     return post;
 }
Пример #30
0
 public void AddPost_calls_underlying_repository_to_save()
 {
     var post = new Model.Post();
     postService.AddPost(post);
     postRepository.AssertWasCalled(x => x.SavePost(post));
 }
Пример #31
0
 protected void DetailsViewPostovi_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
 {
     Model.Post post = Data.DAL.getPostAutor(User.Identity.Name);
     SqlDataSourcePostoviDetails.UpdateParameters["idAutor"].DefaultValue = post.idAutor.ToString();
 }
Пример #32
0
 /// <summary>
 /// Removes the passed in <paramref name="entity"/> from the entities set
 /// </summary>
 /// <param name="entity">Entity to be deleted</param>
 public void Delete(Post entity)
 {
     Contract.Requires<ArgumentNullException>(entity != null);
     _repository.Delete(entity);
 }