public async Task UpdateCocktail_Updates_Correct() { //Arrange var options = Utils.GetOptions(nameof(UpdateCocktail_Updates_Correct)); var cocktail = new Cocktail { Id = Guid.NewGuid(), Name = "Cuba Libre" }; var cocktailDTO = new CocktailDTO { Name = "Cuba Libre Indeed", AlcoholPercentage = 2.5, IsAlcoholic = true }; using (var arrangeContext = new CMContext(options)) { await arrangeContext.Cocktails.AddAsync(cocktail); await arrangeContext.SaveChangesAsync(); } //Act, Assert using (var assertContex = new CMContext(options)) { var sut = new CocktailServices(assertContex); var result = await sut.UpdateCocktail(cocktail.Id, cocktailDTO); Assert.AreEqual("Cuba Libre Indeed", result.Name); Assert.AreEqual(2.5, result.AlcoholPercentage); Assert.AreEqual(true, result.IsAlcoholic); Assert.IsInstanceOfType(result, typeof(CocktailDTO)); } }
public async Task CreateCocktail_Throws_When_NameExists() { //Arrange var options = Utils.GetOptions(nameof(CreateCocktail_Throws_When_NameExists)); var cocktail = new Cocktail { Id = Guid.NewGuid(), Name = "Cuba Libre" }; var cocktailDTO = new CocktailDTO { Name = "Cuba Libre" }; using (var arrangeContext = new CMContext(options)) { await arrangeContext.Cocktails.AddAsync(cocktail); await arrangeContext.SaveChangesAsync(); } //Act, Assert using (var assertContext = new CMContext(options)) { var sut = new CocktailServices(assertContext); await Assert.ThrowsExceptionAsync <ArgumentException>(() => sut.CreateCocktail(cocktailDTO)); } }
public async Task <CocktailDTO> Create(CocktailDTO cocktailDTO) { if (this.context.Bars.Any(b => b.Name == cocktailDTO.Name)) { throw new ArgumentException("The name is already existing"); } if (cocktailDTO.Name == null) { throw new ArgumentNullException("The name is mandatory"); } var cocktail = new Cocktail { Id = cocktailDTO.Id, AlcoholPercentage = cocktailDTO.AlcoholPercentage, Bars = cocktailDTO.Bars, Comments = cocktailDTO.Comments, ImageURL = cocktailDTO.ImageURL, Ingredients = cocktailDTO.Ingredients, IsAlcoholic = cocktailDTO.IsAlcoholic, Name = cocktailDTO.Name, Rating = cocktailDTO.Rating, Stars = cocktailDTO.Stars }; await context.Cocktails.AddAsync(cocktail); await context.SaveChangesAsync(); return(cocktail.Map()); }
public async Task GetAllCocktailsDTOReturnsCorrectDTOs() { var options = TestUtilities.GetOptions(nameof(GetAllCocktailsDTOReturnsCorrectDTOs)); var ingredientServiceMock = new Mock <ICocktailIngredientService>(); var cocktailMapperToDTOMock = new Mock <IDTOServiceMapper <CocktailDTO, Cocktail> >(); var cocktailMapperMock = new Mock <IDTOServiceMapper <Cocktail, CocktailDTO> >(); var commentMapperToDTOMock = new Mock <IDTOServiceMapper <CommentDTO, CocktailComment> >(); var commentMapperMock = new Mock <IDTOServiceMapper <CocktailComment, CommentDTO> >(); var addCocktailMapperMock = new Mock <IDTOServiceMapper <Cocktail, AddCocktailDTO> >(); var cocktailRatingToDTOMock = new Mock <IDTOServiceMapper <RatingDTO, CocktailRating> >(); var ingrMapper = new Mock <IDTOServiceMapper <CocktailIngredient, CocktailIngredientDTO> >(); ingrMapper.Setup(x => x.MapFrom(It.IsAny <CocktailIngredient>())).Returns(It.IsAny <CocktailIngredientDTO>()); var cocktail = new Cocktail() { Name = "Name", Id = "1", Motto = "Motto", PicUrl = "Pic", }; var cocktail2 = new Cocktail() { Name = "Name2", Id = "12", Motto = "Motto2", PicUrl = "Pic2", }; var cocktailDTO = new CocktailDTO() { Name = "Name", Id = "1", Motto = "Motto", PicUrl = "Pic", }; //Act cocktailMapperMock.Setup(m => m.MapFrom(It.IsAny <Cocktail>())).Returns(cocktailDTO); using (var actContext = new IriOnCocktailServiceDbContext(options)) { await actContext.Cocktails.AddAsync(cocktail); await actContext.Cocktails.AddAsync(cocktail2); await actContext.SaveChangesAsync(); } using (var assertContext = new IriOnCocktailServiceDbContext(options)) { var sut = new CocktailService(assertContext, ingredientServiceMock.Object, cocktailMapperMock.Object, cocktailMapperToDTOMock.Object, commentMapperToDTOMock.Object, commentMapperMock.Object, addCocktailMapperMock.Object, cocktailRatingToDTOMock.Object); var result = await sut.GetAllCocktailsDTO(); Assert.AreEqual(2, result.Count); } }
public CocktailViewModel MapToVMFromDTO(CocktailDTO cocktailDTO) { if (cocktailDTO == null) { return(null); } var cocktailVM = new CocktailViewModel { Id = cocktailDTO.Id, Name = cocktailDTO.Name, AverageRating = cocktailDTO.AverageRating, Bars = cocktailDTO.Bars.Select(b => new BarViewModel { Id = b.Id, Name = b.Name, //Address = b.Address, CityName = b.CityName, //Phone = b.Phone, AverageRating = b.AverageRating }).ToList(), Ingredients = cocktailDTO.Ingredients.Select(i => new IngredientViewModel { Id = i.Id, Name = i.Name }).ToList(), ImageData = cocktailDTO.ImageData, ImageSource = cocktailDTO.ImageSource }; return(cocktailVM); }
public CocktailDTO MapToDTOFromVM(EditCocktailViewModel editCocktailVM) { if (editCocktailVM == null) { return(null); } var cocktailDTO = new CocktailDTO { Id = editCocktailVM.Id, Name = editCocktailVM.Name, Ingredients = editCocktailVM.ContainedIngredients.Select(i => new IngredientDTO { Id = i }).ToList(), Bars = editCocktailVM.ContainedBars.Select(b => new BarDTO { Id = b }).ToList(), }; if (editCocktailVM.File != null) { cocktailDTO.ImageData = editCocktailVM.ImageData; } return(cocktailDTO); }
public async Task CreateCocktail() { var options = TestUtilities.GetOptions(nameof(CreateCocktail)); var mockIngredient = new Mock <IIngredientManager>(); var mockFactory = new Mock <ICocktailFactory>(); var igredients = new List <string> { "first" }; var ingredient = new Ingredient() { Name = "first", }; var cocktailDTO = new CocktailDTO() { Name = "cocktailName", Information = "cocktail infromation", Picture = "picture", }; using (var arrangeContext = new CMContext(options)) { await arrangeContext.Ingredients.AddAsync(ingredient); await arrangeContext.SaveChangesAsync(); var sut = new CocktailManager(mockIngredient.Object, arrangeContext, mockFactory.Object); await sut.CreateCocktail(cocktailDTO, igredients); } using (var assertContext = new CMContext(options)) { Assert.AreEqual(1, assertContext.Cocktails.Count()); } }
public void CorrectMapping_ToEntityModel() { //Arrange var options = Utils.GetOptions(nameof(CorrectMapping_ToEntityModel)); //Act & Assert using (var assertContext = new CocktailMagicianContext(options)) { var cocktailDTO = new CocktailDTO { Id = 5, Name = "Cuba Libre", AverageRating = 3.5, IsDeleted = false }; var sut = new CocktailMapper(); var result = sut.MapToCocktail(cocktailDTO); Assert.IsInstanceOfType(result, typeof(Cocktail)); Assert.AreEqual(cocktailDTO.Id, result.Id); Assert.AreEqual(cocktailDTO.Name, result.Name); Assert.AreEqual(cocktailDTO.AverageRating, result.AverageRating); Assert.AreEqual(cocktailDTO.IsDeleted, result.IsDeleted); } }
public CocktailDTO MapToCocktailDTO(Cocktail cocktail) { if (cocktail == null) { return(null); } var cocktailDTO = new CocktailDTO { Id = cocktail.Id, Name = cocktail.Name, AverageRating = cocktail.AverageRating, Bars = cocktail.CocktailBars.Select(b => new BarDTO { Id = b.Bar.Id, Name = b.Bar.Name }).ToList(), Ingredients = cocktail.IngredientsCocktails.Select(i => new IngredientDTO { Id = i.Ingredient.Id, Name = i.Ingredient.Name }).ToList(), IsDeleted = cocktail.IsDeleted, ImageData = cocktail.ImageData, ImageSource = cocktail.ImageSource }; return(cocktailDTO); }
/// <summary> /// This method adds the new Cocktail to the DataBase after checking if it does not exists already /// </summary> /// <param name="cocktail">This is the newly created Cocktail object</param> /// <returns>Task</returns> public async Task CreateCocktail(CocktailDTO cocktail, List <string> ingredients) { var cocktailToFind = _context.Cocktails.SingleOrDefault(c => c.Name == cocktail.Name); if (cocktailToFind != null) { throw new InvalidOperationException("Cocktail already exists in the database"); } var cocktailToAdd = _cocktailFactory.CreateNewCocktail(cocktail.Name, cocktail.Picture); cocktailToAdd.CocktailIngredient = new List <CocktailIngredient>(); foreach (var ingredient in ingredients) { var findIngredient = await _ingredientManager.FindIngredientByNameAsync(ingredient); if (findIngredient != null) { cocktailToAdd.CocktailIngredient.Add(new CocktailIngredient() { Cocktail = cocktailToAdd, Ingredient = findIngredient.ToEntity() }); } } cocktailToAdd.Information = CreateCocktailsRecipe(ingredients); await _context.Cocktails.AddAsync(cocktailToAdd); await _context.SaveChangesAsync(); }
public async Task RecoverCocktail_When_ItIsDeleted() { var testCocktailName = "TestCocktailName"; var options = Utils.GetOptions(nameof(RecoverCocktail_When_ItIsDeleted)); var entityCocktail = new Cocktail() { Name = testCocktailName, IsDeleted = true, }; var dto = new CocktailDTO() { Name = testCocktailName, }; var mockMapper = new Mock <ICocktailMapper>(); mockMapper.Setup(x => x.MapDTOToEntity(It.IsAny <CocktailDTO>())) .Returns((CocktailDTO x) => new Cocktail() { Name = x.Name, }); mockMapper.Setup(x => x.MapEntityToDTO(It.IsAny <Cocktail>())) .Returns((Cocktail x) => new CocktailDTO() { Name = x.Name, }); var mockBarMapper = new Mock <IBarMapper>(); using (var arrangeContext = new BCcontext(options)) { await arrangeContext.Cocktails .AddAsync(entityCocktail); await arrangeContext.SaveChangesAsync(); } using (var actContext = new BCcontext(options)) { var sut = new CocktailsService(actContext, mockMapper.Object, mockBarMapper.Object); var cocktail = sut.CreateAsync(dto); await actContext.SaveChangesAsync(); } using (var assertContext = new BCcontext(options)) { var sut = new CocktailsService(assertContext, mockMapper.Object, mockBarMapper.Object); var cocktail = await sut.CreateAsync(dto); Assert.AreEqual(1, assertContext.Cocktails.Count()); Assert.IsNotNull(cocktail); Assert.AreEqual(testCocktailName, testCocktailName); Assert.IsFalse(cocktail.IsDeleted); } }
public bool CocktailIsUnique(CocktailDTO cocktailDTO) { if (this.context.Cocktails.Any(x => x.Name.ToLower().Equals(cocktailDTO.Name.ToLower()))) { return(false); } return(true); }
public async Task AddCocktailToBar_Throws_When_Cocktail_IsAreadyListed() { //Arrange var options = Utils.GetOptions(nameof(AddCocktailToBar_Throws_When_Cocktail_IsAreadyListed)); var bar = new Bar { Id = Guid.NewGuid(), Name = "Cosmos", Country = new Country { Id = Guid.NewGuid(), Name = "Bulgaria" } }; var cocktail = new Cocktail { Id = Guid.NewGuid(), Name = "Manhattan", }; var cocktailDTO = new CocktailDTO { Id = cocktail.Id, Name = cocktail.Name, }; var barCocktail = new BarCocktail { BarId = bar.Id, CocktailId = cocktail.Id, }; using (var arrangeContext = new CMContext(options)) { await arrangeContext.Bars.AddAsync(bar); await arrangeContext.Cocktails.AddAsync(cocktail); await arrangeContext.BarCocktails.AddAsync(barCocktail); await arrangeContext.SaveChangesAsync(); } //Act,Assert using (var assertContext = new CMContext(options)) { var sut = new BarServices(assertContext); await Assert.ThrowsExceptionAsync <InvalidOperationException>(() => sut.AddCocktailToBar(bar.Id, cocktailDTO.Id)); } }
public CocktailViewModel MapDTOToView(CocktailDTO dto) { try { return(new CocktailViewModel { Id = dto.Id, Name = dto.Name, Rating = dto.Rating, TimesRated = dto.TimesRated, ImageSrc = dto.ImageSrc, IsDeleted = dto.IsDeleted, IsAlcoholic = dto.IsAlcoholic, Instructions = dto.Instructions, Ingredients = dto.Ingredients.Select(i => new CocktailIngredientViewModel() { IngredientId = i.IngredientId, IngredientName = i.IngredientName, Parts = i.Parts }).ToList(), //Comments = dto.Comments, //TODO: Mapping lists ? Bars = dto.Bars.Select(b => new CocktailBarView { BarId = b.BarId, BarName = b.BarName, CocktailId = b.CocktailId, CocktailName = b.CocktailName, }).ToList(), Comments = dto.Comments.Select(c => new CocktailUserCommentVM { CocktailId = c.CocktailId, CocktailName = c.CocktailName, UserId = c.UserId, UserName = c.UserName, Text = c.Text, IsFlagged = c.IsFlagged, }).ToList(), CocktailRatings = dto.CocktailRatings.Select(r => new UserCocktailRatingDTO { CocktailId = r.CocktailId, CocktailName = r.CocktailName, UserId = r.UserId, UserName = r.UserName, Rating = r.Rating, }).ToList(), //Instructions = dto.Instructions, }); } catch (Exception) { return(new CocktailViewModel()); } }
public async Task RemoveCocktailFromBar_Throws_When_Cocktail_NotFound_AtThisBar() { //Arrange var options = Utils.GetOptions(nameof(RemoveCocktailFromBar_Throws_When_Cocktail_NotFound_AtThisBar)); var bar = new Bar { Id = Guid.Parse("86cb5331-0035-4a52-b99b-08df779358e3"), Name = "Cosmos", Country = new Country { Id = Guid.Parse("fb837576-a066-43a1-9812-3c1eac4d449c"), Name = "Bulgaria" } }; var cocktail = new Cocktail { Id = Guid.Parse("bb4b4175-81c5-4828-bca4-3660f796eb3f"), Name = "Manhattan", }; var cocktailDTO = new CocktailDTO { Id = cocktail.Id, Name = cocktail.Name, }; var barCocktail = new BarCocktail { Id = Guid.Parse("ca28a84e-1885-4d1b-aee9-3ab4f9ade0f7"), CocktailId = cocktail.Id }; using (var arrangeContext = new CMContext(options)) { await arrangeContext.Bars.AddAsync(bar); await arrangeContext.Cocktails.AddAsync(cocktail); await arrangeContext.BarCocktails.AddAsync(barCocktail); await arrangeContext.SaveChangesAsync(); } //Act,Assert using (var assertContext = new CMContext(options)) { var sut = new BarServices(assertContext); await Assert.ThrowsExceptionAsync <InvalidOperationException>(() => sut.RemoveCocktailFromBar(bar.Id, cocktailDTO.Id)); } }
public async Task GetAllCocktailDTOs_ThrowsCorrectMsgWhenNotAvailable() { var options = TestUtilities.GetOptions(nameof(GetAllCocktailDTOs_ThrowsCorrectMsgWhenNotAvailable)); var ingredientServiceMock = new Mock <ICocktailIngredientService>(); var cocktailMapperToDTOMock = new Mock <IDTOServiceMapper <CocktailDTO, Cocktail> >(); var cocktailMapperMock = new Mock <IDTOServiceMapper <Cocktail, CocktailDTO> >(); var commentMapperToDTOMock = new Mock <IDTOServiceMapper <CommentDTO, CocktailComment> >(); var commentMapperMock = new Mock <IDTOServiceMapper <CocktailComment, CommentDTO> >(); var addCocktailMapperMock = new Mock <IDTOServiceMapper <Cocktail, AddCocktailDTO> >(); var cocktailRatingToDTOMock = new Mock <IDTOServiceMapper <RatingDTO, CocktailRating> >(); var ingrMapper = new Mock <IDTOServiceMapper <CocktailIngredient, CocktailIngredientDTO> >(); ingrMapper.Setup(x => x.MapFrom(It.IsAny <CocktailIngredient>())).Returns(It.IsAny <CocktailIngredientDTO>()); var cocktail = new Cocktail() { Name = "Name", Id = "1", Motto = "Motto", PicUrl = "Pic", NotAvailable = true, }; var cocktailDTO = new CocktailDTO() { Name = "Name", Id = "1", Motto = "Motto", PicUrl = "Pic", NotAvailable = true, }; var cocktailDTOMock = new Mock <CocktailDTO>(); var cocktailMock = new Mock <Cocktail>(); //Act cocktailMapperMock.Setup(m => m.MapFrom(It.IsAny <Cocktail>())).Returns(cocktailDTO); using (var actContext = new IriOnCocktailServiceDbContext(options)) { await actContext.Cocktails.AddAsync(cocktail); await actContext.SaveChangesAsync(); } using (var assertContext = new IriOnCocktailServiceDbContext(options)) { var sut = new CocktailService(assertContext, ingredientServiceMock.Object, cocktailMapperMock.Object, cocktailMapperToDTOMock.Object, commentMapperToDTOMock.Object, commentMapperMock.Object, addCocktailMapperMock.Object, cocktailRatingToDTOMock.Object); await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.GetAllCocktailsDTO(), GlobalConstants.NoCocktailsFound); } }
/// <summary> /// This method finds the corresponding Cocktail to update and updates its properties with the new values. /// Updates the Cocktails recipe by calling the method UpdateInformation. /// </summary> /// <param name="cocktail">Object of type Cocktail with new values to update</param> /// <param name="ingredientsToRemove">List of ingredients names to remove from Recipe</param> /// <param name="ingredientsToAdd">List of ingredients names to add to the recipe</param> /// <returns>Task</returns> public async Task EditCocktailAsync(CocktailDTO cocktail, List <string> ingredientsToRemove, List <string> ingredientsToAdd) { var cocktailToUpdate = await _context.Cocktails.Include(c => c.CocktailIngredient).FirstOrDefaultAsync(c => c.Id == cocktail.Id); cocktailToUpdate.Name = cocktail.Name; cocktailToUpdate.Picture = cocktail.Picture; if (ingredientsToRemove.Count() > 0 && ingredientsToAdd.Count() > 0) { foreach (var ingredient in ingredientsToRemove) { var ingredientToRemove = await _ingredientManager.FindIngredientByNameAsync(ingredient); _context.CocktailIngredients.Remove(cocktailToUpdate.CocktailIngredient.FirstOrDefault(ci => ci.CocktailId == cocktailToUpdate.Id && ci.IngredientId == ingredientToRemove.Id)); } foreach (var ingredient in ingredientsToAdd) { var ingredientToAdd = await _ingredientManager.FindIngredientByNameAsync(ingredient); cocktailToUpdate.CocktailIngredient.Add(new CocktailIngredient() { Cocktail = cocktailToUpdate, Ingredient = ingredientToAdd.ToEntity() }); } } else if (ingredientsToRemove.Count() > 0 && ingredientsToAdd.Count() == 0) { foreach (var ingredient in ingredientsToRemove) { var ingredientToRemove = await _ingredientManager.FindIngredientByNameAsync(ingredient); _context.CocktailIngredients.Remove(cocktailToUpdate.CocktailIngredient.FirstOrDefault(ci => ci.CocktailId == cocktailToUpdate.Id && ci.IngredientId == ingredientToRemove.Id)); } } else if (ingredientsToRemove.Count() == 0 && ingredientsToAdd.Count() > 0) { foreach (var ingredient in ingredientsToAdd) { var ingredientToAdd = await _ingredientManager.FindIngredientByNameAsync(ingredient); cocktailToUpdate.CocktailIngredient.Add(new CocktailIngredient() { Cocktail = cocktailToUpdate, Ingredient = ingredientToAdd.ToEntity() }); } } _context.Cocktails.Update(cocktailToUpdate); await _context.SaveChangesAsync(); await UpdateInformation(cocktailToUpdate.Id); }
public async Task UpdateCocktail_WhenParamsAreValid() { //Arrange var mockDateTimeprovider = new Mock <IDateTimeProvider>(); var mockCocktailMapper = new Mock <ICocktailMapper>(); mockCocktailMapper.Setup(c => c.MapToCocktail(It.IsAny <CocktailDTO>())) .Returns <CocktailDTO>(c => new Cocktail { Id = c.Id, Name = c.Name, IsDeleted = c.IsDeleted }); var mockIngMapper = new Mock <IIngredientMapper>(); mockIngMapper.Setup(i => i.MapToIngredient(It.IsAny <IngredientDTO>())) .Returns <IngredientDTO>(i => new Ingredient { Id = i.Id, Name = i.Name }); var mockBarMapper = new Mock <IBarMapper>(); var mockCocktailReviewService = new Mock <ICocktailReviewService>(); var options = Utils.GetOptions(nameof(UpdateCocktail_WhenParamsAreValid)); Utils.GetInMemoryDataBase(options); var newDTO = new CocktailDTO { Name = "Gin sTonik", Ingredients = new List <IngredientDTO> { new IngredientDTO { Id = 3 }, new IngredientDTO { Id = 4 } } }; //Act & Assert using (var assertContext = new CocktailMagicianContext(options)) { var sut = new CocktailService(mockDateTimeprovider.Object, mockCocktailMapper.Object, mockIngMapper.Object, mockBarMapper.Object, assertContext, mockCocktailReviewService.Object); var result = await sut.UpdateCocktailAsync(2, newDTO); Assert.AreEqual(newDTO.Id, result.Id); Assert.AreEqual(newDTO.Name, result.Name); Assert.AreEqual(newDTO.IsDeleted, result.IsDeleted); Assert.AreEqual(newDTO.Ingredients.ToList().Count, result.Ingredients.ToList().Count); CollectionAssert.AreEqual(newDTO.Ingredients.ToList(), result.Ingredients.ToList()); } }
public static Cocktail ToCreateEntity(this CocktailDTO cocktailDTO) { var cocktail = new Cocktail { Name = cocktailDTO.Name, Picture = cocktailDTO.Picture, IsDeleted = cocktailDTO.IsDeleted, CocktailReviews = cocktailDTO.CocktailReviewDTOs?.ToEntity() }; return(cocktail); }
public static Cocktail CocktailDTOMapToModel(this CocktailDTO cocktailDTO) { var cocktail = new Cocktail(); cocktail.Id = cocktailDTO.Id; cocktail.Name = cocktailDTO.Name; cocktail.Description = cocktailDTO.Description; cocktail.UnlistedOn = cocktailDTO.UnlistedOn; cocktail.AvgRating = cocktailDTO.AvgRating; return(cocktail); }
public static CocktailViewModel ToCatalogVM(this CocktailDTO cocktail) { var cocktailViewModel = new CocktailViewModel() { CocktailId = cocktail.Id, Information = cocktail.Information, Name = cocktail.Name, Picture = cocktail.Picture, Rating = cocktail.Rating }; return(cocktailViewModel); }
public async Task <CocktailDTO> EditCocktailAsync(CocktailDTO cocktailDTO) { var cocktail = await GetCocktail(cocktailDTO.Id); cocktail.Name = cocktailDTO.Name; cocktail.PicUrl = cocktailDTO.PicUrl; cocktail.Motto = cocktailDTO.Motto; this.context.Cocktails.Update(cocktail); await this.context.SaveChangesAsync(); return(cocktailDTO); }
public async Task <ActionResult <CocktailDTO> > PostCocktail(CocktailDTO cocktailDTO) { try { var cocktail = await this._service.CreateAsync(cocktailDTO); return(Created("PostCocktail", cocktail)); } catch (Exception) { return(NoContent()); } }
public async Task <IActionResult> PutCocktail(Guid id, CocktailDTO cocktailDTO) { try { var cocktail = await this._service.UpdateAsync(id, cocktailDTO); return(RedirectToAction()); } catch (Exception) { return(NoContent()); } }
public async Task AddCocktailToBar_Adds_Correctly_When_Params_Are_Valid() { //Arrange var options = Utils.GetOptions(nameof(AddCocktailToBar_Adds_Correctly_When_Params_Are_Valid)); var bar = new Bar { Id = Guid.NewGuid(), Name = "Cosmos", Country = new Country { Id = Guid.NewGuid(), Name = "Bulgaria" } }; var cocktail = new Cocktail { Id = Guid.NewGuid(), Name = "Manhattan", }; var cocktailDTO = new CocktailDTO { Id = cocktail.Id, Name = cocktail.Name, }; using (var arrangeContext = new CMContext(options)) { await arrangeContext.Bars.AddAsync(bar); await arrangeContext.Cocktails.AddAsync(cocktail); await arrangeContext.SaveChangesAsync(); } //Act,Assert using (var assertContext = new CMContext(options)) { var sut = new BarServices(assertContext); var result = await sut.AddCocktailToBar(bar.Id, cocktailDTO.Id); Assert.AreEqual(1, assertContext.BarCocktails.Count()); Assert.AreEqual(1, result.BarCocktails.Count()); Assert.AreEqual(true, result.BarCocktails.ToList()[0].IsListed); Assert.IsInstanceOfType(result, typeof(BarDTO)); } }
public static Cocktail ToEntity(this CocktailDTO cocktailDTO) { var cocktail = new Cocktail { Id = cocktailDTO.Id, Name = cocktailDTO.Name, Information = cocktailDTO.Information, Picture = cocktailDTO.Picture, IsDeleted = cocktailDTO.IsDeleted, CocktailReviews = cocktailDTO.CocktailReviewDTOs?.ToEntity() }; return(cocktail); }
public static CocktailDTO ToCatalogDTO(this Cocktail cocktail) { var cocktailDTO = new CocktailDTO { Id = cocktail.Id, Name = cocktail.Name, Information = cocktail.Information, Picture = cocktail.Picture, IsDeleted = cocktail.IsDeleted, Rating = cocktail.Rating }; return(cocktailDTO); }
public static CocktailDTO ToEditDTO(this CocktailViewModel cocktailView) { var cocktailDTO = new CocktailDTO() { Id = cocktailView.CocktailId, Information = cocktailView.Information, Name = cocktailView.Name, Picture = cocktailView.Picture, Rating = cocktailView.Rating, CocktailIngredientDTOs = cocktailView.CocktailIngredients != null?cocktailView.CocktailIngredients.ToDTO() : new List <CocktailIngredientDTO>() }; return(cocktailDTO); }
public static CocktailViewModel ToEditVM(this CocktailDTO cocktail) { var cocktailViewModel = new CocktailViewModel() { CocktailId = cocktail.Id, Information = cocktail.Information, Name = cocktail.Name, Picture = cocktail.Picture, Rating = cocktail.Rating, CocktailIngredients = cocktail.CocktailIngredientDTOs.ToVM() }; return(cocktailViewModel); }
public static CocktailDTO ToDTO(this CocktailViewModel cocktailView) { var cocktailViewModel = new CocktailDTO() { //Id = cocktailView.CocktailId, //Information = cocktailView.Information, Name = cocktailView.Name, Picture = cocktailView.Picture, Rating = cocktailView.Rating, CocktailReviewDTOs = cocktailView.ReviewViewModels?.ToCocktailReviewDTO() }; return(cocktailViewModel); }