public async Task CocktailCommentAsync_ThrowsWhenNull() { //Arrange var options = TestUtilities.GetOptions(nameof(CocktailCommentAsync_ThrowsWhenNull)); 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> >(); //Act var CommentDTOMock = new Mock <CommentDTO>(); //commentMapperToDTOMock.Setup(m => m.MapFrom(It.IsAny<CommentDTO>())).Returns(null); using (var actContext = new IriOnCocktailServiceDbContext(options)) { var sut = new CocktailService(actContext, ingredientServiceMock.Object, cocktailMapperMock.Object, cocktailMapperToDTOMock.Object, commentMapperToDTOMock.Object, commentMapperMock.Object, addCocktailMapperMock.Object, cocktailRatingToDTOMock.Object); await Assert.ThrowsExceptionAsync <ArgumentException>(() => sut.CocktailCommentAsync(CommentDTOMock.Object)); } }
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 CreateIngredientCorrectly() { var options = TestUtilities.GetOptions(nameof(CreateIngredientCorrectly)); 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", }; mapToEntityMock.Setup(m => m.MapFrom(ingredientDTOMock.Object)).Returns(ingredient); using (var actContext = new IriOnCocktailServiceDbContext(options)) { var sut = new IngredientService(actContext, mapToDTOMock.Object, mapToEntityMock.Object); await sut.CreateIngredient(ingredientDTOMock.Object); } using (var assertContext = new IriOnCocktailServiceDbContext(options)) { Assert.AreEqual(1, assertContext.Ingredients.Count()); } }
public async Task CreateCocktailCorrectly() { //Arrange var options = TestUtilities.GetOptions(nameof(CreateCocktailCorrectly)); 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 cocktailDTOMock = new Mock <CocktailDTO>(); var cocktailIngredientDTOMock = new Mock <List <CocktailIngredientDTO> >(); var cocktailMock = new Mock <Cocktail>(); cocktailDTOMock.Object.Ingredients = cocktailIngredientDTOMock.Object; //Act cocktailMapperToDTOMock.Setup(m => m.MapFrom(It.IsAny <CocktailDTO>())).Returns(cocktailMock.Object); using (var actContext = new IriOnCocktailServiceDbContext(options)) { var sut = new CocktailService(actContext, ingredientServiceMock.Object, cocktailMapperMock.Object, cocktailMapperToDTOMock.Object, commentMapperToDTOMock.Object, commentMapperMock.Object, addCocktailMapperMock.Object, cocktailRatingToDTOMock.Object); await sut.CreateCocktail(cocktailDTOMock.Object); } using (var assertContext = new IriOnCocktailServiceDbContext(options)) { Assert.AreEqual(1, assertContext.Cocktails.Count()); } }
public IngredientService(IriOnCocktailServiceDbContext context, IDTOServiceMapper <Ingredient, IngredientDTO> mapper, IDTOServiceMapper <IngredientDTO, Ingredient> mapToEntity) { this.context = context; this.mapper = mapper; this.mapToEntity = mapToEntity; }
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 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 GetIngredientThrowsCorrectMsg() { var options = TestUtilities.GetOptions(nameof(GetIngredientThrowsWhenNull)); var mapToDTOMock = new Mock <IDTOServiceMapper <Ingredient, IngredientDTO> >(); var mapToEntityMock = new Mock <IDTOServiceMapper <IngredientDTO, Ingredient> >(); using (var assertContext = new IriOnCocktailServiceDbContext(options)) { var sut = new IngredientService(assertContext, mapToDTOMock.Object, mapToEntityMock.Object); await Assert.ThrowsExceptionAsync <ArgumentException>(() => sut.GetIngredientDTO("1"), GlobalConstants.UnavailbleIngredient); } }
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 GetAllIngredientsThrowsCorrectMsgWhenNoIngredientsFound() { var options = TestUtilities.GetOptions(nameof(GetAllIngredientsThrowsCorrectMsgWhenNoIngredientsFound)); var mapToDTOMock = new Mock <IDTOServiceMapper <Ingredient, IngredientDTO> >(); var mapToEntityMock = new Mock <IDTOServiceMapper <IngredientDTO, Ingredient> >(); mapToDTOMock.Setup(m => m.MapFrom(It.IsAny <Ingredient>())).Returns(It.IsAny <IngredientDTO>()); using (var assertContext = new IriOnCocktailServiceDbContext(options)) { var sut = new IngredientService(assertContext, mapToDTOMock.Object, mapToEntityMock.Object); await Assert.ThrowsExceptionAsync <ArgumentException>(() => sut.GetAllIngredients()); } }
public BarService(IriOnCocktailServiceDbContext context, IDTOServiceMapper <Bar, BarDTO> mapper, IDTOServiceMapper <BarDTO, Bar> mapperFromEntity, IDTOServiceMapper <ICollection <Bar>, ICollection <BarDTO> > barsMapper, IDTOServiceMapper <CommentDTO, BarComment> barCommentMapper, IDTOServiceMapper <BarComment, CommentDTO> barCommentDTOMapper, IDTOServiceMapper <RatingDTO, BarRating> barRatingMapper) { this.context = context; this.mapper = mapper; this.mapperFromEntity = mapperFromEntity; this.barsMapper = barsMapper; this.barCommentMapper = barCommentMapper; this.barCommentDTOMapper = barCommentDTOMapper; this.barRatingMapper = barRatingMapper; }
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 CocktailService(IriOnCocktailServiceDbContext context, ICocktailIngredientService cocktailIngredientService, IDTOServiceMapper <Cocktail, CocktailDTO> mapper, IDTOServiceMapper <CocktailDTO, Cocktail> cocktailMapper, IDTOServiceMapper <CommentDTO, CocktailComment> cocktailCommentMapper, IDTOServiceMapper <CocktailComment, CommentDTO> cocktailCommentDTOMapper, IDTOServiceMapper <Cocktail, AddCocktailDTO> addCocktailMapper, IDTOServiceMapper <RatingDTO, CocktailRating> cocktailRatingMapper) { this.context = context; this.cocktailIngredientService = cocktailIngredientService; this.mapper = mapper; this.cocktailMapper = cocktailMapper; this.cocktailCommentMapper = cocktailCommentMapper; this.cocktailCommentDTOMapper = cocktailCommentDTOMapper; this.addCocktailMapper = addCocktailMapper; this.cocktailRatingMapper = cocktailRatingMapper; }
public async Task GetCocktailDTO_ThrowsCorrectMsgWhenNull() { var options = TestUtilities.GetOptions(nameof(GetCocktailDTO_ThrowsCorrectMsgWhenNull)); 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> >(); 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 <ArgumentException>(() => sut.GetCocktailDTO("1"), GlobalConstants.UnavailableCocktail); } }
public async Task CreateCocktail_ThrowWhenDTOIsNull() { //Arrange var options = TestUtilities.GetOptions(nameof(CreateCocktail_ThrowWhenDTOIsNull)); 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> >(); using (var actContext = new IriOnCocktailServiceDbContext(options)) { var sut = new CocktailService(actContext, ingredientServiceMock.Object, cocktailMapperMock.Object, cocktailMapperToDTOMock.Object, commentMapperToDTOMock.Object, commentMapperMock.Object, addCocktailMapperMock.Object, cocktailRatingToDTOMock.Object); await Assert.ThrowsExceptionAsync <ArgumentException>(() => sut.CreateCocktail(null)); } }
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 GetAllCocktailsDTO_ThrowsWhenNoResultsFound() { var options = TestUtilities.GetOptions(nameof(GetAllCocktailsDTO_ThrowsWhenNoResultsFound)); 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>()); 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()); } }
public RoleService(IriOnCocktailServiceDbContext context, UserManager <User> roleManager, IDTOServiceMapper <User, UserDTO> userDTOMapper) { this.context = context; this.userManager = roleManager; this.userDTOMapper = userDTOMapper; }
public CocktailIngredientService(IriOnCocktailServiceDbContext context, IDTOServiceMapper <CocktailIngredientDTO, CocktailIngredient> cocktailIngredientMapper) { this.context = context; this.cocktailIngredientMapper = cocktailIngredientMapper; }
public BarCocktailsService(IriOnCocktailServiceDbContext context) { this.context = context; }
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); } }