public async Task Delete_Cocktail_Correctly() { //Arrange var options = TestUtilities.GetOptions(nameof(Delete_Cocktail_Correctly)); var mockCocktailDtoMapper = new Mock <IDtoMapper <Cocktail, CocktailDto> >(); var mockCocktailIngretientService = new Mock <ICocktailIngredientService>(); var mockIngredientsService = new Mock <IIngredientService>(); var mockDateTimeProvider = new Mock <IDateTimeProvider>(); var cocktail = new Cocktail { Id = 1, Name = "TestCocktail", }; using (var arrangeContext = new CocktailMagicianContext(options)) { await arrangeContext.Cocktails.AddAsync(cocktail); await arrangeContext.SaveChangesAsync(); var cocktailService = new CocktailService(arrangeContext, mockCocktailDtoMapper.Object, mockDateTimeProvider.Object, mockCocktailIngretientService.Object, mockIngredientsService.Object); var result = await cocktailService.DeleteCocktailAsync(1); } //Act and Assert using (var assertContext = new CocktailMagicianContext(options)) { var deletedCocktail = await assertContext.Cocktails.FirstAsync(); Assert.IsTrue(deletedCocktail.IsDeleted); } }
public async Task Throw_When_NoCocktailFoun() { //Arrange var options = TestUtilities.GetOptions(nameof(Throw_When_NoCocktailFoun)); var mockCocktailDtoMapper = new Mock <IDtoMapper <Cocktail, CocktailDto> >(); var mockCocktailIngretientService = new Mock <ICocktailIngredientService>(); var mockIngredientsService = new Mock <IIngredientService>(); var mockDateTimeProvider = new Mock <IDateTimeProvider>(); //Act and Assert using (var assertContext = new CocktailMagicianContext(options)) { var sut = new CocktailService(assertContext, mockCocktailDtoMapper.Object, mockDateTimeProvider.Object, mockCocktailIngretientService.Object, mockIngredientsService.Object); await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.DeleteCocktailAsync(1)); } }
public async Task DeleteCocktail_Should() { //Arrange var mockDateTimeProvider = new Mock <IDateTimeProvider>(); var mockMapper = new Mock <ICocktailMapper>(); var mockIngMapper = new Mock <IngredientMapper>(); var mockBarMapper = new Mock <IBarMapper>(); var mockCocktailReviewService = new Mock <ICocktailReviewService>(); var options = Utils.GetOptions(nameof(DeleteCocktail_Should)); Utils.GetInMemoryDataBase(options); //Act & Assert using (var assertContex = new CocktailMagicianContext(options)) { var sut = new CocktailService(mockDateTimeProvider.Object, mockMapper.Object, mockIngMapper.Object, mockBarMapper.Object, assertContex, mockCocktailReviewService.Object); var result = await sut.DeleteCocktailAsync(2); Assert.IsTrue(result); } }
public async Task DeleteCocktailAsyncDeleteCorrectly() { //Arrange var options = TestUtilities.GetOptions(nameof(DeleteCocktailAsyncDeleteCorrectly)); 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() { 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.DeleteCocktailAsync("1"); } using (var assertContext = new IriOnCocktailServiceDbContext(options)) { Assert.AreEqual(true, cocktail.NotAvailable); } }