public void Generate_Category_Specific_Laptop_Count() { /// Arrange var mock = new Mock <IGoodsService>(); mock.Setup(m => m.GetLaptopList()).Returns(GetLaptopList()); var controller = new GoodsController(mock.Object); controller.pageSize = 3; // Act var res1 = controller.GoodsList("Black"); var viewResult1 = Assert.IsType <ViewResult>(res1); var model1 = Assert.IsAssignableFrom <LaptopListViewModel>(viewResult1.Model).PagingInfo.TotalItems; var res2 = controller.GoodsList("White"); var viewResult2 = Assert.IsType <ViewResult>(res2); var model2 = Assert.IsAssignableFrom <LaptopListViewModel>(viewResult2.Model).PagingInfo.TotalItems; var res3 = controller.GoodsList("Gray"); var viewResult3 = Assert.IsType <ViewResult>(res3); var model3 = Assert.IsAssignableFrom <LaptopListViewModel>(viewResult3.Model).PagingInfo.TotalItems; var res4 = controller.GoodsList(null); var viewResult4 = Assert.IsType <ViewResult>(res4); var model4 = Assert.IsAssignableFrom <LaptopListViewModel>(viewResult4.Model).PagingInfo.TotalItems; // Assert Assert.Equal(3, model1); Assert.Equal(1, model2); Assert.Equal(1, model3); Assert.Equal(5, model4); }
public void GoodsController_ListByName() { TestControllerBuilder builder = new TestControllerBuilder(); // Arrange var mock = new Mock <IEshopRepository>(); mock.Setup(m => m.Goods) .Returns(new List <Goods> { new Goods() { Name = "ABCD", Category = new Category() }, new Goods() { Name = "XYZ", Category = new Category() }, new Goods() { Name = "KLMN", Category = new Category() } }); var expexted = new GoodsModel() { Goods = new List <Goods> { new Goods() { Name = "ABCD", Category = new Category() }, new Goods() { Name = "KLMN", Category = new Category() }, new Goods() { Name = "XYZ", Category = new Category() } }, Sort = new SortModel() { RevboolName = true } }; var controller = new GoodsController(mock.Object); builder.InitializeController(controller); // Action var result = controller.ListByName(expexted) as ViewResult; // Assert Assert.IsNotNull(result); }
private static void PrintBasket(Dictionary <string, int> currentBasket) { if (currentBasket.Count == 0) { Console.WriteLine("Seems like your order is already completed!\n"); return; } Console.WriteLine("Your current unfinished order:"); foreach (var item in currentBasket) { Console.WriteLine(GoodsController.GetBrand(item.Key) + " " + item.Value); } Console.WriteLine(); }
static string GetBrand(Items item, int choose) { int i = 1; foreach (var brand in GoodsController.GetBrands(item)) { if (i == choose) { return(brand); } i++; } throw new ArgumentException("Incorrect option."); }
public void CanFilterGoods() { // Arrange var mock = new Mock <IEshopRepository>(); mock.Setup(m => m.Goods).Returns(new List <Goods>() { new Goods() { Name = "Meizu M2 Note", Description = "Mobile Phone from Meizu", Category = new Category() { Name = "Mobile Phones" }, AvailableCount = 5, Price = 3000 }, new Goods() { Name = "Hp DV6-6158er", Category = new Category() { Name = "NoteBook" }, Description = "Awesome notebook, developed by HP", AvailableCount = 0, Price = 10000 } }); GoodsController controller = new GoodsController(mock.Object); GoodsModel model = new GoodsModel() { PriceLow = 2000, PriceHight = 3500 }; int expected = 1; // Action var result = controller.Filters(model).Count; // Assert Assert.AreEqual(expected, result); }
public void Can_Filter_Laptops() { // Arrange var mock = new Mock <IGoodsService>(); mock.Setup(m => m.GetLaptopList()).Returns(GetLaptopList()); var controller = new GoodsController(mock.Object); controller.pageSize = 3; // Action var result = controller.GoodsList("Black", 1); var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <LaptopListViewModel>(viewResult.Model).Laptops.ToList(); // Assert Assert.Equal(3, model.Count()); Assert.True(model[0].Name == "iPhone 7" && model[0].Color == "Black"); Assert.True(model[1].Name == "iPhone 8" && model[1].Color == "Black"); }
public void Search_Goods_IncorrectData_Test() { TestControllerBuilder builder = new TestControllerBuilder(); // Arrange var mock = new Mock <IEshopRepository>(); mock.Setup(m => m.Goods) .Returns(new List <Goods> { new Goods() { Name = "Just a name" }, new Goods() { Name = "just Anozer name" }, new Goods() { Name = "Wrong name" } }); int expected = 2; var controller = new GoodsController(mock.Object); builder.InitializeController(controller); var model = new GoodsModel() { Name = "Incorrect search querry" }; // Action ViewResult view = controller.Search(model) as ViewResult; int result = ((GoodsModel)view.Model).Goods.Count(); // Assert Assert.AreNotEqual(expected, result); }
public void ReverseToModel_Test() { // Arrange var mock = new Mock <IEshopRepository>(); GoodsController controller = new GoodsController(mock.Object); GoodsModel model = new GoodsModel() { Sort = new SortModel() { RevboolId = false } }; var expected = true; // Action controller.ReverseToModel(model, "Id"); var result = model.Sort.RevboolId; // Assert Assert.AreEqual(expected, result); }
public void Can_Paginate() { // Arrange var mock = new Mock <IGoodsService>(); mock.Setup(m => m.GetLaptopList()).Returns(GetLaptopList()); var controller = new GoodsController(mock.Object); controller.pageSize = 3; // Act var result = controller.GoodsList(null, 2); var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <LaptopListViewModel>(viewResult.Model); // Assert List <LaptopModel> laptops = model.Laptops.ToList(); Assert.True(laptops.Count == 2); Assert.Equal("iPhone 7", laptops[0].Name); Assert.Equal("iPhone 8", laptops[1].Name); }
public void Can_Send_Pagination_View_Model() { // Arrange var mock = new Mock <IGoodsService>(); mock.Setup(m => m.GetLaptopList()).Returns(GetLaptopList()); GoodsController controller = new GoodsController(mock.Object); controller.pageSize = 3; // Act var result = controller.GoodsList(null, 2); var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <LaptopListViewModel>(viewResult.Model); // Assert PagingInfo pageInfo = model.PagingInfo; Assert.Equal(2, pageInfo.CurrentPage); Assert.Equal(3, pageInfo.ItemsPerPage); Assert.Equal(5, pageInfo.TotalItems); Assert.Equal(2, pageInfo.TotalPages); }
public void Clicked商品データ() { GoodsController Controller = gameObject.transform.parent.parent.parent.parent.parent.Find("Controller").GetComponent <GoodsController>(); Controller.setGoodsData(Number.ToNumber(transform.name)); }
static void MakeOrder(OrderController orderController, Storage storage) { bool finished = false; while (!finished) { Console.Clear(); PrintBasket(orderController.CurrentBasket); Console.WriteLine($"1) Add more items."); Console.WriteLine($"2) Send order."); Console.WriteLine($"3) Exit from basket."); ChooseLimits(1, 3, "Your choose: ", out int choose); Console.WriteLine(); try { switch (choose) { case (1): bool chosen = false; while (!chosen) { try { var quantity = Enum.GetNames(typeof(Items)).Length; Console.Clear(); Console.WriteLine("What type of product you want?"); if (orderController.CurrentOrder.CurrentUser.Age > 18) { foreach (var item in (Items[])Enum.GetValues(typeof(Items))) { Console.WriteLine((int)item + ") " + item); } } else { foreach (var item in (Items[])Enum.GetValues(typeof(Items))) { if (item != Items.Wine) { Console.WriteLine(((int)item - 1) + ") " + item); } } } ChooseLimits(1, quantity, "Your chosen item: ", out int good); if (orderController.CurrentOrder.CurrentUser.Age < 18) { good++; } PrintBrands(GoodsController.GetBrands((Items)good)); ChooseLimits(1, GoodsController.GetAmount((Items)good), "Choose what you want: ", out int brand); ChooseLimits(1, 100, "Type amount (less than 100): ", out int amount); orderController.Add(GoodsController.CreateItem((Items)good, GetBrand((Items)good, brand)), amount); chosen = true; } catch (TypeInitializationException ex) { Console.WriteLine(ex.InnerException); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); Console.ResetColor(); Console.Write("Type any key to continue..."); Console.ReadKey(); } } break; case (2): orderController.FinishOrder(); if (storage.MakeOrder(orderController.CurrentOrder)) { Console.WriteLine("Your order is completed!"); } else { Console.WriteLine("You was added to the queue. Come back next day."); Console.WriteLine($"You are on {storage.GetQueuePosition(orderController.CurrentOrder.CurrentUser)} position in queue."); } orderController.CheckCurrentOrder(); finished = true; break; default: finished = true; break; } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); Console.ResetColor(); } } }
static void Main() { #region initializing all necessary objects GoodsController goodsController = new GoodsController(); Greetings(); var userController = new UserController(); var orderController = new OrderController(); var storage = new Storage(); var calendar = new Calendar(); ChangeUser(userController, orderController); calendar.NewDay += storage.GetItemsFromProvider; calendar.NewDay += storage.CheckOrders; calendar.NewDay += orderController.CheckOrders; #endregion while (true) { Console.Write("Type any key to move to the menu . . ."); Console.ReadKey(); Console.Clear(); Console.WriteLine("Day today: " + calendar.GetDayOfWeek() + "\n"); Menu(); ChooseLimits(1, 6, "Type your option: ", out int choose); Console.WriteLine(); switch (choose) { case (1): ChangeUser(userController, orderController); break; case (2): MakeOrder(orderController, storage); break; case (3): if (orderController.CurrentOrder.IsSent) { Console.WriteLine($"You are on {storage.GetQueuePosition(orderController.CurrentOrder.CurrentUser)} position in queue."); } else { Console.WriteLine("Unsent order."); } PrintBasket(orderController.CurrentOrder.Basket); break; case (4): PrintBasket(orderController.CurrentBasket); break; case (5): calendar.MoveOneDay(); break; case (6): return; } } }