public void DeleteCategory_UsingAThreeShould_ShouldUpdateChildrensProperties()
        {
            IList <Category> categories = CategoryHelper.GetCategories(10);
            List <Category>  parents    = categories.Skip(0).Take(5).ToList();
            List <Category>  childrens  = categories.Skip(5).Take(5).ToList();

            this.SetupData(x =>
            {
                foreach (Category c in childrens)
                {
                    x.Store(c);
                }
            });

            parents[0].ChildrenIds = childrens.Select(x => x.Id).ToArray();

            this.SetupData(x =>
            {
                foreach (Category c in parents)
                {
                    x.Store(c);
                }
            });

            this.WaitStaleIndexes();

            this.sut.DeleteCategory(RavenIdHelper.Resolve(parents[0].Id), RavenIdHelper.Resolve(parents[1].Id));
            this.sut.Session.SaveChanges();

            using (IDocumentSession testSession = this.DocumentStore.OpenSession())
            {
                Category replaceCategory = testSession.Load <Category>(parents[1].Id);

                replaceCategory
                .ChildrenIds
                .Should()
                .Not
                .Be.Null();

                replaceCategory
                .ChildrenIds
                .Count()
                .Should()
                .Be
                .EqualTo(5);

                Category[] chlCat = testSession.Load <Category>(replaceCategory.ChildrenIds);

                foreach (Category category in chlCat)
                {
                    category.ParentId.Should().Be.EqualTo(replaceCategory.Id);
                }
            }
        }
Beispiel #2
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);
        }
        public void DeleteCategory_UsingTheDefaultCategory_ShouldMoveTheDefaultAttributoToTheNewCategory()
        {
            IList <Category> categories = CategoryHelper.GetCategories(4);

            Category defaultCategory = CategoryHelper.GetCategories(1)[0];

            defaultCategory.IsDefault = true;

            categories.Add(defaultCategory);

            this.SetupData(x =>
            {
                foreach (Category c in categories)
                {
                    x.Store(c);
                }
            });

            this.WaitStaleIndexes();

            this.sut.DeleteCategory(RavenIdHelper.Resolve(defaultCategory.Id), RavenIdHelper.Resolve(categories[0].Id));
            this.sut.Session.SaveChanges();

            IList <Category> newCategories;

            using (IDocumentSession testSession = this.DocumentStore.OpenSession())
            {
                newCategories = testSession.Query <Category>().ToList();
            }

            newCategories.Count(x => x.IsDefault)
            .Should()
            .Be
            .EqualTo(1);

            newCategories.Single(x => x.Id == categories[0].Id).IsDefault
            .Should()
            .Be
            .True();
        }
        public void DeleteCategory(int id, int newCategoryId)
        {
            if (id < 1)
            {
                throw new ArgumentException("Category id cannot be lesser than 1.", "id");
            }

            if (newCategoryId < 1)
            {
                throw new ArgumentException("New category id cannot be lesser than 1", "newCategoryId");
            }

            var ravenCategoryId    = RavenIdHelper.Resolve <Category>(id);
            var ravenNewCategoryId = RavenIdHelper.Resolve <Category>(newCategoryId);

            Category[] categories = this.Session.Load <Category>(new[] { ravenCategoryId, ravenNewCategoryId });

            if (categories[0] == null)
            {
                throw new DexterCategoryNotFoundException(id);
            }

            if (categories[0] == null)
            {
                throw new DexterCategoryNotFoundException(newCategoryId);
            }

            if (categories[0].IsDefault)
            {
                categories[1].IsDefault = true;
            }

            categories[1].ChildrenIds = categories[0].ChildrenIds;

            this.Session.Delete(categories[0]);
            this.Session.Store(categories[1]);

            UpdateCategoryIndex.UpdateCategoryIndexAfterDelete(this.store, this.Session, categories[0], categories[1]);
            UpdateCategoryIndex.UpdateCategoryIndexes(this.store, this.Session, categories[1], categories[0].Name);
        }
Beispiel #5
0
        public static void Configure()
        {
            Mapper.CreateMap <ItemDto, Item>()
            .ForMember(dest => dest.SearchContent, opt => opt.MapFrom(x => x.Content.CleanHtmlText()))
            .Include <PostDto, Post>()
            .Include <PageDto, Page>();

            Mapper.CreateMap <Item, ItemDto>()
            .ForMember(dest => dest.Id, opt => opt.MapFrom(x => RavenIdHelper.Resolve(x.Id)))
            .Include <Post, PostDto>()
            .Include <Page, PageDto>();

            Mapper.CreateMap <Post, PostDto>();

            Mapper.CreateMap <Page, PageDto>()
            .ForMember(dest => dest.PagesId, opt => opt.MapFrom(x => RavenIdHelper.Resolve(x.PagesId)))
            .ForMember(dest => dest.ParentId, opt => opt.MapFrom(x => RavenIdHelper.Resolve(x.ParentId)));

            Mapper.CreateMap <PageDto, Page>()
            .ForMember(dest => dest.Id, opt => opt.MapFrom(x => RavenIdHelper.Resolve <Page>(x.Id)))
            .ForMember(dest => dest.ParentId, opt => opt.MapFrom(x => RavenIdHelper.Resolve <Page>(x.ParentId)))
            .ForMember(dest => dest.PagesId, opt => opt.MapFrom(x => RavenIdHelper.Resolve <Page>(x.PagesId)));

            Mapper.CreateMap <PostDto, Post>()
            .ForMember(dest => dest.Id, opt => opt.MapFrom(x => RavenIdHelper.Resolve <Post>(x.Id)));

            Mapper.CreateMap <Comment, CommentDto>().ReverseMap();

            Mapper.CreateMap <Category, CategoryDto>()
            .ForMember(dest => dest.Id, opt => opt.MapFrom(x => RavenIdHelper.Resolve(x.Id)));

            Mapper.CreateMap <CategoryDto, Category>()
            .ForMember(dest => dest.Id, opt => opt.MapFrom(x => RavenIdHelper.Resolve <Category>(x.Id)))
            .ForMember(dest => dest.ParentId, opt => opt.MapFrom(x => RavenIdHelper.Resolve <Category>(x.Parent.Id)));

            Mapper.CreateMap <EmailMessage, EmailMessageDto>().ReverseMap();
        }
Beispiel #6
0
        public void SaveOrUpdate(PageDto item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item", "The post must be contains a valid instance");
            }

            Page page = this.Session.Load <Page>(item.Id)
                        ?? new Page
            {
                CreatedAt = DateTimeOffset.Now
            };

            if (string.IsNullOrEmpty(item.Author))
            {
                item.Author = Thread.CurrentPrincipal.Identity.Name;
            }

            item.MapPropertiesToInstance(page);

            if (string.IsNullOrEmpty(page.Excerpt))
            {
                page.Excerpt = AbstractHelper.GenerateAbstract(page.Content);
            }

            if (string.IsNullOrEmpty(page.Slug))
            {
                page.Slug = SlugHelper.GenerateSlug(page.Title, page.Id, this.GetPostBySlugInternal);
            }

            if (page.IsTransient)
            {
                ItemComments comments = new ItemComments
                {
                    Item = new ItemReference
                    {
                        Id              = page.Id,
                        Status          = page.Status,
                        ItemPublishedAt = page.PublishAt
                    }
                };

                this.Session.Store(comments);
                page.CommentsId = comments.Id;

                ItemTrackbacks trackbacks = new ItemTrackbacks
                {
                    Item = new ItemReference
                    {
                        Id              = page.Id,
                        Status          = page.Status,
                        ItemPublishedAt = page.PublishAt
                    }
                };

                this.Session.Store(trackbacks);
                page.TrackbacksId = trackbacks.Id;
            }

            this.Session.Store(page);

            UpdateDenormalizedItemIndex.UpdateIndexes(this.store, this.Session, page);

            item.Id = RavenIdHelper.Resolve(page.Id);
        }