public IHttpActionResult Get()
        {
            var pizzas = new PizzaList(this._repository);
            IEnumerable <PizzaItemDto> pizzasList;
            string userName = User.Identity.Name;

            pizzasList = pizzas.GetPizzasListByUserFullName(userName);

            return(Ok <IEnumerable <PizzaItemDto> >(pizzasList));
        }
Пример #2
0
        public void GetPizzasListByUserFullName_ExistingUserName_ReturnsListOfPizzas()
        {
            var              mock       = new Mock <IPizzaRepository>();
            string           name       = "John";
            List <PizzaItem> pizzaItems = new List <PizzaItem>()
            {
                new PizzaItem()
                {
                    Order = new Order(new Guid(), 1, new Contact(), new User("John", "John`s email"))
                },
                new PizzaItem()
                {
                    Order = new Order(new Guid(), 2, new Contact(), new User("John", "John`s email"))
                },
                new PizzaItem()
                {
                    Order = new Order(new Guid(), 3, new Contact(), new User("John", "John`s email"))
                },
                new PizzaItem()
                {
                    Order = new Order(new Guid(), 4, new Contact(), new User("Sam", "John`s email"))
                },
                new PizzaItem()
                {
                    Order = new Order(new Guid(), 5, new Contact(), new User("Sam", "John`s email"))
                },
                new PizzaItem()
                {
                    Order = new Order(new Guid(), 6, new Contact(), new User("Sam", "John`s email"))
                },
                new PizzaItem()
                {
                    Order = new Order(new Guid(), 7, new Contact(), new User("John", "John`s email"))
                }
            };

            mock.Setup(moq => moq.GetList(It.IsAny <Expression <Func <PizzaItem, bool> > >())).Returns(pizzaItems.Where(p => p.Order.User.Name == name));

            PizzaList pizzaList = new PizzaList(mock.Object);
            int       expected  = 4;

            int actual = pizzaList.GetPizzasListByUserFullName(name).Count;

            Assert.IsNotNull(actual);
            Assert.AreEqual(expected, actual);
        }