public async Task Delete_IncorrectValues_Returns404()
        {
            //arrange
            BLComment comment = null;

            _commentService.Setup(cs => cs.GetById(111)).Returns(Task.FromResult(comment));
            //act
            var result = await _commentsController.Delete(111);

            //assert
            _commentService.Verify(cs => cs.GetById(111));
            Assert.AreEqual(result.GetType(), typeof(NotFoundResult));
        }
Example #2
0
        public async Task <IActionResult> Post(int gameId, [FromBody] BLComment comment)
        {
            if (gameId <= 0 || comment == null || comment.Body.Length == 0 || comment.GameId < 0 ||
                comment.Name.Length == 0)
            {
                return(BadRequest("Wrong arguments for model creation"));
            }

            comment.GameId = gameId;
            await _commentService.AddAsync(comment);

            return(Created("/api/comments/" + gameId, comment));
        }
Example #3
0
        public void AddAsync_IncorrectComment_ThrowsEx()
        {
            //arrange
            BLComment comment = new BLComment()
            {
                Body = "Body", GameId = 1, Name = ""
            };

            _commentRepository.Setup(cr => cr.InsertAsync(It.IsAny <Comment>())).Returns(Task.CompletedTask).Verifiable();
            _unitOfWork.Setup(cr => cr.SaveAsync()).Returns(Task.CompletedTask).Verifiable();
            //act
            //assert
            Assert.ThrowsAsync <ArgumentException>(async() => await _commentService.AddAsync(comment));
        }
        public async Task Post_IdOfGameAndNewComment_Returns201()
        {
            //arrange
            BLComment comment = new BLComment {
                Body = "Body", Name = "Name", GameId = 1
            };

            _commentService.Setup(cs => cs.AddAsync(comment)).Returns(Task.FromResult(true)).Verifiable();
            //act
            var result = await _commentsController.Post(1, comment);

            //assert
            _commentService.Verify(cs => cs.AddAsync(comment));
            Assert.AreEqual(result.GetType(), typeof(CreatedResult));
        }
        public async Task Post_IncorrectValues_Returns404()
        {
            //arrange
            BLComment commentDal = null;
            BLComment comment    = new BLComment {
                Body = "Body", Name = "Name", GameId = 1
            };

            _commentService.Setup(cs => cs.GetById(1)).Returns(Task.FromResult(commentDal));
            //act
            var result = await _commentsController.AnswerToComment(2, 1, comment);

            //assert
            _commentService.Verify(cs => cs.GetById(1));
            Assert.AreEqual(result.GetType(), typeof(NotFoundResult));
        }
        public async Task AnswerToComment_CorrectValues_Returns200()
        {
            //arrange
            BLComment comment = new BLComment {
                Body = "Body", Name = "Name", GameId = 1
            };

            _commentService.Setup(cs => cs.AddAsync(comment)).Returns(Task.FromResult(true)).Verifiable();
            _commentService.Setup(cs => cs.GetById(1)).Returns(Task.FromResult(comment));
            //act
            var result = await _commentsController.AnswerToComment(2, 1, comment);

            //assert
            _commentService.Verify(cs => cs.AddAsync(comment));
            _commentService.Verify(cs => cs.GetById(1));
            Assert.AreEqual(result.GetType(), typeof(CreatedResult));
        }
Example #7
0
        public async Task AddAsync_CorrectComment_AddToDB()
        {
            //arrange
            BLComment comment = new BLComment()
            {
                Body = "Body", GameId = 1, Name = "Name"
            };

            _commentRepository.Setup(cr => cr.InsertAsync(It.IsAny <Comment>())).Returns(Task.CompletedTask).Verifiable();
            _unitOfWork.Setup(cr => cr.SaveAsync()).Returns(Task.CompletedTask).Verifiable();
            //act
            await _commentService.AddAsync(comment);

            //assert
            _commentRepository.Verify(cs => cs.InsertAsync(It.IsAny <Comment>()));
            _unitOfWork.Verify(cs => cs.SaveAsync());
        }
Example #8
0
        public async Task <IActionResult> AnswerToComment(int gameId, int commentId, [FromBody] BLComment comment)
        {
            if (gameId <= 0 || comment == null || comment.Body.Length == 0 || comment.GameId < 0 ||
                comment.Name.Length == 0 || commentId <= 0)
            {
                return(BadRequest("Wrong arguments for model creation"));
            }

            comment.GameId = gameId;
            if ((await _commentService.GetById(commentId))?.Body == null)
            {
                return(NotFound());
            }

            comment.ParentCommentId = commentId;
            await _commentService.AddAsync(comment);

            return(Created("api/comments/" + gameId + "/" + commentId, comment));
        }
Example #9
0
        // Chia bảng ra nhiều lần get, một lần get (end - begin) item
        static private DataTable GetDatabase(int begin, int end, out bool flag, string nameTable)
        {
            flag = true;
            DataSet dt = null;

            if (nameTable.Contains("IMAGE"))
            {
                switch (nameTable.Trim())
                {
                case "IMAGE_PHONE":
                    dt = new BLImageSmartPhone().GetData();
                    break;

                case "IMAGE_LAPTOP":
                    dt = new BLImageLaptop().GetData();
                    break;

                case "IMAGE_FASHION":
                    dt = new BLImageFahion().GetData();
                    break;

                case "IMAGE_CAR":
                    dt = new BLImageCar().GetData();
                    break;

                case "IMAGE_BOOK":
                    dt = new BLImageCar().GetData();
                    break;

                default:
                    flag = false;
                    return(null);
                }
            }
            else if (nameTable.Contains("PRODUCT"))
            {
                switch (nameTable.Trim())
                {
                case "PRODUCT_PHONE":
                    dt = new BLProductSmart().GetData();
                    break;

                case "PRODUCT_LAPTOP":
                    dt = new BLProductLaptop().GetData();
                    break;

                case "PRODUCT_FASHION":
                    dt = new BLProductFashion().GetData();
                    break;

                case "PRODUCT_CAR":
                    dt = new BLProductCar().GetData();
                    break;

                case "PRODUCT_BOOK":
                    dt = new BLProductBook().GetData();
                    break;

                default:
                    flag = false;
                    return(null);
                }
            }
            else if (nameTable.Contains("DETAIL"))
            {
                switch (nameTable.Trim())
                {
                case "DETAIL_PHONE":
                    dt = new BLDetailSmartPhone().GetData();
                    break;

                case "DETAIL_LAPTOP":
                    dt = new BLDetailLaptop().GetData();
                    break;

                case "DETAIL_FASHION":
                    dt = new BLDetailFashion().GetData();
                    break;

                case "DETAIL_CAR":
                    dt = new BLDetailCar().GetData();
                    break;

                case "DETAIL_BOOK":
                    dt = new BLDetailBook().GetData();
                    break;

                default:
                    flag = false;
                    return(null);
                }
            }
            else if (nameTable.Contains("CATEGORY"))
            {
                switch (nameTable.Trim())
                {
                case "CATEGORY_PHONE":
                    dt = new BLCategory_Smartphone_Tablet().GetData();
                    break;

                case "CATEGORY_LAPTOP":
                    dt = new BLCategory_Laptop().GetData();
                    break;

                case "CATEGORY_FASHION":
                    dt = new BLCategory_Fashion().GetData();
                    break;

                case "CATEGORY_CAR":
                    dt = new BLCategory_Car().GetData();
                    break;

                case "CATEGORY_BOOK":
                    dt = new BLCategory_Book().GetData();
                    break;

                default:
                    flag = false;
                    return(null);
                }
            }
            else
            {
                switch (nameTable.Trim())
                {
                case "CUSTOMER":
                    dt = new BLCustomer().GetData();
                    break;

                case "COMMENT":
                    dt = new BLComment().GetData();
                    break;

                case "BILL":
                    dt = new BLDetailBill().GetData();
                    break;

                default:
                    flag = false;
                    return(null);
                }
            }

            DataTable table = dt.Tables[0];

            if (table.Rows.Count <= end)
            {
                end  = table.Rows.Count;
                flag = false;
            }
            DataTable resulrSplip = table.AsEnumerable().Skip(begin).Take(end - begin).CopyToDataTable();

            return(resulrSplip);
        }