public async Task GetAllCommentsForCocktailCorrectly() { var options = TestUtilities.GetOptions(nameof(GetAllCommentsForCocktailCorrectly)); 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 cocktail = new Cocktail() { Name = "Name", Id = "1", Motto = "Motto", PicUrl = "Pic", }; var cocktailComment = new CocktailComment { CocktailId = "1", Description = "description", CreatedOn = DateTime.Now, }; var cocktailComment2 = new CocktailComment { CocktailId = "1", Description = "description", CreatedOn = DateTime.Now, }; //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(); await actContext.CocktailComments.AddAsync(cocktailComment); await actContext.CocktailComments.AddAsync(cocktailComment2); 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.GetAllCommentsForCocktail("1"); Assert.AreEqual(2, result.Count); } }
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 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); } }
public async Task EditCocktailAsyncEditsCorrectly() { //Arrange var options = TestUtilities.GetOptions(nameof(EditCocktailAsyncEditsCorrectly)); 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 cocktailDTO = new CocktailDTO() { Id = "1", Name = "name2", PicUrl = "picture2", Motto = "motto2", }; var cocktail = new Cocktail() { Id = "1", Name = "name", PicUrl = "picture", Motto = "motto" }; //Act using (var actContext = new IriOnCocktailServiceDbContext(options)) { actContext.Cocktails.Add(cocktail); await actContext.SaveChangesAsync(); var sut = new CocktailService(actContext, ingredientServiceMock.Object, cocktailMapperMock.Object, cocktailMapperToDTOMock.Object, commentMapperToDTOMock.Object, commentMapperMock.Object, addCocktailMapperMock.Object, cocktailRatingToDTOMock.Object); await sut.EditCocktailAsync(cocktailDTO); } using (var assertContext = new IriOnCocktailServiceDbContext(options)) { Assert.AreEqual(cocktailDTO.Name, cocktail.Name); Assert.AreEqual(cocktailDTO.PicUrl, cocktail.PicUrl); Assert.AreEqual(cocktailDTO.Motto, cocktail.Motto); } }
public async Task AddsCorrectly() { var options = TestUtilities.GetOptions(nameof(AddsCorrectly)); var bar = new Bar() { Id = "1", Name = "Bar", }; var cocktail = new Cocktail() { Id = "1", Name = "Cocktail", }; var cocktail2 = new Cocktail() { Id = "2", Name = "Cocktail2", }; var cocktailIds = new List <string>(); cocktailIds.Add(cocktail.Id); cocktailIds.Add(cocktail2.Id); using (var actContext = new IriOnCocktailServiceDbContext(options)) { await actContext.Cocktails.AddAsync(cocktail); await actContext.Cocktails.AddAsync(cocktail2); await actContext.Bars.AddAsync(bar); await actContext.SaveChangesAsync(); var sut = new BarCocktailsService(actContext); await sut.Add(cocktailIds, bar.Id); } using (var assertContext = new IriOnCocktailServiceDbContext(options)) { Assert.AreEqual(2, assertContext.CocktailBars.Where(cb => cb.BarId == bar.Id).Count()); } }
public async Task GetIngredientReturnsCorrectValue() { var options = TestUtilities.GetOptions(nameof(GetIngredientReturnsCorrectValue)); var mapToDTOMock = new Mock <IDTOServiceMapper <Ingredient, IngredientDTO> >(); var mapToEntityMock = new Mock <IDTOServiceMapper <IngredientDTO, Ingredient> >(); var ingredientDTOMock = new Mock <IngredientDTO>(); var ingredient = new Ingredient() { Name = "Chubaka", Id = "1", }; var ingredientDTO = new IngredientDTO() { Name = "Chubaka", Id = "1", }; mapToDTOMock.Setup(m => m.MapFrom(It.IsAny <Ingredient>())).Returns(ingredientDTO); using (var actContext = new IriOnCocktailServiceDbContext(options)) { await actContext.Ingredients.AddAsync(ingredient); await actContext.SaveChangesAsync(); } using (var assertContext = new IriOnCocktailServiceDbContext(options)) { var sut = new IngredientService(assertContext, mapToDTOMock.Object, mapToEntityMock.Object); var dto = await sut.GetIngredientDTO("1"); Assert.AreEqual("1", dto.Id); Assert.AreEqual("Chubaka", dto.Name); } }
public async Task GetAllContainedCocktailsDTOCorrectly() { var options = TestUtilities.GetOptions(nameof(GetAllContainedCocktailsDTOCorrectly)); 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 bar = new Bar() { Id = "1", Name = "name", Address = "address", Motto = "motto", PicUrl = "picture", }; var cocktail = new Cocktail() { Name = "Name", Id = "1", Motto = "Motto", PicUrl = "Pic", }; var cocktail2 = new Cocktail() { Name = "Name", Id = "2", Motto = "Motto", PicUrl = "Pic", }; var cocktailBar = new CocktailBar { CocktailId = "1", BarId = "1", }; var cocktailBar2 = new CocktailBar { CocktailId = "2", BarId = "1", }; //Act //cocktailMapperMock.Setup(m => m.MapFrom(It.IsAny<Cocktail>())).Returns(cocktailDTO); using (var actContext = new IriOnCocktailServiceDbContext(options)) { await actContext.Bars.AddAsync(bar); await actContext.Cocktails.AddAsync(cocktail); await actContext.Cocktails.AddAsync(cocktail2); await actContext.SaveChangesAsync(); await actContext.CocktailBars.AddAsync(cocktailBar); await actContext.CocktailBars.AddAsync(cocktailBar2); 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.GetAllContainedCocktailsDTO("1"); Assert.AreEqual(2, result.Count); } }