private Blog CreateBlog(Document inDocument)
        {
            using var documentContext = this.ApiServiceContext.CreateApiDocumentContext(inDocument);
            var inBlog = documentContext.GetResource <Blog>();

            var validator = new BlogValidator();

            validator.ValidateAndThrow(inBlog);

            var outBlog = this.BloggingRepository.CreateBlog(inBlog);

            return(outBlog);
        }
Пример #2
0
        public void Insert()
        {
            BlogCategory category = BlogValidator.ValidateCategory(null, ctx);

            if (errors.HasErrors)
            {
                run(New);
                return;
            }

            categoryService.Insert(category);
            List <BlogCategory> categories = categoryService.GetByApp(category.AppId);

            dropList("CategoryId", categories, "Name=Id", category.Id);
            set("cid", category.Id);
        }
        public void Adds_valid_entities_to_repositories()
        {
            friendlyUrlGen.Expect(x => x.GenerateUrl(Arg<string>.Is.Anything, Arg<string[]>.Is.Anything)).Return("aaaa").
                Repeat.
                Any();
            var blogValidator = new BlogValidator();
            var postValidator = new PostValidator();
            var userValidator = new UserValidator();

            blogRP.Expect(x => x.SaveBlog(Arg<Blog>.Is.Anything))
                .Do(new Expect<Blog>(blogValidator.ValidateAndThrowException));
            userRP.Expect(x => x.SaveUser(Arg<User>.Is.Anything))
                .Do(new Expect<User>(userValidator.ValidateAndThrowException));
            postRP.Expect(x => x.SavePost(Arg<Post>.Is.Anything))
                .Do(new Expect<Post>(postValidator.ValidateAndThrowException));

            var installer = new DefaultStartupInstaller(blogRP, postRP, userRP, friendlyUrlGen);

            installer.Execute();
        }
Пример #4
0
 public BlogValidatorTests()
 {
     _validator = new BlogValidator();
 }
Пример #5
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));
            }
        }