Exemple #1
0
        public static CocktailIngredientDTO ToDTO(this CocktailIngredientsViewModel viewModel)
        {
            var cocktailIngredientDTO = new CocktailIngredientDTO
            {
                CocktailId     = viewModel.CocktailId,
                IngredientId   = viewModel.IngredientId,
                IngredientName = viewModel.IngredientName
            };

            return(cocktailIngredientDTO);
        }
Exemple #2
0
        public static CocktailIngredientsViewModel ToVM(this CocktailIngredientDTO cocktailIngredientDTO)
        {
            var viewModel = new CocktailIngredientsViewModel
            {
                CocktailId     = cocktailIngredientDTO.CocktailId,
                IngredientId   = cocktailIngredientDTO.IngredientId,
                IngredientName = cocktailIngredientDTO.IngredientName
            };

            return(viewModel);
        }
Exemple #3
0
        public static CocktailIngredientViewModel MapToViewModel(this CocktailIngredientDTO dto)
        {
            var vm = new CocktailIngredientViewModel
            {
                Name  = dto.Name,
                Value = dto.Value,
                Unit  = dto.Unit
            };

            return(vm);
        }
Exemple #4
0
        public static CocktailIngredientDTO ToDTO(this CocktailIngredient cocktailIngredient)
        {
            var cocktailIngredientDTO = new CocktailIngredientDTO
            {
                CocktailId     = cocktailIngredient.CocktailId,
                IngredientId   = cocktailIngredient.IngredientId,
                IngredientName = cocktailIngredient.Ingredient.Name
            };

            return(cocktailIngredientDTO);
        }
        public static CocktailIngredient GetEntity(this CocktailIngredientDTO item)
        {
            if (item == null)
            {
                throw new ArgumentNullException();
            }

            return(new CocktailIngredient
            {
                Cocktail = item.Cocktail,
                CocktailId = item.CocktailId,
                Ingredient = item.Ingredient,
                IngredientId = item.IngredientId
            });
        }
        public static CocktailIngredientDTO MapToDTO(this CocktailIngredientViewModel vm)
        {
            var dto = new CocktailIngredientDTO
            {
                Value = vm.Value
            };

            var commaIndex = vm.Name.IndexOf(',');

            if (commaIndex >= 0)
            {
                dto.Name = vm.Name.Substring(0, commaIndex);
            }
            else
            {
                dto.Name = vm.Name;
            }
            return(dto);
        }
        public async Task ThrowException_WhenCocktailIngredientHasNoQuantity()
        {
            var cocktailFactoryMock           = new Mock <ICocktailFactory>();
            var cocktailIngredinetFactoryMock = new Mock <ICocktailIngredientFactory>();
            var barCocktailFactoryMock        = new Mock <IBarCocktailFactory>();

            var cocktailNameTest = "TestName";
            var imageURLTest     = "https://www.google.com/";

            var ingrNameTest = "IngrTest";
            var ingrUnitTest = "Unit";
            var quantityTest = 0.0;

            var cocktailIngredientDTO = new CocktailIngredientDTO
            {
                Name  = ingrNameTest,
                Unit  = ingrUnitTest,
                Value = quantityTest
            };

            var listOfIngr = new List <CocktailIngredientDTO> {
                cocktailIngredientDTO
            };

            var cocktailTest = new Cocktail
            {
                Name      = cocktailNameTest,
                ImagePath = imageURLTest
            };

            var options = TestUtilities.GetOptions(nameof(ThrowException_WhenCocktailIngredientHasNoQuantity));

            using (var assertContext = new CocktailMagicianDb(options))
            {
                var sut = new CocktailServices(assertContext, cocktailFactoryMock.Object, cocktailIngredinetFactoryMock.Object, barCocktailFactoryMock.Object);
                await Assert.ThrowsExceptionAsync <InvalidOperationException>(() => sut.AddAsync(cocktailNameTest, imageURLTest, listOfIngr));
            }
        }
        public async Task AddCocktailToDB()
        {
            var cocktailFactoryMock           = new Mock <ICocktailFactory>();
            var cocktailIngredinetFactoryMock = new Mock <ICocktailIngredientFactory>();
            var barCocktailFactoryMock        = new Mock <IBarCocktailFactory>();

            var cocktailNameTest = "TestName";
            var imageURLTest     = "https://www.google.com/";

            var ingrNameTest = "IngrTest";
            var ingrUnitTest = "Unit";
            var quantityTest = 0.5;

            var cocktailIngredientDTO = new CocktailIngredientDTO
            {
                Name  = ingrNameTest,
                Unit  = ingrUnitTest,
                Value = quantityTest
            };

            var listOfIngr = new List <CocktailIngredientDTO> {
                cocktailIngredientDTO
            };

            var cocktailTest = new Cocktail
            {
                Name      = cocktailNameTest,
                ImagePath = imageURLTest
            };

            cocktailFactoryMock
            .Setup(f => f.Create(cocktailNameTest, imageURLTest))
            .Returns(cocktailTest);

            var options = TestUtilities.GetOptions(nameof(AddCocktailToDB));

            using (var arrangeContext = new CocktailMagicianDb(options))
            {
                arrangeContext.Ingredients.Add(new Ingredient {
                    Name = ingrNameTest, Unit = ingrUnitTest
                });
                await arrangeContext.SaveChangesAsync();
            }

            using (var actContext = new CocktailMagicianDb(options))
            {
                var sut = new CocktailServices(actContext, cocktailFactoryMock.Object, cocktailIngredinetFactoryMock.Object, barCocktailFactoryMock.Object);

                var ingrId = await actContext.Ingredients.Where(i => i.Name == ingrNameTest).Select(i => i.Id).FirstAsync();

                cocktailIngredinetFactoryMock
                .Setup(f => f.Create(cocktailTest, ingrId, quantityTest))
                .Returns(new CocktailIngredient
                {
                    Cocktail     = cocktailTest,
                    IngredientId = ingrId,
                    Quatity      = quantityTest
                });

                await sut.AddAsync(cocktailNameTest, imageURLTest, listOfIngr);
            }

            using (var assertContext = new CocktailMagicianDb(options))
            {
                var cocktail = await assertContext.Cocktails.Include(c => c.CocktailIngredients).FirstAsync();

                Assert.AreEqual(1, assertContext.Cocktails.Count());
                Assert.AreEqual(cocktailNameTest, cocktail.Name);
                Assert.AreEqual(1, cocktail.CocktailIngredients.Count());
            }
        }