コード例 #1
0
        public async Task <int> CreateCommentsAsync(CommentsServiceModel commentsServiceModel, int?parentId = null)
        {
            var comments = AutoMapperConfig.MapperInstance.Map <Comment>(commentsServiceModel);

            comments.ParentId = parentId;

            this.dbContext.Comments.Add(comments);
            await this.dbContext.SaveChangesAsync();

            return(comments.Id);
        }
コード例 #2
0
        public async Task Create_WithCorrectData_ShouldSuccsessfullyCreate()
        {
            var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedData(dbContext);

            this.commentsService = new CommentsService(dbContext);

            var testCommentService = new CommentsServiceModel
            {
                Content = "comment3",
            };

            var expectedResultId = 3;
            var actualResultId   = await this.commentsService.CreateCommentsAsync(testCommentService);

            Assert.Equal(actualResultId, expectedResultId);
        }