Example #1
0
        public BeerType AddType(BeerType type)
        {
            ctx.Attach(type).State = EntityState.Added;
            ctx.SaveChanges();

            return(type);
        }
Example #2
0
        private static Beer InitBeer(string name, BeerType type, double abv, string brewery)
        {
            Beer beer = new Beer(name, type, abv, brewery);

            beers.Add(beer.Id, beer);
            return(beer);
        }
        public void Ctor_ShouldInitializePropertiesCorrectly()
        {
            var beer = new BeerType();

            Assert.IsNotNull(beer.Beers);
            Assert.IsInstanceOf <HashSet <Beer> >(beer.Beers);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,ModifiedOn,IsDeleted,DeletedOn")] BeerType beerType)
        {
            if (id != beerType.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (beerType.IsDeleted)
                    {
                        beerType.DeletedOn = DateTime.Now;
                    }
                    beerType.ModifiedOn = DateTime.Now;
                    _context.Update(beerType);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BeerTypeExists(beerType.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(beerType));
        }
Example #5
0
        [InlineData(1, "Beer", "Fra 1884!", 65, 50, 100, 14, int.MinValue, "image.png", "Stock must be a whole number above or equal to zero")]   // invalid stock: -2147483648

        public void AddBeer_InvalidBeer_ExceptArgumentException(int id, string name, string description, double price, double EBC, double IBU, double percentage, int stock, string imageURL, string expectedErrorMsg)
        {
            // arrange
            Brand brand = new Brand {
                ID = 1
            };
            BeerType type = new BeerType {
                ID = 1
            };

            Beer beer = new Beer
            {
                ID          = id,
                Name        = name,
                Description = description,
                Price       = price,
                EBC         = EBC,
                IBU         = IBU,
                Percentage  = percentage,
                Stock       = stock,
                ImageURL    = imageURL,
                Brand       = brand,
                Type        = type
            };

            IValidator validator = new BEValidator();

            // act + assert
            var ex = Assert.Throws <ArgumentException>(() => validator.ValidateBeer(beer));

            Assert.Equal(expectedErrorMsg, ex.Message);
        }
Example #6
0
        public void AddBeer_InvalidBeerTypeNull_ExceptArgumentException()
        {
            // arrange
            Brand brand = new Brand {
                ID = 1
            };
            BeerType type = null;

            Beer beer = new Beer
            {
                ID          = 1,
                Name        = "Beer",
                Description = "From 1884!",
                Price       = 65,
                EBC         = 60,
                IBU         = 40,
                Percentage  = 6.5,
                Stock       = 49,
                ImageURL    = "image.png",
                Brand       = brand,
                Type        = type
            };

            IValidator validator = new BEValidator();

            // act + assert
            var ex = Assert.Throws <ArgumentException>(() => validator.ValidateBeer(beer));

            Assert.Equal("A type must be selected", ex.Message);
        }
Example #7
0
        public void AddBeer_ValidBeer(int id, string name, string description, double price, double EBC, double IBU, double percentage, int stock, string ImageURL)
        {
            // arrange
            Brand brand = new Brand {
                ID = 1
            };
            BeerType type = new BeerType {
                ID = 1
            };

            Beer beer = new Beer
            {
                ID          = id,
                Name        = name,
                Description = description,
                Price       = price,
                EBC         = EBC,
                IBU         = IBU,
                Percentage  = percentage,
                ImageURL    = ImageURL,
                Brand       = brand,
                Type        = type
            };

            IValidator validator = new BEValidator();

            // act + assert
            validator.ValidateBeer(beer);
        }
Example #8
0
 public Beer(string _name = "NoName", BeerType _type = BeerType.Mix, float _procent = 0.0F, int _volume = 0)
 {
     name    = _name;
     type    = _type;
     procent = _procent;
     volume  = _volume;
 }
Example #9
0
 //Constructors
 public Beer()
 {
     name    = "NoName";
     type    = BeerType.Mix;
     procent = 0.0F;
     volume  = 0;
 }
        public void GetAllTypes(int beerTypeCount)
        {
            // arrange
            BeerType beerType1 = new BeerType {
                ID = 1
            };
            BeerType beerType2 = new BeerType {
                ID = 2
            };
            List <BeerType> types = new List <BeerType>()
            {
                beerType1, beerType2
            };

            var expected = types.GetRange(0, beerTypeCount);

            foreach (var type in expected)
            {
                typeDatabase.Add(type.ID, type);
            }

            BeerTypeService service = new BeerTypeService(repoMock.Object, validatorMock.Object);

            // act
            var result = service.GetAllTypes();

            // assert
            Assert.Equal(expected, result);
            repoMock.Verify(repo => repo.ReadTypes(), Times.Once);
        }
Example #11
0
 public Beer(string n, BeerType b, float p, int v)
 {
     SetName(n);
     SetBeerType(b);
     SetPercent(p);
     SetVolume(v);
 }
Example #12
0
 private void Init(string brand, string subBrand, BeerStyle style, BeerType type)
 {
     Type     = type;
     Style    = style;
     Brand    = brand;
     SubBrand = subBrand;
 }
Example #13
0
        public void Return_Correct_Edited_Type()
        {
            var options = Utils.GetOptions(nameof(Return_Correct_Edited_Type));

            var beerType = new BeerType
            {
                Id          = 1,
                Description = "Type of beer conditioned at low temperatures.",
                Type        = "Lager",
            };

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.BeerTypes.Add(beerType);
                arrangeContext.SaveChanges();
            }

            var newType  = "Lageerr";
            var newDescr = "Updated";

            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut = new BeerTypesService(assertContext);

                var result = sut.UpdateBeerType(beerType.Id, newType, newDescr);

                Assert.AreEqual(beerType.Id, result.Id);
                Assert.AreEqual(newType, result.Type);
                Assert.AreEqual(newDescr, result.Description);
            }
        }
        public void GetBeerTypesFilterSearch_IndexOutOfBounds_ExpectInvalidDataException()
        {
            // arrange
            repoMock.Setup(repo => repo.ReadTypesFilterSearch(It.IsAny <Filter>())).Returns(() => throw new InvalidDataException("Index out of bounds"));

            BeerType beerType1 = new BeerType {
                ID = 1
            };
            BeerType beerType2 = new BeerType {
                ID = 2
            };

            typeDatabase.Add(beerType1.ID, beerType1);
            typeDatabase.Add(beerType2.ID, beerType2);

            Filter filter = new Filter {
                CurrentPage = 2, ItemsPrPage = 2
            };
            BeerTypeService service = new BeerTypeService(repoMock.Object, validatorMock.Object);

            // act
            var ex = Assert.Throws <InvalidDataException>(() => service.GetTypesFilterSearch(filter));

            // assert
            Assert.Equal("Index out of bounds", ex.Message);
            repoMock.Verify(repo => repo.ReadTypesFilterSearch(It.Is <Filter>(f => f == filter)), Times.Once);
        }
    public static List <Clasification> GetAll()
    {
        //list
        List <Clasification> list = new List <Clasification>();
        //query
        string query = "select cla_code,cla_name,type_code from clasification";
        //command
        MySqlCommand command = new MySqlCommand(query);
        //execute query
        MySqlConnection connection = new MySqlConnection();

        connection.ConnectionSource = new AppSettings();
        DataTable table = connection.ExecuteQuery(command);

        //iterate rows
        foreach (DataRow row in table.Rows)
        {
            //read fields
            string   code     = (string)row["cla_code"];
            string   name     = (string)row["cla_name"];
            BeerType beertype = new BeerType((string)row["type_code"]);
            //add clasification to list
            list.Add(new Clasification(code, name, beertype));
        }
        //return list
        return(list);
    }
    public Clasification(string id)
    {
        //query
        string query = "select cla_code,cla_name,type_code from clasification where cla_code = @ID";
        //command
        MySqlCommand command = new MySqlCommand(query);

        //parameters
        command.Parameters.AddWithValue("@ID", id);
        //execute query
        MySqlConnection connection = new MySqlConnection();

        connection.ConnectionSource = new AppSettings();
        DataTable table = connection.ExecuteQuery(command);

        //check if rows were found
        if (table.Rows.Count > 0)
        {
            //read first and only row
            DataRow row = table.Rows[0];
            //read data
            _code     = (string)row["cla_code"];
            _name     = (string)row["cla_name"];
            _beerType = new BeerType((string)row["type_code"]);
        }
    }
Example #17
0
 public Beer(string Name1, BeerType Slags1, float Procent1, int Volumen1)
 {
     Navn    = Name1;
     Slags   = Slags1;
     Procent = Procent1;
     Volumen = Volumen1;
 }
        public void GetBeerTypesFilterSearch_CorrectPaging()
        {
            // arrange
            BeerType beerType1 = new BeerType {
                ID = 1
            };
            BeerType beerType2 = new BeerType {
                ID = 2
            };

            typeDatabase.Add(beerType1.ID, beerType1);
            typeDatabase.Add(beerType2.ID, beerType2);

            var expected = new List <BeerType>()
            {
                beerType1, beerType2
            };
            int expectedSize = expected.Count;

            Filter filter = new Filter {
                CurrentPage = 1, ItemsPrPage = 2
            };
            BeerTypeService service = new BeerTypeService(repoMock.Object, validatorMock.Object);

            // act
            var result = service.GetTypesFilterSearch(filter);

            // assert
            Assert.Equal(expected, result.List);
            Assert.Equal(expectedSize, result.totalItems);
            repoMock.Verify(repo => repo.ReadTypesFilterSearch(It.Is <Filter>(f => f == filter)), Times.Once);
        }
Example #19
0
 public Beer(string name, BeerType beerType, int minTemperature, int maxTemperature)
 {
     Name           = name;
     BeerType       = beerType;
     MinTemperature = minTemperature;
     MaxTemperature = maxTemperature;
 }
Example #20
0
 public async Task <bool> RemoveBeerType(BeerType beerType)
 {
     if (await _beerTypeRepository.DeleteAsyn(beerType) == 0)
     {
         return(false);
     }
     return(true);
 }
Example #21
0
 public BeerTypeViewmodel Map(BeerType raw)
 {
     return(new BeerTypeViewmodel()
     {
         Id = raw.Id,
         Name = raw.Name
     });
 }
Example #22
0
 public Beer(long id, string name, BeerType beerType, int minTemperature, int maxTemperature)
 {
     Id             = id;
     Name           = name;
     BeerType       = beerType;
     MinTemperature = minTemperature;
     MaxTemperature = maxTemperature;
 }
Example #23
0
 public async Task <bool> UpdateBeerType(int id, BeerType beerType)
 {
     if (await _beerTypeRepository.UpdateAsyn(beerType, id) == null)
     {
         return(false);
     }
     return(true);
 }
Example #24
0
 public Beer(string name, BeerType type, double abv, string brewery)
 {
     Id      = Guid.NewGuid().ToString();
     Name    = name;
     Type    = type;
     Abv     = abv;
     Brewery = brewery;
 }
Example #25
0
 public Beer(string navn, BeerType slags, float procent, int volumen)
 {
     Navn    = navn;
     Slags   = slags;
     Procent = procent;
     Volumen = volumen;
     Alkohol = GetUnits();
 }
        public void Editar()
        {
            EditarTipoViewModel editarTipo = new EditarTipoViewModel(TipoSeleccionado);
            IWindowManager      manejador2 = new WindowManager();

            manejador2.ShowDialog(editarTipo, null, null);
            Tipos = null;
            Tipos = new BindableCollection <BeerType>(BeerType.GetAll());
        }
        public void Agregar()
        {
            AgregarTipoViewModel agregarTipo = new AgregarTipoViewModel();
            IWindowManager       manejador   = new WindowManager();

            manejador.ShowDialog(agregarTipo, null, null);
            Tipos = null;
            Tipos = new BindableCollection <BeerType>(BeerType.GetAll());
        }
 public BeerType CreateType(BeerType type)
 {
     if (type != null)
     {
         this.Validator.ValidateType(type);
         return(TypeRepository.AddType(type));
     }
     return(null);
 }
Example #29
0
 public IHttpActionResult PostBeerType(BeerType beerType)
 {
     if (!ModelState.IsValid)
     {
         return BadRequest(ModelState);
     }
     _context.Post(beerType);
     return CreatedAtRoute("DefaultApi", new { id = beerType.BeerTypeID }, beerType);
 }
 public Beer(string name, string brand, BeerType type, float percentage, double price, string url, uint stock)
 {
     this.Name       = name;
     this.Brand      = brand;
     this.Type       = type;
     this.Percentage = percentage;
     this.Price      = price;
     this.ImageURL   = url;
     this.Stock      = stock;
 }
Example #31
0
 public int AdminUpdate(BeerType entity)
 {
     this.deleteableRepo.Update(entity);
     this.deleteableRepo.SaveChanges();
     return entity.Id;
 }