public async Task DeleteNotExistingPizza() { int expectedPizzaId = 2; pizzaRepoMock.Setup(x => x.GetByExpressionAsync(It.IsAny <Expression <Func <PizzaModel, bool> > >(), It.IsAny <Func <IQueryable <PizzaModel>, IIncludableQueryable <PizzaModel, object> > >())).Returns(GetPizzaById(expectedPizzaId)); uowMock.Setup(x => x.Pizzas).Returns(pizzaRepoMock.Object); IPizzaService service = new PizzaService(uowMock.Object); IServiceResult deletionResult = await service.DeleteAsync(expectedPizzaId); Assert.AreEqual(ResultType.Error, deletionResult.Result); Assert.IsNotNull(deletionResult.Errors); Assert.AreEqual($"Cannot delete pizza with id {expectedPizzaId}", deletionResult.Errors.First()); }
public async Task DeletePizzaCorrectly() { int expectedPizzaId = 1; pizzaRepoMock.Setup(x => x.GetByExpressionAsync(It.IsAny <Expression <Func <PizzaModel, bool> > >(), It.IsAny <Func <IQueryable <PizzaModel>, IIncludableQueryable <PizzaModel, object> > >())).Returns(GetPizzaById(expectedPizzaId)); pizzaRepoMock.Setup(x => x.Delete(It.IsAny <PizzaModel>())); uowMock.Setup(x => x.Pizzas).Returns(pizzaRepoMock.Object); uowMock.Setup(x => x.SaveChangesAsync()).Returns(Task.FromResult(true)); IPizzaService service = new PizzaService(uowMock.Object); IServiceResult deletionResult = await service.DeleteAsync(expectedPizzaId); Assert.AreEqual(ResultType.Deleted, deletionResult.Result); Assert.IsNull(deletionResult.Errors); }