Exemple #1
0
        public void AddRestaurantShouldSaveRestaurantInDb()
        {
            //arrange
            var restaurantPoco = new RestaurantPoco
            {
                WebsiteUrl            = "website url",
                MenuUrl               = "menu url",
                Name                  = "name",
                Phone                 = "1234356",
                IsActive              = true,
                FreeShippingThreshold = 543.24,
                ShippingRate          = 14.56
            };

            _mapper.Setup(m => m.MapToPoco(It.IsAny <Restaurant>())).Returns(restaurantPoco);

            //act
            var id = _repo.AddRestaurant(new Restaurant());

            //assert
            var addedRestaurant = _databaseFixture.Db.SingleOrDefault <RestaurantPoco>("SELECT * FROM Restaurants WHERE Id = @0", id);

            _mapper.Verify(m => m.MapToPoco(It.IsAny <Restaurant>()), Times.Once);
            Assert.NotNull(addedRestaurant);
            Assert.Equal(restaurantPoco.WebsiteUrl, addedRestaurant.WebsiteUrl);
            Assert.Equal(restaurantPoco.MenuUrl, addedRestaurant.MenuUrl);
            Assert.Equal(restaurantPoco.Name, addedRestaurant.Name);
            Assert.Equal(restaurantPoco.Phone, addedRestaurant.Phone);
            Assert.Equal(restaurantPoco.IsActive, addedRestaurant.IsActive);
            Assert.Equal(restaurantPoco.FreeShippingThreshold, addedRestaurant.FreeShippingThreshold);
            Assert.Equal(restaurantPoco.ShippingRate, addedRestaurant.ShippingRate);
        }
Exemple #2
0
        public void RestaurantPocoShouldBeMappedToRestaurant()
        {
            //Arrange
            var restaurantPoco = new RestaurantPoco();

            restaurantPoco.ID                    = 1;
            restaurantPoco.IsActive              = true;
            restaurantPoco.MenuUrl               = "http://menumock.url";
            restaurantPoco.WebsiteUrl            = "http://mock.url";
            restaurantPoco.Name                  = "MockName";
            restaurantPoco.Phone                 = "123456789";
            restaurantPoco.ShippingRate          = 14.54;
            restaurantPoco.FreeShippingThreshold = 124.53;

            //Act
            var restaurant = _restaurantMapper.MapToDomain(restaurantPoco);

            //Assert
            Assert.Equal(restaurant.ID, restaurantPoco.ID);
            Assert.Equal(restaurant.IsActive, restaurantPoco.IsActive);
            Assert.Equal(restaurant.MenuUrl, restaurantPoco.MenuUrl);
            Assert.Equal(restaurant.WebsiteUrl, restaurantPoco.WebsiteUrl);
            Assert.Equal(restaurant.Name, restaurantPoco.Name);
            Assert.Equal(restaurant.Phone, restaurantPoco.Phone);
            Assert.IsType <Restaurant>(restaurant);
        }
Exemple #3
0
        public void AddOrderShouldAddOrderToDb()
        {
            IList <OrderedMealPoco> orderedMeals = new List <OrderedMealPoco>()
            {
                new OrderedMealPoco
                {
                    MealName      = "meal name",
                    Price         = 14.2,
                    PurchaserName = "purchaser name",
                }
            };
            RestaurantPoco restaurant = new RestaurantPoco()
            {
                ID         = 1,
                IsActive   = true,
                MenuUrl    = "menu url",
                Name       = "name",
                Phone      = "123445670",
                WebsiteUrl = "website url"
            };
            //arrange
            var orderPocoBeforDbInsert = new OrderPoco
            {
                AccountNumber         = "1324564362367",
                Deadline              = new DateTime(2016, 01, 28, 12, 00, 00),
                EstimatedDeliveryTime = new DateTime(2016, 01, 28, 13, 00, 00),
                OrderedMeals          = orderedMeals,
                Owner        = "owner",
                RestaurantId = restaurant.ID,
                StatusId     = (int)OrderStatus.InProgress
            };

            _orderMapper.Setup(m => m.MapToPoco(It.IsAny <Order>())).Returns(orderPocoBeforDbInsert);
            //act
            var newOrderId = _repo.AddOrder(new Order());

            //assert
            var orderFromDb = GetOrderPocoFromDbById(newOrderId);

            Assert.NotNull(orderFromDb);
            Assert.Equal(orderPocoBeforDbInsert.Deadline, orderFromDb.Deadline);
            Assert.Equal(orderPocoBeforDbInsert.EstimatedDeliveryTime, orderFromDb.EstimatedDeliveryTime);
            Assert.Equal(orderPocoBeforDbInsert.OrderedMeals.Count, orderFromDb.OrderedMeals.Count);
            Assert.Equal(orderPocoBeforDbInsert.OrderedMeals.First().Price, orderFromDb.OrderedMeals.First().Price);
            Assert.Equal(orderPocoBeforDbInsert.Owner, orderFromDb.Owner);
            Assert.Equal(orderPocoBeforDbInsert.StatusId, orderFromDb.Status.Id);
            Assert.Equal(orderPocoBeforDbInsert.RestaurantId, orderFromDb.Restaurant.ID);
        }
Exemple #4
0
        public void GetRestaurantShouldCallRestaurantMapperWithValidArgument()
        {
            //arrange
            var restaurantPoco =
                _databaseFixture.Db
                .Query <RestaurantPoco>("SELECT * FROM Restaurants WHERE Active = 1").First();
            var restaurant = new Restaurant
            {
                ID                    = restaurantPoco.ID,
                IsActive              = false,
                MenuUrl               = "nowe menu url",
                WebsiteUrl            = "nowy website url",
                Name                  = "nowy name",
                Phone                 = "12345676",
                ShippingRate          = 123.67,
                FreeShippingThreshold = 2345435634.76
            };

            _mapper.Setup(m => m.MapToDomain(It.IsAny <RestaurantPoco>())).Returns(restaurant);
            RestaurantPoco mapperArgument = new RestaurantPoco();

            _mapper.Setup(c => c.MapToDomain(It.IsAny <RestaurantPoco>()))
            .Callback <RestaurantPoco>(o => mapperArgument = o)
            .Returns(new Restaurant());

            //act
            var restaurantFromRepo = _repo.GetRestaurant(restaurantPoco.ID);

            //assert
            Assert.NotNull(restaurantFromRepo);
            Assert.Equal(restaurantPoco.ID, mapperArgument.ID);
            Assert.Equal(restaurantPoco.WebsiteUrl, mapperArgument.WebsiteUrl);
            Assert.Equal(restaurantPoco.MenuUrl, mapperArgument.MenuUrl);
            Assert.Equal(restaurantPoco.Name, mapperArgument.Name);
            Assert.Equal(restaurantPoco.Phone, mapperArgument.Phone);
            Assert.Equal(restaurantPoco.IsActive, mapperArgument.IsActive);
            Assert.Equal(restaurantPoco.FreeShippingThreshold, mapperArgument.FreeShippingThreshold);
            Assert.Equal(restaurantPoco.ShippingRate, mapperArgument.ShippingRate);
        }
Exemple #5
0
        public void EditRestaurantShouldUpdateRestaurantInDb()
        {
            //arrange
            var restaurantId          = _databaseFixture.Db.Query <RestaurantPoco>("SELECT * FROM Restaurants").First().ID;
            var updatedRestaurantPoco = new RestaurantPoco
            {
                ID                    = restaurantId,
                IsActive              = false,
                MenuUrl               = "nowe menu url",
                WebsiteUrl            = "nowy website url",
                Name                  = "nowy name",
                Phone                 = "12345676",
                ShippingRate          = 123.67,
                FreeShippingThreshold = 2345435634.76
            };

            _mapper.Setup(m => m.MapToPoco(It.IsAny <Restaurant>())).Returns(updatedRestaurantPoco);
            //act
            _repo.EditRestaurant(new Restaurant()
            {
                ID = restaurantId
            });

            //assert
            var updatedRestaurant =
                _databaseFixture.Db
                .Query <RestaurantPoco>("SELECT * FROM Restaurants WHERE Id = @0", restaurantId)
                .FirstOrDefault();

            Assert.NotNull(updatedRestaurant);
            Assert.Equal(updatedRestaurantPoco.WebsiteUrl, updatedRestaurant.WebsiteUrl);
            Assert.Equal(updatedRestaurantPoco.MenuUrl, updatedRestaurant.MenuUrl);
            Assert.Equal(updatedRestaurantPoco.Name, updatedRestaurant.Name);
            Assert.Equal(updatedRestaurantPoco.Phone, updatedRestaurant.Phone);
            Assert.Equal(updatedRestaurantPoco.IsActive, updatedRestaurant.IsActive);
            Assert.Equal(updatedRestaurantPoco.FreeShippingThreshold, updatedRestaurant.FreeShippingThreshold);
            Assert.Equal(updatedRestaurantPoco.ShippingRate, updatedRestaurant.ShippingRate);
        }
Exemple #6
0
        private static void InsertRestaurants(Database db)
        {
            List <RestaurantPoco> restaurantPocos = new List <RestaurantPoco>();

            for (int i = 0; i < 10; i++)
            {
                var r = new RestaurantPoco
                {
                    IsActive   = i % 2 == 0,
                    MenuUrl    = "http://restauracja" + i + ".pl/menu",
                    WebsiteUrl = "http://restauracja" + i + ".pl",
                    Name       = "restauracja " + i,
                    Phone      = string.Concat(Enumerable.Repeat(i.ToString(), 9))
                };
                restaurantPocos.Add(r);
                //db.Execute(@"INSERT INTO [Restaurants] ([Id],[Name],[Phone],[Url],[MenuUrl],[Active]) VALUES (1,N'Restauracja Michała',N'123456789',N'url',N'menu url',1);");
            }

            foreach (var restaurantPoco in restaurantPocos)
            {
                db.Insert(restaurantPoco);
            }
        }
Exemple #7
0
        public OrderPoco MapIt(OrderPoco order, OrderedMealPoco orderedMeal, StatusPoco status, RestaurantPoco restaurant)
        {
            // Terminating call.  Since we can return null from this function
            // we need to be ready for PetaPoco to callback later with null
            // parameters
            if (order == null)
            {
                return(_currentOrder);
            }

            // Is this the same author as the current one we're processing
            if (_currentOrder != null && _currentOrder.Id == order.Id)
            {
                // Yes, just add this post to the current author's collection of posts
                _currentOrder.OrderedMeals.Add(orderedMeal);

                // Return null to indicate we're not done with this author yet
                return(null);
            }


            // This is a different author to the current one, or this is the
            // first time through and we don't have an author yet

            // Save the current author
            var previousOrder = _currentOrder;

            // Setup the new current author
            _currentOrder = order;
            _currentOrder.OrderedMeals = new List <OrderedMealPoco>();
            if (orderedMeal.OrderId == order.Id)
            {
                _currentOrder.OrderedMeals.Add(orderedMeal);
            }
            if (status.Id == order.StatusId)
            {
                _currentOrder.Status = status;
            }
            if (restaurant.ID == order.RestaurantId)
            {
                _currentOrder.Restaurant = restaurant;
            }
            // Return the now populated previous author (or null if first time through)
            return(previousOrder);
        }