public IHttpActionResult GetPizzasByUserId() { PizzaService pizzaService = CreatePizzaService(); var pizza = pizzaService.GetPizzasByUserId(GetUserIdByGuid()); return(Ok(pizza)); }
public IHttpActionResult GetPizzaByPizzaId(PizzaDetail pizzaId) { PizzaService pizzaService = CreatePizzaService(); var pizza = pizzaService.GetPizzaByPizzaId(pizzaId.PizzaId); return(Ok(pizza)); }
public async Task GetPizzaById() { int expectedId = 1; PizzaModel expectedPizza = (await GetPizzaById(expectedId)).Single(); pizzaRepoMock.Setup(x => x.GetByExpressionAsync(It.IsAny <Expression <Func <PizzaModel, bool> > >(), It.IsAny <Func <IQueryable <PizzaModel>, IIncludableQueryable <PizzaModel, object> > >())).Returns(GetPizzaById(expectedId)); uowMock.Setup(x => x.Pizzas).Returns(pizzaRepoMock.Object); // create instance of service IPizzaService service = new PizzaService(uowMock.Object); // call function to test IServiceResult <PizzaToReturnDto> result = await service.GetByIdAsync(expectedId); // asserts Assert.AreEqual(ResultType.Correct, result.Result); Assert.IsNotNull(result.ReturnedObject); Assert.AreEqual(expectedPizza.Id, result.ReturnedObject.Id); Assert.AreEqual(expectedPizza.Name.ToLower(), result.ReturnedObject.Name.ToLower()); Assert.AreEqual(expectedPizza.PizzaIngredients.Count + 3, result.ReturnedObject.Ingredients.Count); Assert.AreEqual(expectedPizza.PizzaDetails.Count, result.ReturnedObject.TotalPrices.Count); // check of total price makes sure that also ingredients have correct prices for (int i = 0; i < expectedPizza.PizzaDetails.Count; i++) { Assert.AreEqual(expectedPizza.PizzaDetails.ElementAt(i).TotalPrice, result.ReturnedObject.TotalPrices.ElementAt(i).Price); } }
private PizzaService CreatePizzaService() { var userId = GetUserIdByGuid(); var pizzaService = new PizzaService(userId); return(pizzaService); }
public IHttpActionResult GetPizzas() { PizzaService pizzaService = CreatePizzaService(); var pizzas = pizzaService.GetAllPizzas(); return(Ok(pizzas)); }
static void Main(string[] args) { string sUrl = "http://files.olo.com/pizzas.json"; IEnumerable <PizzaCounts> finalList = null; var ps = new PizzaService(); try { finalList = ps.GetMostPopularToppings(sUrl, 20); } catch (Exception ex) { string msg = ex.Message; if (ex.InnerException != null) { msg += Environment.NewLine + ex.InnerException.Message; } Console.WriteLine("Exception thrown: " + ex.Message); } if (finalList != null) { int i = 0; foreach (var item in finalList) { i++; Console.WriteLine(i.ToString() + ". " + item.toppings + " - " + item.count); } } Console.ReadLine(); }
static void Main(string[] args) { FileHelper fileHelper = new FileHelper(); PizzaService pizzaService = new PizzaService(); Console.WriteLine("Please wait, processing ..."); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); List <PizzaTopping> top20Toppings = pizzaService.GetTop20Toppings( fileHelper.GetToppingsList()); stopWatch.Stop(); TimeSpan time = stopWatch.Elapsed; Console.Clear(); Console.WriteLine("TOP 20 RANKED MOST POPULAR PIZZA TOPPINGS:\n"); Console.WriteLine(" RANK | ORDERS | TOPPING"); Console.WriteLine(" -------------------------------\n"); var rank = 1; foreach (PizzaTopping item in top20Toppings) { Console.WriteLine($" {(rank++).ToString().PadLeft(2,'0')} {item.Rank.ToString().PadLeft(5, ' ')} {item.Toppings.ToDelimitedString()}"); } Console.WriteLine(" -------------------------------\n"); Console.WriteLine($"Elapsed time: {time.Milliseconds} milliseconds"); Console.ReadLine(); }
public void SetUp() { var getPizzaRepository = new Mock <IPizzaRepository>(); getPizzaRepository.Setup(x => x.GetAll()).Returns(new GetPizzasResponse { Pizzas = new List <PizzaRecord> { new PizzaRecord { Id = 1, Name = "Original" }, new PizzaRecord { Id = 2, Name = "Veggie Delight" } } }); var subject = new PizzaService(getPizzaRepository.Object); _result = subject.GetAll(); }
public BestellungViewModel(PizzaService.BestellungEntity bestellung) { Datum = bestellung.Datum; Name = bestellung.Besteller; Gesamtpreis = bestellung.Pizzen.Sum(p => p.Pizza.Preis); Pizzen = bestellung.Pizzen.Select(p => p.Pizza.Name + " (" + p.Pizza.Preis.ToString("C") + ")").OrderBy(p => p).ToList(); }
public async Task CreateNewPizzaWithTakenName() { PizzaToCreateDto expectedPizzaToCreate = new PizzaToCreateDto { Name = "TestPizza", IngredientIds = new List <int> { 1 } }; pizzaRepoMock.Setup(x => x.GetByExpressionAsync(It.IsAny <Expression <Func <PizzaModel, bool> > >(), It.IsAny <Func <IQueryable <PizzaModel>, IIncludableQueryable <PizzaModel, object> > >())).Returns(GetPizzaByName(expectedPizzaToCreate.Name)); uowMock.Setup(x => x.Pizzas).Returns(pizzaRepoMock.Object); IPizzaService service = new PizzaService(uowMock.Object); IServiceResult <PizzaToReturnDto> creationResult = await service.CreateAsync(expectedPizzaToCreate); Assert.AreEqual(ResultType.Error, creationResult.Result); Assert.IsNull(creationResult.ReturnedObject); Assert.IsNotNull(creationResult.Errors); Assert.AreEqual(1, creationResult.Errors.Count); Assert.AreEqual($"Pizza name: {expectedPizzaToCreate.Name} is already taken", creationResult.Errors.First()); }
public async Task DeleteIngredientFromPizzaCorrectly() { string expectedPizzaName = "TestPizza"; int expectedIdOfIngredient = 2; pizzaRepoMock.Setup(x => x.GetByExpressionAsync(It.IsAny <Expression <Func <PizzaModel, bool> > >(), It.IsAny <Func <IQueryable <PizzaModel>, IIncludableQueryable <PizzaModel, object> > >())).Returns(GetPizzaByName(expectedPizzaName)); pizzaRepoMock.Setup(x => x.Update(It.IsAny <PizzaModel>())); Mock <IFoodOrderRepository <IngredientModel> > ingredientRepoMock = new Mock <IFoodOrderRepository <IngredientModel> >(); ingredientRepoMock.Setup(x => x.GetByExpressionAsync(It.IsAny <Expression <Func <IngredientModel, bool> > >(), It.IsAny <Func <IQueryable <IngredientModel>, IIncludableQueryable <IngredientModel, object> > >())).Returns(GetExpectedIngredientById(expectedIdOfIngredient)); uowMock.Setup(x => x.Pizzas).Returns(pizzaRepoMock.Object); uowMock.Setup(x => x.Ingredients).Returns(ingredientRepoMock.Object); uowMock.Setup(x => x.SaveChangesAsync()); IPizzaService service = new PizzaService(uowMock.Object); IServiceResult <PizzaToReturnDto> result = await service.DeleteIngredientAsync(expectedPizzaName, expectedIdOfIngredient); Assert.AreEqual(ResultType.Edited, result.Result); Assert.IsNull(result.Errors); Assert.AreEqual(4, result.ReturnedObject.Ingredients.Count); for (int i = 0; i < result.ReturnedObject.TotalPrices.Count; i++) { Assert.AreEqual(expectedPizzas.First().PizzaDetails.ElementAt(i).TotalPrice, result.ReturnedObject.TotalPrices.ElementAt(i).Price); } }
// GET: Pizza public ActionResult Index() { List <Pizza> pizzas = PizzaService.GetAllPizzas(); ViewData["username"] = ((User)Session["user"]).Username; ViewData["isAdmin"] = ((User)Session["user"]).Role; return(View(pizzas)); }
public IActionResult crearPizza(string nombre, double precio) { Pizza pizza = new Pizza(); pizza.nombre = nombre; pizza.precio = precio; PizzaService.Save(pizza); return(Ok()); }
public PizzaChangeDeliveryAddressSteps( PizzaService pizzaService, AddressFactory addressFactory, CustomerFactory customerFactory) { _pizzaService = pizzaService; _addressFactory = addressFactory; _customerFactory = customerFactory; }
static public void listarPizzas() { List <Pizza> pizza = PizzaService.GetAll(); foreach (var p in pizza) { Console.WriteLine(p.id.ToString() + "- " + p.nombre); } }
public ActionResult <Pizza> Get(int id) { var pizza = PizzaService.Get(id); if (pizza == null) { return(NotFound()); } return(pizza); }
public IActionResult Index(IndexViewModel model, PizzaService service) { model.Pizzas = service.GetPizzaIEnumerable(); model.Orders = service.GetOrders(); model.BasicToppings = service.GetBasicToppings(); model.DeluxeToppings = service.GetDeluxeToppings(); return(View(model)); }
public IActionResult Update(int id, Pizza pizza) { var existingPizza = PizzaService.Get(id); if (id != pizza.Id || existingPizza is null) { return(BadRequest()); } PizzaService.Update(pizza); return(NoContent()); }
public void DeepCreate(Order order) { Create(order); order.GetPizzas().ToList().ForEach(pizza => { pizza.SetOrder(order); PizzaService.CreatePizza(pizza); }); order.GetBeverages().ToList().ForEach(beverage => { beverage.SetOrder(order); BeverageService.CreateBeverage(beverage); }); }
public async Task <ActionResult> Index() { var pizzaResult = await PizzaService.GetGroupedPizzas(); var model = new PizzaIndexViewModel() { Result = pizzaResult?.Take(20).ToList(), TotalOrders = pizzaResult != null?pizzaResult.Sum(x => x.Count) : 0 }; return(View(model)); }
public void GetPizzasById_Returns_Data(int id) { pizzaDalMock = new Mock <IPizzaDal>(); pizzaDalMock.Setup(i => i.GetPizzaById(id)).Returns(GetStaticPizza().FirstOrDefault()); _service = new PizzaService(pizzaDalMock.Object); // Act var result = _service.GetPizzaById(id); // Assert Assert.NotNull(result); }
public void AddCustomPizza_Returns_Data() { var pizza = CustomPizza(); pizzaDalMock = new Mock <IPizzaDal>(); pizzaDalMock.Setup(i => i.AddPizza(pizza)).Returns(Guid.NewGuid); _service = new PizzaService(pizzaDalMock.Object); // Act var result = _service.AddPizza(pizza); // Assert Assert.NotNull(result); }
public IActionResult Delete(int id) { var pizza = PizzaService.Get(id); if (pizza is null) { return(NotFound()); } PizzaService.Delete(id); return(NoContent()); }
private static void Main() { Console.WriteLine("Hello, please write your name:"); var name = Console.ReadLine(); Console.WriteLine("Hello, please write amount:"); var amount = double.Parse(Console.ReadLine()); var user = new UserService(new UserValidator()).CreateUser(name, amount); var pizzaService = new PizzaService(new PizzaValidator()); var menu = new Menu(pizzaService, user); menu.MakeOrder(); }
public void ReturnAllPizzas_WhenCalled() { // Arrange var pizzas = Helper.GetPizzas(); var contextMock = new Mock <IPizzaFactoryDbContext>(); var pizzaDbSetMock = QueryableDbSetMock.GetQueryableMockDbSet(pizzas); contextMock.Setup(ctx => ctx.Pizzas).Returns(pizzaDbSetMock.Object); IPizzaService pizzaService = new PizzaService(contextMock.Object); // Act var pizzasFound = pizzaService.GetAll(); // Assert Assert.AreEqual(pizzas.Count(), pizzasFound.Count()); }
static async Task Main() { var pizzaService = new PizzaService(); List <Pizza> AllPizzas = await pizzaService.GetPizzas(); Dictionary <string, int> TopPizzaConfigurations = pizzaService.GetTopPizzaConfigurations(AllPizzas); WriteLine(" - Top 20 Pizza configurations - "); WriteLine("Pizza Configuration | Order Count"); foreach (var pizza in TopPizzaConfigurations) { WriteLine($"{pizza.Key} | {pizza.Value}"); //TODO : Refactor to handle pinapple exception - kidding } ReadLine(); }
public void ReturnIEnumerableOfPizzaModels_WhenCalled() { // Arrange var pizzas = Helper.GetPizzas(); var contextMock = new Mock <IPizzaFactoryDbContext>(); var pizzaDbSetMock = QueryableDbSetMock.GetQueryableMockDbSet(pizzas); contextMock.Setup(ctx => ctx.Pizzas).Returns(pizzaDbSetMock.Object); IPizzaService pizzaService = new PizzaService(contextMock.Object); // Act var pizzasFound = pizzaService.GetAll(); // Assert Assert.IsInstanceOfType(pizzasFound, typeof(IEnumerable <PizzaModel>)); }
public override void Load() { Mapper.Initialize(cfg => cfg.AddProfiles(typeof(PizzaProfile))); var mapper = Mapper.Configuration.CreateMapper(); this.Bind <IMapper>().ToConstant(mapper); this.Bind <PizzaShopContext>().ToSelf(); this.Bind <IValidator <PizzaDto> >().To <PizzaDtoValidator>(); this.Bind <IPizzaService>().ToMethod(ctx => { var service = new PizzaService(ctx.Kernel.Get <PizzaShopContext>(), ctx.Kernel.Get <IMapper>()); return(new ProxyGenerator().CreateInterfaceProxyWithTarget <IPizzaService>(service, new ValidationInterceptor(ctx.Kernel))); }); // ... }
public async Task CountPriceOfNotExistingPizza() { 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 <PizzaModel> priceUpdateResult = await service.UpdatePriceAsync(expectedPizzaId); Assert.AreEqual(ResultType.Error, priceUpdateResult.Result); Assert.IsNull(priceUpdateResult.ReturnedObject); Assert.IsNotNull(priceUpdateResult.Errors); Assert.AreEqual($"Pizza with id {expectedPizzaId} was not found", priceUpdateResult.Errors.First()); }
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 void SetUp() { var getPizzaRepository = new Mock <IPizzaRepository>(); getPizzaRepository.Setup(x => x.GetAll()).Returns(new GetPizzasResponse { HasError = true, Error = new Error { UserMessage = "Something went wrong when retrieving PizzaRecords." } }); var subject = new PizzaService(getPizzaRepository.Object); _result = subject.GetAll(); }
public PizzaController() { _urlBase = ConfigurationManager.AppSettings["UrlPrincipalRaiz"] + @"/api/pizza/"; _pizzaService = new PizzaService(); }
public BestellungViewModel(PizzaService.BestellungEntity bestellung) { Datum = bestellung.Datum; Name = bestellung.Besteller; Gesamtpreis = bestellung.Pizzen.Sum(p => p.Pizza.Preis); }
public PizzaViewModel(PizzaService.PizzaEntity pizza) { Id = pizza.Id; Name = pizza.Name; Preis = pizza.Preis; Zutaten = Arrayify(pizza.Zutaten); }