Ejemplo n.º 1
0
        public async Task <IActionResult> Write(WritePostModel model)
        {
            if (ModelState.IsValid)
            {
                var post = await _service.WritePostAsync(model.UrlSlug, model.Title, model.Summary, model.Body, model.Tags);

                return(RedirectToAction(nameof(Blog), new { Id = post.UrlSlug }));
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task Return_400_If_Params_Invalid()
        {
            // arrange
            HttpClient     client = CreateClient();
            WritePostModel model  = new WritePostModel
            {
                // missing all params
            };

            // act
            HttpResponseMessage response = await client.PostAsync("/Home/Write", model.ToFormContent());

            // assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
Ejemplo n.º 3
0
        public async Task Should_CreateBlogPost_IfParamsValid()
        {
            // arrange
            var context = _fixture.Context;
            var model   = new WritePostModel
            {
                UrlSlug = "test-post",
                Title   = "Test post",
                Summary = "Test post summary.",
                Body    = "Test post body.",
                Tags    = "test,tags"
            };

            // act
            await _fixture.Client.PostAsync("/Home/Write", model.ToFormContent());

            // assert
            var newPost = await context.Posts.FirstOrDefaultAsync(post => post.UrlSlug == model.UrlSlug);

            Assert.NotNull(newPost);
        }
Ejemplo n.º 4
0
        public async Task Create_Blog_Post_If_Params_Valid()
        {
            // arrange
            HttpClient client = CreateClient();

            WritePostModel model = new WritePostModel
            {
                UrlSlug = "test-post",
                Title   = "Test post",
                Summary = "Test post summary.",
                Body    = "Test post body.",
                Tags    = "test,tags"
            };

            // act
            await client.PostAsync("/Home/Write", model.ToFormContent());

            var result = await client.GetAsync($"/Home/Blog/{model.UrlSlug}");

            // assert
            Assert.True(result.IsSuccessStatusCode);
        }