コード例 #1
0
        public IHttpActionResult GetPizzasByUserId()
        {
            PizzaService pizzaService = CreatePizzaService();
            var          pizza        = pizzaService.GetPizzasByUserId(GetUserIdByGuid());

            return(Ok(pizza));
        }
コード例 #2
0
        public IHttpActionResult GetPizzaByPizzaId(PizzaDetail pizzaId)
        {
            PizzaService pizzaService = CreatePizzaService();
            var          pizza        = pizzaService.GetPizzaByPizzaId(pizzaId.PizzaId);

            return(Ok(pizza));
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        private PizzaService CreatePizzaService()
        {
            var userId       = GetUserIdByGuid();
            var pizzaService = new PizzaService(userId);

            return(pizzaService);
        }
コード例 #5
0
        public IHttpActionResult GetPizzas()
        {
            PizzaService pizzaService = CreatePizzaService();
            var          pizzas       = pizzaService.GetAllPizzas();

            return(Ok(pizzas));
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        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();
        }
コード例 #8
0
        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();
        }
コード例 #9
0
ファイル: MainWindow.xaml.cs プロジェクト: halllo/StpNtp
 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();
 }
コード例 #10
0
        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());
        }
コード例 #11
0
        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);
            }
        }
コード例 #12
0
        // 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));
        }
コード例 #13
0
        public IActionResult crearPizza(string nombre, double precio)
        {
            Pizza pizza = new Pizza();

            pizza.nombre = nombre;
            pizza.precio = precio;
            PizzaService.Save(pizza);
            return(Ok());
        }
コード例 #14
0
 public PizzaChangeDeliveryAddressSteps(
     PizzaService pizzaService,
     AddressFactory addressFactory,
     CustomerFactory customerFactory)
 {
     _pizzaService    = pizzaService;
     _addressFactory  = addressFactory;
     _customerFactory = customerFactory;
 }
コード例 #15
0
        static public void listarPizzas()
        {
            List <Pizza> pizza = PizzaService.GetAll();

            foreach (var p in pizza)
            {
                Console.WriteLine(p.id.ToString() + "- " + p.nombre);
            }
        }
コード例 #16
0
        public ActionResult <Pizza> Get(int id)
        {
            var pizza = PizzaService.Get(id);

            if (pizza == null)
            {
                return(NotFound());
            }
            return(pizza);
        }
コード例 #17
0
        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));
        }
コード例 #18
0
ファイル: PizzaController.cs プロジェクト: ribeiro-dev/WebAPI
        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());
        }
コード例 #19
0
 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);
     });
 }
コード例 #20
0
        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));
        }
コード例 #21
0
        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);
        }
コード例 #22
0
        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);
        }
コード例 #23
0
        public IActionResult Delete(int id)
        {
            var pizza = PizzaService.Get(id);

            if (pizza is null)
            {
                return(NotFound());
            }

            PizzaService.Delete(id);

            return(NoContent());
        }
コード例 #24
0
        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();
        }
コード例 #25
0
        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());
        }
コード例 #26
0
        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();
        }
コード例 #27
0
        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>));
        }
コード例 #28
0
        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)));
            });
            // ...
        }
コード例 #29
0
        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());
        }
コード例 #30
0
        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());
        }
コード例 #31
0
        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();
        }
コード例 #32
0
 public PizzaController()
 {
     _urlBase = ConfigurationManager.AppSettings["UrlPrincipalRaiz"] + @"/api/pizza/";
     _pizzaService = new PizzaService();
 }
コード例 #33
0
ファイル: MainWindow.xaml.cs プロジェクト: halllo/StpNtp
 public BestellungViewModel(PizzaService.BestellungEntity bestellung)
 {
     Datum = bestellung.Datum;
     Name = bestellung.Besteller;
     Gesamtpreis = bestellung.Pizzen.Sum(p => p.Pizza.Preis);
 }
コード例 #34
0
ファイル: MainWindow.xaml.cs プロジェクト: halllo/StpNtp
 public PizzaViewModel(PizzaService.PizzaEntity pizza)
 {
     Id = pizza.Id;
     Name = pizza.Name;
     Preis = pizza.Preis;
     Zutaten = Arrayify(pizza.Zutaten);
 }