예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string  name       = txtName.Text;
            var     categoryId = GetCategoryId();
            string  descript   = txtDescript.Text;
            decimal price      = (txtPrice.Text == "")? 0 : decimal.Parse(txtPrice.Text);

            byte[] img = null;

            if (!string.IsNullOrEmpty(fileImg))
            {
                img = ImageStatic.ConvertImg2Binary(pictureBox1.BackgroundImage);
            }

            var drink = new DrinkDto
            {
                Name            = name,
                DrinkCategoryId = categoryId,
                Descript        = descript,
                Price           = price,
                Img             = img,
                Status          = true
            };

            drinkController.Create(drink);

            MessageBox.Show("You added drink successfully", "Notification");
            loadTable();
        }
예제 #4
0
 public Drink CreateDrink(Drink drink)
 {
     return(drinkController.Create(drink));
 }
예제 #5
0
        private void FillDataToTheDataBase()
        {
            #region Make bar
            BarController     bc      = new BarController();
            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    = "******"
            };
            this.bar = bc.Create(bar, m.Id, "TestPassword");
            #endregion

            IngredientController ingredientController = new IngredientController();

            List <Drink> drinks = new List <Drink>();


            Ingredient vodka = new Ingredient
            {
                Name       = "TestVodka",
                Measurable = true,
                Alch       = 37.5
            };

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

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


            quantifiedIngredientVodka = new QuantifiedIngredient
            {
                Quantity    = 6,
                Ingredient  = ingredientController.Find("TestVodka").First(), //We would like it to throw an exception here, as it's a test
                Measurement = ingredientController.FindMeasurement("cl")
            };

            quantifiedIngredientJuice = new QuantifiedIngredient
            {
                Quantity    = 2,
                Ingredient  = ingredientController.Find("TestJuice").First(), //We would like it to throw an exception here, as it's a test
                Measurement = ingredientController.FindMeasurement("cl")
            };

            Drink drinkVodkaJuice = new Drink
            {
                Recipe = "TestVodkaJuiceRecipe",
                Names  = new List <string>()
                {
                    "TestName1", "TestName2"
                },
                Ingredients = new List <QuantifiedIngredient>()
                {
                    quantifiedIngredientJuice, quantifiedIngredientVodka
                }
            };

            Drink drinkVodka = new Drink
            {
                Recipe = "TestVodkaRecipe",
                Names  = new List <string>()
                {
                    "TestNameVodka"
                },
                Ingredients = new List <QuantifiedIngredient>()
                {
                    quantifiedIngredientVodka
                }
            };

            Drink drinkJuice = new Drink
            {
                Recipe = "TestJuiceRecipe",
                Id     = 3,
                Names  = new List <string>()
                {
                    "TestJuice", "TestAppelsinjuice"
                },
                Ingredients = new List <QuantifiedIngredient>()
                {
                    quantifiedIngredientJuice
                }
            };

            TestVodka      = controller.Create(drinkVodka);
            TestJuice      = controller.Create(drinkJuice);
            TestVodkaJuice = controller.Create(drinkVodkaJuice);
        }