public void Adding_Game_To_Cart_Goes_To_Cart_Screen() { // Arrange Mock <IGameRepository> mock = new Mock <IGameRepository>(); mock.Setup(m => m.Games).Returns(new List <Game> { new Game { GameId = 1, Name = "G-1", Category = "Cat-1" } }.AsQueryable()); Cart cart = new Cart(); CartController controller = new CartController(mock.Object, null); // Act RedirectToRouteResult result = controller.AddToCart(cart, 2, "myUrl"); // Assert Assert.AreEqual("Index", result.RouteValues["action"]); Assert.AreEqual("myUrl", result.RouteValues["returnUrl"]); }
public void Can_Add_To_Cart() { //Arrange - create the mock repository Mock <IProductRepository> mock = new Mock <IProductRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product { ProductID = 1, Name = "P1", Category = "Apples" }, }.AsQueryable()); //Arrange - create Cart Cart cart = new Cart(); //Arrange - create the controller CartController target = new CartController(mock.Object, null); //Act - add a product to the cart target.AddToCart(cart, 1, null); //Assert Assert.AreEqual(cart.Lines.Count(), 1); Assert.AreEqual(cart.Lines.ToArray()[0].Product.ProductID, 1); }
public void Can_Add_To_Cart() { // 准备-创建模仿存储库 Mock <IProductsRepository> mock = new Mock <IProductsRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product { ProductID = 1, Name = "P1", Category = "Apples" } }.AsQueryable()); // 准备-创建新购物车 Cart cart = new Cart(); // 准备-创建控制器 CartController target = new CartController(mock.Object, null); // 动作-对cart添加一个产品 target.AddToCart(cart, 1, null); // 断言 Assert.AreEqual(cart.Lines.Count(), 1); Assert.AreEqual(cart.Lines.ToArray()[0].Product.ProductID, 1); }
public void Completed_ClearsTheCart() { //Arrange var options = TestDbContextOptionsBuilder(); SeedTestDb(options); var productToAdd = 1; using (var context = new P3Referential(options)) { var cart = new Cart(); var productRepository = new ProductRepository(context); var orderRepository = new OrderRepository(context); var productService = new ProductService(cart, productRepository, null, null); var orderService = new OrderService(cart, orderRepository, productService); var orderController = new OrderController(cart, orderService, null); var cartController = new CartController(cart, productService); cartController.AddToCart(productToAdd); //Check that cart has a single item Assert.Single(cart.Lines); //Act orderController.Completed(); //Verify that the cart gets cleared Assert.Empty(cart.Lines); //Cleanup context.Database.EnsureDeleted(); } }
public void Adding_Book_To_Cart() { Mock <IBookRepository> mock = new Mock <IBookRepository>(); mock.Setup(m => m.Books).Returns(new List <Book> { new Book { BookID = 1, Name = "Book1", Genre = "Genre1" }, new Book { BookID = 2, Name = "Book2", Genre = "Genre2" }, new Book { BookID = 3, Name = "Book3", Genre = "Genre1" }, new Book { BookID = 4, Name = "Book4", Genre = "Genre3" }, new Book { BookID = 5, Name = "Book5", Genre = "Genre2" }, }.AsQueryable()); CartController controller = new CartController(mock.Object, null); Cart cart = new Cart(); RedirectToRouteResult result = controller.AddToCart(cart, 1, "myUrl"); Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl"); }
public void Can_Add_To_Cart() { // Arrange Mock <IProductRepository> mock = new Mock <IProductRepository>(); mock.Setup(m => m.Products).Returns(new[] { new Product { ProductID = 1, Name = "P1", Category = "Apples" }, new Product { ProductID = 2, Name = "P2", Category = "Oranges" }, }.AsQueryable()); Cart cart = new Cart(); CartController controller = new CartController(mock.Object, null); // Act controller.AddToCart(cart, 1, null); // Assert CollectionAssert.AreEqual(cart.Lines.Select(l => l.Product.ProductID).ToArray(), new[] { 1 }); }
public void Can_Add_To_Cart() { // Организация - создание имитированного хранилища // Организация - создание имитированного хранилища Mock <IShopRepository> mock = new Mock <IShopRepository>(); mock.Setup(m => m.Products).Returns(new List <Product> { new Product() { Id = 1, Name = "Игра1", Category = "Кат1" }, }.AsQueryable()); // Организация - создание корзины Cart cart = new Cart(); // Организация - создание контроллера CartController controller = new CartController(mock.Object, null); // Действие - добавить игру в корзину controller.AddToCart(cart, 1, null); // Утверждение Assert.AreEqual(cart.Lines.Count(), 1); Assert.AreEqual(cart.Lines.ToList()[0].Item.Id, 1); }
public void Adding_Product_Goes_To_Cart_Screen() { //Arrange Mock <IProductsRepository> mock = new Mock <IProductsRepository>(); mock.Setup(m => m.Product).Returns(new Product[] { new Product { ProductID = 1, Price = 100, Name = "Carot" }, new Product { ProductID = 2, Price = 10, Name = "Carot2" }, new Product { ProductID = 3, Price = 10, Name = "Carot3" } }.AsQueryable()); Cart cart = new Cart(); CartController target = new CartController(mock.Object, null); //Act RedirectToRouteResult result = target.AddToCart(cart, 2, "myUrl"); Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl"); }
public void Can_Add_To_Cart() { //Организация - создание имитированного хранилища Mock <IProductRepository> mock = new Mock <IProductRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product { ProductID = 1, Name = "P1", Category = "Apples" } }.AsQueryable()); //Организация - создание эксемпляра Cart Cart cart = new Cart(); //Организация - создание контроллера CartController target = new CartController(mock.Object, null); //Действие - добавление товара в корзину target.AddToCart(cart, 1, null); //Утверждение Assert.AreEqual(cart.Lines.Count(), 1); Assert.AreEqual(cart.Lines.ToArray()[0].Product.ProductID, 1); }
public void Adding_Product_To_Cart_Goes_To_Cart_Screen() { //Организация - создание имитированного хранилища Mock <IProductRepository> mock = new Mock <IProductRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product { ProductID = 1, Name = "P1", Category = "Apples" }, }.AsQueryable()); //Организация - создание экземпляра Cart Cart cart = new Cart(); //Организация - создание контроллера CartController target = new CartController(mock.Object, null); //Действие - добавление товара в корзину RedirectToRouteResult result = target.AddToCart(cart, 2, "myUrl"); //Утверждение Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl"); }
public void Adding_Book_To_Cart_Goes_To_Cart_Screen() { //Arrange Mock <IBookRepository> mock = new Mock <IBookRepository>(); mock.Setup(m => m.Books).Returns(new Book[] { new Book { ISBN = 1, Title = "ASP.NET MVC", Specialization = "Programming" } }.AsQueryable() ); Cart cart = new Cart(); CartController target = new CartController(mock.Object, null); //Act RedirectToRouteResult result = target.AddToCart(cart, 2, "myUrl"); //Assert Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl"); }
public void AddToCart_Adds_CartLine() { //arrange Mock <IBusinessLogicLayer> mockOfBusinessLogicLayer = new Mock <IBusinessLogicLayer>(); Mock <IUserLayer> mockOfUserLayer = new Mock <IUserLayer>(); Mock <ControllerContext> mockOfControllerContext = new Mock <ControllerContext>(); mockOfControllerContext.SetupGet(m => m.HttpContext.Session["cartViewModel"]).Returns(new CartViewModel(mockOfBusinessLogicLayer.Object) { UserId = "firstUserId", UserIsBlocked = true, CartLineViewModels = new List <CartLineViewModel>() }); mockOfBusinessLogicLayer.Setup(m => m.Products).Returns(new List <Product> { new Product { ProductId = 1, Price = 50m } }); CartController target = new CartController(mockOfBusinessLogicLayer.Object, mockOfUserLayer.Object); target.ControllerContext = mockOfControllerContext.Object; //act CartViewModel result = (CartViewModel)target.AddToCart(1, 5).Model; //assert Assert.IsInstanceOfType(result, typeof(CartViewModel)); Assert.AreEqual("firstUserId", result.UserId); Assert.AreEqual(250m, result.TotalPrice); }
public void AddToCartTest_01() { // Arrange - create the mock repository Mock <IProductsRepository> mock = new Mock <IProductsRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product { ProductId = 1, Title = "P1", CategoryId = "Apples" }, }.AsQueryable()); // Arrange - create a mock order processor Mock <IOrderProcessor> mockOrderProcessor = new Mock <IOrderProcessor>(); // Arrange - create a Cart Cart cart = new Cart(); // Arrange - create the controller CartController target = new CartController(mock.Object, mockOrderProcessor.Object); // Act - add a product to the cart RedirectToRouteResult result = target.AddToCart(cart, 2, "myUrl"); // Assert Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl"); }
public void Can_Add_Product_To_Cart() { // Arrange: Set up a mock repository with two products var mockProductsRepos = new Moq.Mock <IProductsRepository>(); var products = new System.Collections.Generic.List <Product> { new Product { ProductID = 14, Name = "Much Ado About Nothing" }, new Product { ProductID = 27, Name = "The Comedy of Errors" }, }; mockProductsRepos.Setup(x => x.Products).Returns(products.AsQueryable()); var cart = new Cart(); var controller = new CartController(mockProductsRepos.Object, null, null); // Act: Try adding a product to the cart RedirectToRouteResult result = controller.AddToCart(cart, 27, "someReturnUrl"); // Assert Assert.AreEqual(1, cart.Lines.Count); Assert.AreEqual("The Comedy of Errors", cart.Lines[0].Product.Name); Assert.AreEqual(1, cart.Lines[0].Quantity); // Check that the visitor was redirected to the cart display screen Assert.AreEqual("Index", result.RouteValues["action"]); Assert.AreEqual("someReturnUrl", result.RouteValues["returnUrl"]); }
public void Adding_Game_To_Cart_Goes_To_Cart_Screen() { // Организация - создание имитированного хранилища Mock <IShopRepository> mock = new Mock <IShopRepository>(); mock.Setup(m => m.Products).Returns(new List <Product> { new Product() { Id = 1, Name = "Игра1", Category = "Кат1" }, }.AsQueryable()); // Организация - создание корзины Cart cart = new Cart(); // Организация - создание контроллера CartController controller = new CartController(mock.Object, null); // Действие - добавить игру в корзину RedirectToRouteResult result = controller.AddToCart(cart, 2, "myUrl"); // Утверждение Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl"); }
public void Adding_Book_To_Cart_Goes_To_Cart_Screen() { //arrange Mock <IBookRepository> mock = new Mock <IBookRepository>(); mock.Setup(m => m.Books).Returns( new Book[] { new Book { ISBN = 1, Title = "Asp.net", Specialization = "programming" }, //new Book { ISBN = 2, Title = "oracle" }, //new Book { ISBN = 3, Title = "C#" } //kabl l3amlyat el est3lam }.AsQueryable() ); Cart cart = new Cart(); CartController target = new CartController(mock.Object, null); //act //target.AddToCart(cart, 1, null); RedirectToRouteResult result = target.AddToCart(cart, 2, "myUrl"); //assert // Assert.AreEqual(cart.Lines.Count(), 1); //Assert.AreEqual(cart.Lines.ToArray()[0].Book.Title, "Asp.net"); Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl"); }
public void AddAgain() { Mock <IProductRepository> repository = new Mock <IProductRepository>(); repository.Setup(m => m.Products).Returns(new Product[] { new Product { Name = "P1", ProductID = 1, Category = "Apples" } }.AsQueryable() ); // Create a new cart. Cart cart = new Cart(); // Create controller. CartController controller = new CartController(repository.Object); // Add item to cart. controller.AddToCart(cart, 1, null); Assert.AreEqual(cart.Lines.Count(), 1); Assert.AreEqual(cart.Lines.ElementAt(0).Product.ProductID, 1); Assert.AreEqual(cart.Lines.ElementAt(0).Product.Name, "P1"); Assert.AreEqual(cart.Lines.ElementAt(0).Product.Category, "Apples"); }
public void Can_Generete_Specific_Book() { Mock <IBookRepository> mock = new Mock <IBookRepository>(); mock.Setup(m => m.Books).Returns(new List <Book> { new Book { BookID = 1, Name = "Book1", Genre = "Genre1" }, new Book { BookID = 2, Name = "Book2", Genre = "Genre2" }, new Book { BookID = 3, Name = "Book3", Genre = "Genre1" }, new Book { BookID = 4, Name = "Book4", Genre = "Genre3" }, new Book { BookID = 5, Name = "Book5", Genre = "Genre2" }, }.AsQueryable()); CartController controller = new CartController(mock.Object, null); Cart cart = new Cart(); controller.AddToCart(cart, 1, null); Assert.AreEqual(cart.Lines.Count(), 1); Assert.AreEqual(cart.Lines.ToList()[0].Book.BookID, 1); }
public void CartScreen() { // Setup repo. Mock <IProductRepository> repository = new Mock <IProductRepository>(); repository.Setup(m => m.Products).Returns(new Product[] { new Product() { Name = "P1", ProductID = 1, Category = "Apples" } }.AsQueryable() ); // Setup cart and controller. Cart cart = new Cart(); CartController controller = new CartController(repository.Object); // call function to add to cart. RedirectToRouteResult result = controller.AddToCart(cart, 1, "myURL"); // Check result. Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["returnUrl"], "myURL"); }
public void AddToCart(Transform t) { SumOfCosts += t.GetComponent <ShopItemController>().Card.Price; CartController.AddToCart(this, t); RevalidateButtonsAndCosts(); }
public void Can_Add_To_Cart() { // Arrange - create the mock repository Mock <ICofeeRepository> mock = new Mock <ICofeeRepository>(); mock.Setup(m => m.Products).Returns(new Cofee[] { new Cofee { CofeeId = 1, Name = "Espresso", PriceCoeff = 2.0M, VolumeOptions = new VolumeOption[] { new VolumeOption { VolumeOptionId = 1, Size = 0.133M, Unit = new Unit { Name = "Litre" } } }, SugarOptions = new SugarOption[] { new SugarOption { SugarOptionId = 1, Size = 1, Price = 0, Unit = new Unit { Name = "Teaspoon" } } } } }.AsQueryable()); // Arrange - create a Cart Cart cart = new Cart(); // Arrange - create the controller CartController target = new CartController(mock.Object, null); // Act - add a product to the cart target.AddToCart(cart, 1, 1, 1, true); // Assert Assert.AreEqual(cart.Lines.Count(), 1); Assert.AreEqual(cart.Lines.ToArray()[0].Recipe.CofeeId, 1); }
public void Adding_Product_To_Cart_Goes_To_Cart_Screen() { // Arrange Mock <IProductRepository> mock = new Mock <IProductRepository>(); mock.Setup(m => m.Products).Returns(new[] { new Product { ProductID = 1, Name = "P1", Category = "Apples" }, new Product { ProductID = 2, Name = "P2", Category = "Oranges" }, }.AsQueryable()); Cart cart = new Cart(); CartController controller = new CartController(mock.Object, null); // Act RedirectToRouteResult result = controller.AddToCart(cart, 3, "myUrl"); // Assert Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl"); }
public void Adding_Product_To_Cart_Goes_To_Cart_Screen() { // Arrange - create the mock repository Mock <ICofeeRepository> mock = new Mock <ICofeeRepository>(); mock.Setup(m => m.Products).Returns(new Cofee[] { new Cofee { CofeeId = 1, Name = "Espresso", PriceCoeff = 2.0M, VolumeOptions = new VolumeOption[] { new VolumeOption { VolumeOptionId = 1, Size = 0.133M, Unit = new Unit { Name = "Litre" } } }, SugarOptions = new SugarOption[] { new SugarOption { SugarOptionId = 1, Size = 1, Price = 0, Unit = new Unit { Name = "Not avaible" } } } } }.AsQueryable()); // Arrange - create a Cart Cart cart = new Cart(); // Arrange - create the controller CartController target = new CartController(mock.Object, null); // Act - add a product to the cart RedirectToRouteResult result = target.AddToCart(cart, 2, 1, 1, true); // Assert Assert.AreEqual(result.RouteValues["action"], "Index"); }
public void Adding_Product_To_Cart_Goes_Cart_Screen() { // 准备-创建模仿存储库 Mock <IProductsRepository> mock = new Mock <IProductsRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product { ProductID = 1, Name = "P1", Category = "Apples" } }.AsQueryable()); // 准备-创建新购物车 Cart cart = new Cart(); // 准备-创建控制器 CartController target = new CartController(mock.Object, null); // 动作-向cart添加一个产品 RedirectToRouteResult result = target.AddToCart(cart, 2, "myUrl"); // 断言 Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl"); }
public void Can_Add_To_Cart() { //Arrange Mock <IBookRepository> mock = new Mock <IBookRepository>(); mock.Setup(m => m.Books).Returns( new Book[] { new Book { ISBN = 1, Title = "ASP.NET", Specialization = "Programming" } }.AsQueryable() ); Cart cart = new Cart(); CartController target = new CartController(mock.Object, null); //Act target.AddToCart(cart, 1, null); // RedirectToRouteResult result = target.AddToCart(cart, 2, "myUrl"); //Assert Assert.AreEqual(cart.Lines.Count(), 1); Assert.AreEqual(cart.Lines.ToArray()[0].Book.Title, "ASP.NET"); // Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl"); }
public void Can_Add_To_Cart() { // Arrange Mock <IGameRepository> mock = new Mock <IGameRepository>(); mock.Setup(m => m.Games).Returns(new List <Game> { new Game { GameId = 1, Name = "G-1", Category = "Cat-1" } }.AsQueryable()); Cart cart = new Cart(); CartController controller = new CartController(mock.Object, null); // Act controller.AddToCart(cart, 1, null); // Assert Assert.AreEqual(1, cart.Lines.Count()); Assert.AreEqual(1, cart.Lines.ToList()[0].Game.GameId); }
public void AddToCart_CanAddToCart_And_SuccessfullyRedirectsToIndexWithReturningExpectedUrl() { // Arrange var expectedReturnUrl = "expected/url"; var product = new Product { Id = 1, Name = "P1", Category = "Apples" }; var mock = new Mock <IProductRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { product }); mock.Setup(m => m.GetProductById(1)).Returns(product); var cart = new Cart(); var controller = new CartController(mock.Object, null); // Act var actualResult = controller.AddToCart(cart, 1, expectedReturnUrl); // Assert Assert.IsTrue( cart.GetCartLinesCount() == 1 && cart.GetCartLines().ElementAt(0).Product.Id == product.Id && (string)actualResult.RouteValues["action"] == "Index" && (string)actualResult.RouteValues["returnUrl"] == expectedReturnUrl ); }
public void Adding_Product_To_Cart_Goes_To_Cart_Screen() { // Arrange - create the mock repository Mock <IProductRepository> mock = new Mock <IProductRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product { ProductID = 1, Name = "P1", Category = "Apples" }, }.AsQueryable()); // Arrange - create a Cart Cart cart = new Cart(); // Arrange - create the controller CartController target = new CartController(mock.Object, null); // Act - add a product to the cart RedirectToRouteResult result = target.AddToCart(cart, 2, "myUrl"); // Assert Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl"); }
public void CAN_Add_To_Cart() { Mock <IProductsRepository> mock = new Mock <IProductsRepository>(); mock.Setup(m => m.Product).Returns(new Product[] { new Product { ProductID = 1, Price = 100, Name = "Carot" }, new Product { ProductID = 2, Price = 10, Name = "Carot2" }, new Product { ProductID = 3, Price = 10, Name = "Carot3" } }.AsQueryable()); Cart cart = new Cart(); CartController target = new CartController(mock.Object, null); target.AddToCart(cart, 3, null); Assert.AreEqual(cart.Lines.Count(), 1); Assert.AreEqual(cart.Lines.ToArray()[0].Product.ProductID, 3); }
public void CanAddToCart() { //Tworzenie imitacji Mock <IProductRepository> mock = new Mock <IProductRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product { ProductID = 1, Name = "P1", Category = "Ubrania" }, }.AsQueryable()); //Utworzenie koszyka Cart cart = new Cart(); cart.AddItem(new Product(), 1); //Utworzenie kontrolera CartController target = new CartController(mock.Object, null); //Działanie - zakończenie zamówienia ViewResult result = target.Checkout(cart, new ShippingDetails()); //Dodanie produktu do koszyka target.AddToCart(cart, 1, null); //Asercje Assert.AreEqual(cart.Lines.Count(), 1); Assert.AreEqual(cart.Lines.ToArray()[0].Product.ProductID, 1); }
public void Adding_Product_To_Cart_Goes_To_Cart_Screen() { // Arrange - create the mock repository Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product {ProductID = 1, Name = "P1", Category = "Apples"}, }.AsQueryable()); // Arrange - create a Cart Cart cart = new Cart(); // Arrange - create the controller CartController target = new CartController(mock.Object, null); // Act - add a product to the cart RedirectToRouteResult result = target.AddToCart(cart, 2, "myUrl"); // Assert Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl"); }
public void Can_Add_To_Cart() { // Arrange - create the mock repository Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product {ProductID = 1, Name = "P1", Category = "Apples"}, }.AsQueryable()); // Arrange - create a Cart Cart cart = new Cart(); // Arrange - create the controller CartController target = new CartController(mock.Object, null); // Act - add a product to the cart target.AddToCart(cart, 1, null); // Assert Assert.AreEqual(cart.Lines.Count(), 1); Assert.AreEqual(cart.Lines.ToArray()[0].Product.ProductID, 1); }