Exemplo n.º 1
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="context"></param>
        public void AddFavoriteRequest(HttpContext context)
        {
            var response = new ResponseMessage();

            try
            {
                //string id = context.Request.Form["FavoriteId"];
                string productId = context.Request.Form["ProductId"];
                string userId    = context.Request.Form["UserId"];

                var exist = _InfoService.GetList().Where(y => y.ProductId == productId && y.UserId == userId).ToList();
                if (exist.Count() > 0)
                {
                    response.code = 500;
                    response.msg  = "已收藏该商品,请勿重复添加";
                    context.Response.Write(SerializeHelp.ToJson(response));
                    return;
                }
                Favorite Favorite = new Favorite()
                {
                    FavoriteId = Guid.NewGuid().ToString(),
                    ProductId  = productId,
                    UserId     = userId,
                    DateTime   = DateTime.Now,
                };
                var add = _InfoService.Add(Favorite);
                if (add)
                {
                    response.code = 0;
                    response.msg  = "添加成功";
                    context.Response.Write(SerializeHelp.ToJson(response));
                    return;
                }
                response.code = 500;
                response.msg  = "添加失败";
                context.Response.Write(SerializeHelp.ToJson(response));
            }
            catch (Exception e)
            {
                string error = e.Message;

                response.code = 500;
                response.msg  = "失败,请重试";
                context.Response.Write(SerializeHelp.ToJson(response));
            }
        }
Exemplo n.º 2
0
        public void ReturnProper_DeleteFavorite_ResultFromCommitMethod()
        {
            // Arrange
            var favoritesRepoMock = new Mock <IEfRepository <Favorite> >();
            var uowMock           = new Mock <ISaveContext>();

            favoritesRepoMock.Setup(c => c.Delete(It.IsAny <Favorite>())).Verifiable();
            uowMock.Setup(u => u.Commit()).Returns(1);

            var favoriteService = new FavoriteService(favoritesRepoMock.Object, uowMock.Object);

            // Act
            var result = favoriteService.Add(It.IsAny <Favorite>());

            // Assert
            Assert.That(result.Equals(1));
        }