示例#1
0
        public ActionResult AddRating(AddRatingVewModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                var result = this.productsService.AddRating(model.ProductId, (int)model.Value, this.CurrentUser.Id);

                return(Json(result));
            }

            throw new HttpException(400, "Invalid Rating");
        }
        public ActionResult AddRating(AddRatingVewModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                var result = this.productsService.AddRating(model.ProductId, (int)model.Value, this.CurrentUser.Id);

                return Json(result);               
            }

            throw new HttpException(400, "Invalid Rating");
        }
        public void TestIfProductsAddVallidRatingWorks()
        {
            var newRating = new AddRatingVewModel
            {
                ProductId = 1,
                Value = 4
            };

            this.controller
                .WithCallTo(c => c.AddRating(newRating))
                .ShouldReturnJson(data =>
                {
                    Assert.IsNotNull(data);
                    Assert.IsTrue((float)data == 3.5f);
                });
        }
        public void TestIfProductsAddVallidRatingWorks()
        {
            var newRating = new AddRatingVewModel
            {
                ProductId = 1,
                Value     = 4
            };

            this.controller
            .WithCallTo(c => c.AddRating(newRating))
            .ShouldReturnJson(data =>
            {
                Assert.IsNotNull(data);
                Assert.IsTrue((float)data == 3.5f);
            });
        }