コード例 #1
0
        public async Task PublishPostAsyncTest()
        {
            var post = new Dto.Post
            {
                AuthorId        = new Guid("00c599a4-b832-4849-b951-b33dd694735e"),
                EmailUser       = "******",
                Id              = 6,
                LastChangedDate = Convert.ToDateTime("2021-02-08 17:24:41.7434906"),
                PostMessage     = "test mock post",
                PublishedDate   = Convert.ToDateTime("2021-02-08 17:20:51.4970303"),
                StatusId        = 4,
                UserName        = "******",
                Statuses        = new List <Dto.PostStatus>
                {
                    new Dto.PostStatus
                    {
                        Comment           = "Published",
                        Id                = 11,
                        Status            = 4,
                        StatusDate        = Convert.ToDateTime("2021-02-08 17:20:51.4970303"),
                        StatusDescription = "Approved",
                        UserId            = new Guid("00c599a4-b832-4849-b951-b33dd694735e")
                    }
                }
            };

            mBLPost.Setup(m => m.PublishPostAsync(post)).Returns(Task.FromResult <string>(""));

            var resultObj = await postController.PublishPostAsync(post);

            var actualResult = (StatusCodeResult)resultObj;

            Assert.AreEqual(HttpStatusCode.Created, (HttpStatusCode)actualResult.StatusCode);
        }
コード例 #2
0
        public async Task PublishPostAsync(Dto.Post post_dto)
        {
            if (post_dto == null)
            {
                throw new ArgumentNullException("post is null");
            }

            //Validate post status.
            if (!post_dto.Statuses.IsAny())
            {
                throw new ArgumentNullException("post doesn't have status assigned.");
            }

            try
            {
                await Task.Factory.StartNew(() =>
                {
                    var post = mapper.Map <Post>(post_dto);
                    unitWork.Posts.Add(post);
                    unitWork.Complete();
                });
            }
            catch (AutoMapperMappingException)
            {
                throw new Exception("Error mapping entities...");
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #3
0
        public async Task <IActionResult> UpdatePostAsync([FromBody] Dto.Post post)
        {
            try
            {
                await blPosts.UpdatePostAsync(post);

                return(NoContent());
            }
            catch (ArgumentException argEx)
            {
                return(BadRequest(argEx));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
コード例 #4
0
        public async Task <Dto.Post> GetPostsByIdAsync(int postId)
        {
            try
            {
                Dto.Post post = null;

                var posts_db = await unitWork.Posts.GetPostsByIdAsync(postId);

                if (posts_db != null)
                {
                    post = mapper.Map <Dto.Post>(posts_db);
                }

                return(post);
            }
            catch (AutoMapperMappingException)
            {
                throw new Exception("Error mapping entities...");
            }
            catch (Exception)
            {
                throw;
            }
        }