示例#1
0
        public void Post_Create_Model_Is_Not_Valid()
        {
            // Arrange
            var drinkViewModel = new DrinkViewModel()
            {
                //Name = "Mirinda", // required field
                Price = 5.00M,
                //Capacity = 0.5f // required field
            };
            var repository = Substitute.For <IDrinkRepository>();
            var mapper     = Substitute.For <IMapper>();
            var controller = new DrinkController(repository, mapper);
            var validator  = new ModelValidator <DrinkViewModel>(drinkViewModel);

            // Act
            var valid = validator.IsValid();

            validator.AddToModelError(controller);
            var result     = controller.Create(drinkViewModel) as RedirectToRouteResult;
            var actionName = result.RouteValues.Values.ElementAt(0);
            var tempData   = controller.TempData["ModelIsNotValid"];

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That("Wystąpił błąd w formularzu, spróbuj ponownie.", Is.EqualTo(tempData));
            Assert.That("Index", Is.EqualTo(actionName));
            Assert.That(valid, Is.False);
        }
示例#2
0
        public void GetDrinkById_Gives_Drink_By_Id()
        {
            var data = new List <Drink>()
            {
                new Drink {
                    Id = 1, Name = "Drink1"
                },
                new Drink {
                    Id = 2, Name = "Drink2"
                },
                new Drink {
                    Id = 3, Name = "Drink3"
                },
            }.AsQueryable();

            var mockSet = new Mock <DbSet <Drink> >();

            mockSet.As <IQueryable <Drink> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <Drink> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <Drink> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <Drink> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var mockContext = new Mock <ShopContext>();

            mockContext.Setup(c => c.Drinks).Returns(mockSet.Object);

            var controller = new DrinkController(mockContext.Object);

            var drink = controller.GetDrinkById(1);

            Assert.AreEqual(1, drink.Id);
        }
示例#3
0
        public void RemoveDrink_Remove_A_Drink()
        {
            var data = new List <Drink>()
            {
                new Drink {
                    Id = 1, Name = "Drink1"
                },
                new Drink {
                    Id = 2, Name = "Drink2"
                },
                new Drink {
                    Id = 3, Name = "Drink3"
                },
            }.AsQueryable();

            var mockSet = new Mock <DbSet <Drink> >();

            mockSet.As <IQueryable <Drink> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <Drink> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <Drink> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <Drink> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var mockContext = new Mock <ShopContext>();

            mockContext.Setup(x => x.Drinks).Returns(mockSet.Object);

            var service = new DrinkController(mockContext.Object);
            var drinks  = service.GetAllDrinks();

            int deletedDrinkId = 1; service.Delete(drinks[0].Id);

            Assert.IsNull(service.GetAllDrinks().FirstOrDefault(x => x.Id == deletedDrinkId));
        }
示例#4
0
        public void GetAllDrinks_Gives_All_Drinks()
        {
            var data = new List <Drink>
            {
                new Drink {
                    Name = "First"
                },
                new Drink {
                    Name = "Second"
                },
                new Drink {
                    Name = "Third"
                },
            }.AsQueryable();

            var mockSet = new Mock <DbSet <Drink> >();

            mockSet.As <IQueryable <Drink> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <Drink> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <Drink> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <Drink> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var mockContext = new Mock <ShopContext>();

            mockContext.Setup(c => c.Drinks).Returns(mockSet.Object);

            var controller = new DrinkController(mockContext.Object);
            var Drinks     = controller.GetAllDrinks();

            Assert.AreEqual(3, Drinks.Count);
            Assert.AreEqual("First", Drinks[0].Name);
            Assert.AreEqual("Second", Drinks[1].Name);
            Assert.AreEqual("Third", Drinks[2].Name);
        }
示例#5
0
        public void Delete_Not_Ajax_Request()
        {
            // Arrange
            var drink = new Drink()
            {
                ID       = 1,
                Name     = "Mirinda",
                Price    = 5.00M,
                Capacity = 0.5f
            };
            var id         = 1;
            var repository = Substitute.For <IDrinkRepository>();
            var mapper     = Substitute.For <IMapper>();

            var fakeController = new FakeController();

            fakeController.PrepareFakeRequest();
            var controller = new DrinkController(repository, mapper);

            controller.ControllerContext = fakeController.GetControllerContext <DrinkController>(new RouteData(), controller);

            repository.Get(id).Returns(drink);

            // Act
            var result      = controller.Delete(id) as RedirectToRouteResult;
            var ajaxRequest = controller.Request.IsAjaxRequest();
            var actionName  = result.RouteValues.Values.ElementAt(0);

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That(ajaxRequest, Is.False);
            Assert.That("Index", Is.EqualTo(actionName));
        }
示例#6
0
        public void Post_Edit_Drink_Is_Null()
        {
            // Arrange
            Drink drink          = null;
            var   drinkViewModel = new DrinkViewModel()
            {
                ID       = -1,
                Name     = "Mirinda",
                Price    = 5.00M,
                Capacity = 0.5f
            };
            var id         = drinkViewModel.ID;
            var repository = Substitute.For <IDrinkRepository>();
            var mapper     = Substitute.For <IMapper>();
            var validator  = new ModelValidator <DrinkViewModel>(drinkViewModel);
            var controller = new DrinkController(repository, mapper);

            repository.Get(id).Returns(drink);

            // Act
            var result     = controller.Edit(drinkViewModel) as HttpNotFoundResult;
            var statusCode = result.StatusCode;
            var valid      = validator.IsValid();

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That(404, Is.EqualTo(statusCode));
            Assert.That(valid, Is.True);
        }
示例#7
0
        public void Post_Edit_Not_Valid()
        {
            // Arrange
            var drinkViewModel = new DrinkViewModel()
            {
                ID = 1,
                //Name = "Mirinda",
                Price = 5.00M,
                //Capacity = 0.5f
            };
            var repository = Substitute.For <IDrinkRepository>();
            var mapper     = Substitute.For <IMapper>();
            var controller = new DrinkController(repository, mapper);
            var validator  = new ModelValidator <DrinkViewModel>(drinkViewModel);

            // Act
            var valid = validator.IsValid();

            validator.AddToModelError(controller);
            var result   = controller.Edit(drinkViewModel) as ViewResult;
            var viewName = result.ViewName;
            var tempData = controller.TempData["ModelIsNotValid"];

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That(valid, Is.False);
            Assert.That("Index", Is.EqualTo(viewName));
            Assert.That("Wystąpił błąd w formularzu, spróbuj ponownie.", Is.EqualTo(tempData));
        }
示例#8
0
        public void FindAllAvailableDrinks()
        {
            //setup
            FillDataToTheDataBase();

            DrinkController dc = new DrinkController();
            BarController   bc = new BarController();

            bc.AddStockToBar(bar, new Stock()
            {
                Ingredient = TestVodkaIngre, Quantity = 100
            });


            //Act
            List <DrinkViewModel> found = controller.FindAllAvailableDrinks(bar).Values.ToList();

            //assert
            Assert.AreEqual(found.Count, 1);

            //Setup 2
            bc.AddStockToBar(bar, new Stock()
            {
                Ingredient = TestJuiceIngre, Quantity = 100
            });

            //Act 2
            List <DrinkViewModel> found2 = controller.FindAllAvailableDrinks(bar).Values.ToList();

            //assert 2
            Assert.AreEqual(found2.Count, 3);
        }
示例#9
0
        public void Post_Create_Model_Is_Valid()
        {
            // Arrange
            var drink = new Drink()
            {
                Name     = "Mirinda",
                Price    = 5.00M,
                Capacity = 0.5f
            };
            var drinkViewModel = new DrinkViewModel()
            {
                Name     = "Mirinda",
                Price    = 5.00M,
                Capacity = 0.5f
            };
            var repository = Substitute.For <IDrinkRepository>();
            var mapper     = Substitute.For <IMapper>();
            var controller = new DrinkController(repository, mapper);
            var validator  = new ModelValidator <DrinkViewModel>(drinkViewModel);

            mapper.Map <DrinkViewModel, Drink>(drinkViewModel).Returns(drink);
            repository.Insert(drink);
            repository.Save();

            // Act
            var valid      = validator.IsValid();
            var result     = controller.Create(drinkViewModel) as RedirectToRouteResult;
            var actionName = result.RouteValues.Values.ElementAt(0); //only action name

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That("Index", Is.EqualTo(actionName));
            Assert.That(valid, Is.True);
        }
示例#10
0
 /// <summary>
 /// Initialize controllers.
 /// </summary>
 public Display()
 {
     drinkController             = new DrinkController(new ShopContext());
     nutController               = new NutController(new ShopContext());
     fruitAndVegetableController = new FruitAndVegetableController(new ShopContext());
     pastryController            = new PastryController(new ShopContext());
     animalProductController     = new AnimalProductController(new ShopContext());
     HandleInput();
 }
        static void Main(string[] args)
        {
            DrinkController dc = new DrinkController();

            while (true)
            {
                dc.UserInput();
            }
        }
示例#12
0
        private void loadDrinks(int?drinkCategoryId, string searchString, decimal?priceFrom, decimal?priceTo, bool?status)
        {
            if (drinkController == null)
            {
                drinkController = new DrinkController();
            }

            tblDrink.DataSource = drinkController.Gets(drinkCategoryId, searchString, priceFrom, priceTo, status).ToList();
            dataGridView1.Columns["Img"].Visible = false;
        }
示例#13
0
 public void CleanUp()
 {
     controller                = new DrinkController();
     TestVodka                 = null;
     TestJuice                 = null;
     TestVodkaJuice            = null;
     TestVodkaIngre            = null;
     TestJuiceIngre            = null;
     bar                       = null;
     quantifiedIngredientVodka = null;
     quantifiedIngredientJuice = null;
     TestHelper.DeleteAllInDB();
 }
示例#14
0
        private void loadflp(int?category, string searchString)
        {
            if (drinkController == null)
            {
                drinkController = new DrinkController();
            }

            var drinks = drinkController.Gets(category, searchString, null, null, true);

            foreach (var d in drinks)
            {
                Create_pnl(d);
            }
        }
示例#15
0
        public void AddDrink_Add_A_Drink()
        {
            var mockSet     = new Mock <DbSet <Drink> >();
            var drink       = new Drink();
            var mockContext = new Mock <ShopContext>();

            mockContext.Setup(m => m.Drinks).Returns(mockSet.Object);

            var controller = new DrinkController(mockContext.Object);

            controller.Add(drink);

            mockSet.Verify(m => m.Add(It.IsAny <Drink>()), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
示例#16
0
        public void CreatePartial()
        {
            // Arrange
            var repository = Substitute.For <IDrinkRepository>();
            var mapper     = Substitute.For <IMapper>();
            var controller = new DrinkController(repository, mapper);

            // Act
            var result   = controller.CreatePartial() as PartialViewResult;
            var viewName = result.ViewName;

            //Assert
            Assert.That(result, !Is.Null);
            Assert.That("_CreatePartial", Is.EqualTo(viewName));
        }
示例#17
0
        public void Get_Edit_Id_Is_Null()
        {
            // Arrange
            int?id         = null;
            var repository = Substitute.For <IDrinkRepository>();
            var mapper     = Substitute.For <IMapper>();
            var controller = new DrinkController(repository, mapper);

            // Act
            var result     = controller.Edit(id) as HttpStatusCodeResult;
            var statusCode = result.StatusCode;

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That(400, Is.EqualTo(statusCode));
        }
示例#18
0
        public void Index()
        {
            // Arrange
            var drinks = new List <Drink>()
            {
                new Drink()
                {
                    Name = "Mirinda", Price = 5.00M, Capacity = 0.5f
                },
                new Drink()
                {
                    Name = "7Up", Price = 5.00M, Capacity = 0.5f
                },
                new Drink()
                {
                    Name = "Woda gazowana", Price = 3.00M, Capacity = 0.5f
                },
                new Drink()
                {
                    Name = "Woda niegazowana", Price = 3.00M, Capacity = 0.5f
                },
                new Drink()
                {
                    Name = "Sok pomarańczowy", Price = 4.00M, Capacity = 0.33f
                }
            };
            var repository = Substitute.For <IDrinkRepository>();
            var mapper     = Substitute.For <IMapper>();
            var controller = new DrinkController(repository, mapper);

            controller.TempData["ModelIsNotValid"] = "Fake content.";
            controller.ViewBag.ModelIsNotValid     = controller.TempData["ModelIsNotValid"];
            repository.GetAll().Returns(drinks);

            // Act
            var result   = controller.Index() as ViewResult;
            var viewName = result.ViewName;
            var model    = result.Model as List <Drink>;
            var viewBag  = controller.ViewBag.ModelIsNotValid;

            // Assert
            Assert.That("Fake content.", Is.EqualTo(viewBag));
            Assert.That("Index", Is.EqualTo(viewName));
            Assert.IsNotNull(model);
            Assert.That(5, Is.EqualTo(model.Count));
        }
示例#19
0
        public void ドリンクを指定本数格納できるかテスト(int num)
        {
            var target = new DrinkController();

            //ドリンクを追加
            var cola = this.SetDorink(120, "コーラ");

            for (var i = 0; i < num; i++)
            {
                target.Add(cola);
            }


            //5本格納しているか
            var expectNum = num;
            var actualNum = target.Count();

            Assert.AreEqual(expectNum, actualNum);
        }
示例#20
0
        public void Get_Edit_Drink_Is_Null()
        {
            // Arrange
            Drink drink      = null;
            var   id         = 0;
            var   repository = Substitute.For <IDrinkRepository>();
            var   mapper     = Substitute.For <IMapper>();
            var   controller = new DrinkController(repository, mapper);

            repository.Get(id).Returns(drink);

            // Act
            var result     = controller.Edit(id) as HttpNotFoundResult;
            var statusCode = result.StatusCode;

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That(404, Is.EqualTo(statusCode));
        }
示例#21
0
        public void Good_Get_Edit()
        {
            // Arrange
            var drink = new Drink()
            {
                ID       = 1,
                Name     = "Mirinda",
                Price    = 5.00M,
                Capacity = 0.5f
            };
            var drinkViewModel = new DrinkViewModel()
            {
                Name     = "Mirinda",
                Price    = 5.00M,
                Capacity = 0.5f
            };
            var id         = 1;
            var repository = Substitute.For <IDrinkRepository>();
            var mapper     = Substitute.For <IMapper>();

            var fakeController = new FakeController();

            fakeController.PrepareFakeAjaxRequest();
            var controller = new DrinkController(repository, mapper);

            controller.ControllerContext = fakeController.GetControllerContext <DrinkController>(new RouteData(), controller);

            repository.Get(id).Returns(drink);
            mapper.Map <Drink, DrinkViewModel>(drink).Returns(drinkViewModel);

            // Act
            var result      = controller.Edit(id) as PartialViewResult;
            var viewName    = result.ViewName;
            var model       = result.Model;
            var ajaxRequest = controller.Request.IsAjaxRequest();

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That("_EditPartial", Is.EqualTo(viewName));
            Assert.That(model, !Is.Null);
            Assert.That(ajaxRequest, Is.True);
        }
示例#22
0
        public void TestFindDrinkPrice()
        {
            FillDataToTheDataBase();
            //setup

            DrinkController dc = new DrinkController();
            BarController   bc = new BarController();


            bc.AddStockToBar(bar, new Stock()
            {
                Ingredient = TestVodkaIngre, Quantity = 100
            });
            bc.AddStockToBar(bar, new Stock()
            {
                Ingredient = TestJuiceIngre, Quantity = 100
            });
            int vodkaSellingPrice = 50;
            int juiceSellingPrice = 10;

            controller.InsertDrinkPrice(bar, new Price()
            {
                BuyingPrice = 10, SellingPrice = vodkaSellingPrice, Ingredient = TestVodkaIngre
            });
            controller.InsertDrinkPrice(bar, new Price()
            {
                BuyingPrice = 2, SellingPrice = juiceSellingPrice, Ingredient = TestJuiceIngre
            });

            //act
            double priceForVodkaJuice        = controller.FindDrinkPriceById(TestVodkaJuice.Id, bar.ID);
            double ActualPriceVodkaJuice     = 0;
            QuantifiedIngredient QIngreVodka = TestVodkaJuice.Ingredients.Where(e => e.Ingredient.Id == TestVodkaIngre.Id).First();
            QuantifiedIngredient QIngreJuice = TestVodkaJuice.Ingredients.Where(e => e.Ingredient.Id == TestJuiceIngre.Id).First();

            ActualPriceVodkaJuice += vodkaSellingPrice * QIngreVodka.Quantity;
            ActualPriceVodkaJuice += juiceSellingPrice * QIngreJuice.Quantity;

            //Assert
            Assert.AreEqual(ActualPriceVodkaJuice, priceForVodkaJuice);
        }
示例#23
0
        public void 格納したドリンクが全て指定銘柄かテスト(string name)
        {
            var target = new DrinkController();


            //ドリンクを追加
            var cola = this.SetDorink(120, name);

            for (var i = 0; i < 5; i++)
            {
                target.Add(cola);
            }

            var expected = name;

            var allList = target.AllList();

            foreach (var n in allList)
            {
                var actual = n.Name();
                Assert.AreEqual(expected, actual);
            }
        }
示例#24
0
        public void 格納したドリンクが全て指定金額かテスト(int price)
        {
            var target = new DrinkController();


            //ドリンクを追加
            var cola = this.SetDorink(price, "コーラ");

            for (var i = 0; i < 5; i++)
            {
                target.Add(cola);
            }

            var expected = price;

            var allList = target.AllList();

            foreach (var n in allList)
            {
                var actual = n.Price();
                Assert.AreEqual(expected, actual);
            }
        }
示例#25
0
        public void Good_Delete()
        {
            // Arrange
            var drink = new Drink()
            {
                ID       = 1,
                Name     = "Mirinda",
                Price    = 5.00M,
                Capacity = 0.5f
            };
            var id         = 1;
            var repository = Substitute.For <IDrinkRepository>();
            var mapper     = Substitute.For <IMapper>();

            var fakeController = new FakeController();

            fakeController.PrepareFakeAjaxRequest();
            var controller = new DrinkController(repository, mapper);

            controller.ControllerContext = fakeController.GetControllerContext <DrinkController>(new RouteData(), controller);

            repository.Get(id).Returns(drink);
            repository.Delete(drink);
            repository.Save();

            // Act
            var result              = controller.Delete(id) as JsonResult;
            var ajaxRequest         = controller.Request.IsAjaxRequest();
            var jsonRequestBehavior = result.JsonRequestBehavior;
            var data = result.Data;

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That(ajaxRequest, Is.True);
            Assert.That(jsonRequestBehavior, Is.EqualTo(JsonRequestBehavior.AllowGet));
        }
示例#26
0
        public void Setup()
        {
            _drinkServiceMock = new Mock <IDrinkService>();

            _controller = new DrinkController(_drinkServiceMock.Object);
        }
 public void Initialize()
 {
     this.service    = new DrinkServiceMock();
     this.controller = new DrinkController(this.service);
 }
示例#28
0
 public DrinkService()
 {
     DrinkCtr = new DrinkController();
     aCtr     = new AlchoholController();
     hCtr     = new HelflaskController();
 }
示例#29
0
        public void barCreateStock()
        {
            IngredientController ingredientController = new IngredientController();
            DrinkController      drinkController      = new DrinkController();
            //setup
            Ingredient vodka = new Ingredient
            {
                Name       = "TestVodka",
                Measurable = true,
                Alch       = 37.5
            };

            Ingredient juice = new Ingredient
            {
                Name       = "TestJuice",
                Measurable = false,
                Alch       = 0
            };

            vodka = ingredientController.Create(vodka);
            juice = ingredientController.Create(juice);

            ManagerController mc      = new ManagerController();
            Manager           manager = new Manager("TestName", "TestPhonenumber", "TestEmail", "TestUsername", null);
            Manager           m       = mc.CreateManager(manager, "TestPassword");

            Country country = LocationDB.Instance.getCountryById(1);

            if (country is null)
            {
                Assert.Fail("Country is null");
            }
            Zipcode zip = LocationDB.Instance.findZipById(1);
            Address a   = new Address("TestVej", zip);

            zip.Country = country;
            a.Zipcode   = zip;
            Bar bar = new Bar
            {
                Address     = a,
                Email       = "TestBarEmail",
                Name        = "TestBarName",
                PhoneNumber = "TestBarP",
                Username    = "******"
            };
            Bar Createdbar = controller.Create(bar, m.Id, "TestPassword");

            ICollection <Measurement> measurements = new DrinkController().FindAllMeasurements();
            var allStocks          = controller.GetAllStocks(bar.ID);
            int precount           = allStocks.Count;
            int preVodkaStockCount = allStocks.Where(e => e.Ingredient.Equals(vodka)).Count();
            int preJuiceStockCount = allStocks.Where(e => e.Ingredient.Equals(juice)).Count();

            //act
            controller.CreateStock(Createdbar.ID, 20, vodka, measurements.FirstOrDefault().Id);

            preVodkaStockCount++;   //Just creted one vodka. so we increment
            precount++;             // Just created one more stock in the DB so we increment

            controller.CreateStock(Createdbar.ID, 20, juice, null);
            precount++;           //Just created one juice, so we increment
            preJuiceStockCount++; // Just craeted one juice so we increment

            List <Stock> stocksFound = controller.GetAllStocks(bar.ID);
            //assert
            bool success = (stocksFound.Where(e => e.Ingredient.Equals(vodka))).Count() == preVodkaStockCount &&
                           stocksFound.Count() == precount;


            Assert.IsTrue(success, "Stock measurable was not created successfully");
            int actual = stocksFound.Where(e => e.Ingredient.Equals(juice)).Count();


            success = (actual == preJuiceStockCount && stocksFound.Count() == precount);

            Assert.IsTrue(success, "Stock not mreasurable was not created successfully");
        }