Ejemplo n.º 1
0
        // GET: /Post/List?page=1
        public ActionResult List(int page = 1)
        {
            int         pageSize = 3;
            List <Post> posts    = new List <Post>(_helper.GetPosts()
                                                   .OrderByDescending(x => x.PostedOn)
                                                   .ToList()
                                                   );
            IEnumerable <Post> postsOnPages = posts.Skip((page - 1) * pageSize).Take(pageSize);
            Pagination         pageInfo     = new Pagination()
            {
                PageNumber = page, PageSize = pageSize, TotalItems = posts.Count
            };

            BlogViewModel viewModel = new BlogViewModel()
            {
                Posts      = postsOnPages,
                Categories = _categoryHelper.GetCategories(),
                PageInfo   = pageInfo
            };

            if (viewModel.Posts == null)
            {
                throw new HttpException(404, "Posts not found!");
            }

            return(View(viewModel));
        }
Ejemplo n.º 2
0
        public void SearchPost_WithValidData_ShouldReturnValidItems()
        {
            IList <Post> posts = PostHelper.GetPosts(6);

            posts[0].Title         = "Manage cookies using Web API";
            posts[0].SearchContent = "In my last project, I’ve deeply used WebApi, both for the client side and server side. In fact my application must call several REST endpoints developed with java and, after a code elaboration, I have to expose the data to other clients (javascript into an html page in this case).One of the pillars request by the Java services (really is not a technology request but just from the implementation made by the external company) is to read all cookies from the response and then send them back to the next requests (like a proxy).To make more clear where my app is, I realized the following chart:";

            posts[1].Title         = "Different keys with RavenDb";
            posts[1].SearchContent = "In last period, I am spending so times to learn document databases, in my case RavenDB and MongoDB. To be honest I am working only on Raven right now because it is friendlier for .NET developers but I promised myself to compare some features from these two awesome database engines. One of the big difficult I found, is to create the right model. I said big because I’m used to design the model for relation database and here is really different. For example we do not have the join and we also need to denormalize the references (http://ravendb.net/docs/faq/denormalized-references).";

            posts[2].Title         = "An amazing experience";
            posts[2].SearchContent = "Yesterday something special is happened and I still cannot believe that the Web.Net European Conference is over. For me was the first conference as a promoter and it was an AMAZING experience. More than 160 people from 11 different countries in the same building speaking about the future of the web (how F*ing cool is that?).";

            posts[3].Title         = "Use Less, Sass and Compass with ASP.NET MVC";
            posts[3].SearchContent = "In my last project, with my team, we chose to use Compass with SASS as CSS Authoring Framework.  Initially we was unsecure about that, the choice was very hard, the classic CSS allows you to find several guys who know it and it doesn’t require compilation unlike with Sass and Less. I’m not a front end developer so my part in this adventure is to manage the project and to make easy the integration of Less/Sass with an ASP.NET MVC application.";

            posts[4].Title         = "The best extensions for Visual Studio 2012";
            posts[4].SearchContent = "Visual Studio 2012 is absolutely the best IDE in the world and, with the latest version, it has sorted most of the big problems (from my point of view the previous version was a bit slow). I’m not a big fan of extensions because they often make Visual Studio unstable and/or slow, but I’ll make an exception because it this case it’s incredibly cool!";

            posts[5].Title         = "How integrate Facebook, Twitter, LinkedIn, Yahoo, Google and Microsoft Account with your ASP.NET MVC application";
            posts[5].SearchContent = "In the past week, 15 august, Microsoft released an incredible number of cool stuff, starting from Windows 8 and ending to Visual Studio 2012 including the new ASP.NET Stack. The version 4 of ASP.NET MVC introduces several cool features; most of them was available with the Beta and RC versions (Web API, Bundling, Mobile Projects Templates, etc.), but the RTM is not a “fixed version” of the RC, it has other interesting things.";

            foreach (Post post in posts)
            {
                this.SetupData(x => x.Store(post));
            }

            this.WaitStaleIndexes();

            IPagedResult <PostDto> result = this.sut.Search("Facebook", 1, 10, null);

            result.Result.Count().Should().Be.GreaterThan(0);
        }
Ejemplo n.º 3
0
        public void GetPostById_WithValidData_ShouldReturnTheCorrectItem()
        {
            // create repository
            IList <Post> posts = PostHelper.GetPosts(5);

            foreach (Post post in posts)
            {
                this.sut.Session.Store(post);
            }

            this.sut.Session.SaveChanges();

            PostDto expectedPost = this.sut.GetPostByKey(RavenIdHelper.Resolve(posts[2].Id));

            expectedPost.Should().Not.Be.Null();
            expectedPost.Title.Should().Be.EqualTo(posts[2].Title);
        }
Ejemplo n.º 4
0
        public void SavePost_ChangingSlug_ShouldUpdateDenormalizedData()
        {
            Post         post;
            ItemComments comments;

            using (IDocumentSession testSession = this.DocumentStore.OpenSession())
            {
                post           = PostHelper.GetPosts(1)[0];
                post.Status    = ItemStatus.Published;
                post.PublishAt = DateTime.Today;

                testSession.Store(post);

                comments          = new ItemComments();
                comments.Approved = new List <Comment>();
                comments.Item     = new ItemReference
                {
                    Id              = post.Id,
                    Status          = post.Status,
                    ItemPublishedAt = post.PublishAt
                };

                testSession.Store(comments);
                post.CommentsId = comments.Id;

                testSession.SaveChanges();
            }

            post.PublishAt = DateTime.Today.AddDays(5);

            PostDto postDto = post.MapTo <PostDto>();

            this.sut.SaveOrUpdate(postDto);

            this.sut.Session.SaveChanges();

            ItemComments retrievedComments = this.sut.Session.Load <ItemComments>(comments.Id);

            retrievedComments.Should().Not.Be.Null();
            retrievedComments.Item.Should().Not.Be.Null();
            retrievedComments.Item.ItemPublishedAt.Should().Be.EqualTo(post.PublishAt);
        }