Exemplo n.º 1
0
        public void Remove_NotExistingObjectPassed_ReturnsNotFoundResponse()
        {
            var id = 99;

            var result = _controller.Delete(id);

            Assert.IsType <NotFoundResult>(result);
        }
Exemplo n.º 2
0
        public void DeleteWithSucccessResponseTest()
        {
            var developerUsername = "******";

            var shoppingCartRepository = new Mock <IShoppingCartRepository>();

            shoppingCartRepository.Setup(x => x.RemoveDeveloperFromShoppingCart(developerUsername)).Returns(true);

            ShoppingCartController controller = CreateController(shoppingCartRepository);

            HttpResponseMessage result = controller.Delete(developerUsername);

            Assert.AreEqual(System.Net.HttpStatusCode.OK, result.StatusCode);
            Assert.IsNull(result.Content);
        }
Exemplo n.º 3
0
        public void DeleteWithErrorResponseTest()
        {
            var developerUsername = "******";

            var shoppingCartRepository = new Mock <IShoppingCartRepository>();

            shoppingCartRepository.Setup(x => x.RemoveDeveloperFromShoppingCart(developerUsername)).Throws(new KeyNotFoundException());

            ShoppingCartController controller = CreateController(shoppingCartRepository);

            HttpResponseMessage result = controller.Delete(developerUsername);

            Assert.AreEqual(System.Net.HttpStatusCode.InternalServerError, result.StatusCode);
            Assert.IsNotNull(result.Content);
        }
Exemplo n.º 4
0
        //TEST:  SHOPPINGCART_DELETE_TEST
        //Test the functionality of the ShoppingCart Delete method using test data.
        public void ShoppingCart_Delete_Test()
        {
            //ARRANGE
            ShoppingCartController shoppingCartController = new ShoppingCartController();
            MyDataEntities         db = new MyDataEntities();
            //Grab the test user that we created in Users_Register and find their UserID. This is used to delete the User's cart
            var userArray  = db.Users.Where(x => x.UserName == "testRegisterUser").ToList();
            int testUserID = 0;

            foreach (var item in userArray)
            {
                testUserID = item.UserID;
            }

            //ACT
            ActionResult result = shoppingCartController.Delete(testUserID);

            //ASSERT
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(JsonResult));
        }
Exemplo n.º 5
0
        public async Task DeleteCartItemTest()
        {
            //_eventStore.Setup(t => t.Raise("ShoppingCartItemRemoved", new { Id = 124, item = 12})).Returns(0uL);
            _eventStore.Setup(t => t.Raise("ShoppingCartItemRemoved", It.IsAny<object>())).Returns(0uL);

            var item = new ShoppingCartItem(12, "ProductName", "Description", new Money("USD", 987.12m));
            var shoppingCart = new ShoppingCart(124, new[] { item });
            _shoppingCartStore.Setup(t => t.Get(124)).Returns(Task.FromResult(shoppingCart));
            _shoppingCartStore.Setup(t => t.Save(It.IsAny<ShoppingCart>())).Returns(Task.CompletedTask);

            var request = new Mock<HttpRequest>();
            // request.Setup(x => x.Scheme).Returns("http");
            // request.Setup(x => x.Host).Returns(HostString.FromUriComponent("http://localhost:8080"));
            // request.Setup(x => x.PathBase).Returns(PathString.FromUriComponent("/api"));
            var httpContext = Mock.Of<HttpContext>(_ => _.Request == request.Object);
            var controllerContext = new ControllerContext { HttpContext = httpContext };
            var controller = new ShoppingCartController(_logger.Object, _shoppingCartStore.Object, _productCatalog.Object, _eventStore.Object)
            {
                ControllerContext = controllerContext,
            };

            await controller.Delete(124, new[] { 12 });
            Assert.IsFalse(shoppingCart.Items.Any());
        }