示例#1
0
        public void ShouldAddProduct()
        {
            var dbProduct = crudOnProducts.AddOrUpdate(product).Result;

            Assert.NotNull(dbProduct);
            crudOnProducts.DeleteProduct(dbProduct.Id).Wait();
        }
        public void ShouldRevoteProductFromFavoritesAfterDeletingIt()
        {
            var productMockup = TestInitialiser.CreateProduct();
            var product       = crudOnProducts.AddOrUpdate(productMockup).Result;

            crudOnFavorites.AddProductToFavorites(username, product.Id).Wait();
            crudOnProducts.DeleteProduct(productId).Wait();
            var favorites = crudOnFavorites.GetUsersFavoriteProducts(username).Result;

            Assert.AreEqual(favorites.Count(), 0);
        }
示例#3
0
        public void ShouldSentProductAlert()
        {
            ProductEmailNotifications productEmailNotifications = new ProductEmailNotifications(crudOnAlerts, mailSender);
            var product = TestInitialiser.CreateProduct();

            product.Title = "ceva bun tare";
            var addedProduct = crudOnProducts.AddOrUpdate(product).Result;

            productEmailNotifications.SendEmailForProduct("ceva", addedProduct.Id);
            Assert.True(true);

            crudOnProducts.DeleteProduct(addedProduct.Id).Wait();
        }
示例#4
0
        public async Task <IHttpActionResult> Post([FromBody] ViewProduct viewProduct)
        {
            try
            {
                if (!await authorization.UserCanUpdateProduct(User.Identity.GetUserName(), viewProduct.Id, viewProduct.UserName))
                {
                    return(Unauthorized());
                }

                var product         = Mapper.Map <Product>(viewProduct);
                var returnedProduct = await crudOnProducts.AddOrUpdate(product);

                var returnedViewProduct = Mapper.Map <ViewProduct>(returnedProduct);

                SendAlertsForProduct(returnedViewProduct.Title, returnedViewProduct.Id);

                return(Ok(returnedViewProduct));
            }
            catch (Exception ex)
            {
                return(throwExceptionToUser.Throw(ex));
            }
        }