private static void InsertOrders(Database db, IEnumerable <RestaurantPoco> savedRestaurantPocos, IEnumerable <StatusPoco> statuses) { List <OrderPoco> orderPocos = new List <OrderPoco>(); foreach (var restaurantPoco in savedRestaurantPocos) { var o = new OrderPoco { AccountNumber = "111111111111111111", RestaurantId = restaurantPoco.ID, Deadline = DateTime.Now, EstimatedDeliveryTime = DateTime.Now, OrderedMeals = null, Owner = "user " + restaurantPoco.ID, StatusId = statuses.First().Id }; orderPocos.Add(o); } foreach (var orderPoco in orderPocos) { db.Insert(orderPoco); } var orders = db.Query <OrderPoco>("SELECT * FROM Orders"); AddOrderedMealsToOrders(db, orders); }
public void GetOrderShouldExecuteMapperWithCorrectData() { //arrange OrderPoco orderPocoFromDb = GetOrderPocoFromDbById(1); OrderPoco mapperArgument = new OrderPoco(); _orderMapper.Setup(c => c.MapToDomain(It.IsAny <OrderPoco>())) .Callback <OrderPoco>(o => mapperArgument = o) .Returns(new Order()); //act var orderFromRepo = _repo.GetOrder(orderPocoFromDb.Id); //assert _orderMapper.Verify(m => m.MapToDomain(It.IsAny <OrderPoco>()), Times.Once); Assert.Equal(orderPocoFromDb.Id, mapperArgument.Id); Assert.Equal(orderPocoFromDb.OrderedMeals.Count(), mapperArgument.OrderedMeals.Count()); Assert.Equal(orderPocoFromDb.Owner, mapperArgument.Owner); Assert.Equal(orderPocoFromDb.EstimatedDeliveryTime, mapperArgument.EstimatedDeliveryTime); Assert.Equal(orderPocoFromDb.Deadline, mapperArgument.Deadline); Assert.Equal(orderPocoFromDb.Status.Id, mapperArgument.Status.Id); Assert.Equal(orderPocoFromDb.Status.Name, mapperArgument.Status.Name); Assert.Equal(orderPocoFromDb.RestaurantId, mapperArgument.RestaurantId); Assert.Equal(orderPocoFromDb.Restaurant.ID, mapperArgument.Restaurant.ID); Assert.Equal(orderPocoFromDb.Restaurant.IsActive, mapperArgument.Restaurant.IsActive); Assert.Equal(orderPocoFromDb.Restaurant.MenuUrl, mapperArgument.Restaurant.MenuUrl); Assert.Equal(orderPocoFromDb.Restaurant.Phone, mapperArgument.Restaurant.Phone); Assert.Equal(orderPocoFromDb.Restaurant.Name, mapperArgument.Restaurant.Name); Assert.Equal(orderPocoFromDb.Restaurant.WebsiteUrl, mapperArgument.Restaurant.WebsiteUrl); }
public void OrderPocoShouldBeMappedToOrder() { //Arrange var orderPoco = new OrderPoco(); orderPoco.AccountNumber = "11 1111 1111 1111 1111"; orderPoco.Deadline = DateTime.Now; orderPoco.EstimatedDeliveryTime = DateTime.Now.AddHours(1); orderPoco.Id = 999; orderPoco.OrderedMeals = new List <OrderedMealPoco>() { new OrderedMealPoco() { Id = 10, Count = 2, Price = 21.32, MealName = "Meal 1", OrderId = 999, PurchaserName = "Johnny Bravo" }, new OrderedMealPoco() { Id = 11, Count = 3, Price = 31.32, MealName = "Meal 2", OrderId = 999, PurchaserName = "Voldemort" } }; orderPoco.Owner = "Papa Smurf"; orderPoco.Restaurant = new RestaurantPoco() { ID = 1 }; orderPoco.RestaurantId = 1; orderPoco.Status = new StatusPoco() { Id = 1 }; orderPoco.StatusId = 1; //Act var order = _orderMapper.MapToDomain(orderPoco); //Assert Assert.Equal(order.Id, orderPoco.Id); Assert.Equal(order.Owner, orderPoco.Owner); Assert.Equal(order.Status, (OrderStatus)orderPoco.StatusId); Assert.Equal(order.AccountNumber, orderPoco.AccountNumber); Assert.Equal(order.Restaurant.ID, orderPoco.RestaurantId); Assert.Equal(order.Deadline, orderPoco.Deadline); Assert.Equal(order.EstimatedDeliveryTime, orderPoco.EstimatedDeliveryTime); Assert.Equal(order.OrderedMeals.Count, orderPoco.OrderedMeals.Count); Assert.IsType <Order>(order); }
public async Task <SimpleResult> Edit(OrderPoco input) { _context.Orders.Attach(input).State = EntityState.Modified; await _context.SaveChangesAsync(); return(new SimpleResult { IsSuccess = true }); }
public ActionResult GetApplicantEducation(Guid id) { OrderPoco poco = _logic.Get(id); if (poco == null) { return(NotFound()); } else { return(Ok(poco)); } }
public async Task <SimpleResult> Add(OrderPoco input) { try { return(await _domain.Add(input)); } catch { return(new SimpleResult { IsSuccess = false }); } }
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); }
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); }
public async Task <SimpleResult> Add(OrderPoco input) { var poco = new OrderPoco { DateCreated = input.DateCreated, Deleted = false, Plumber = input.Plumber, Site = input.Site }; await _context.Orders.AddAsync(poco); await _context.SaveChangesAsync(); var selected = new List <OrderItemPoco>(); foreach (var s in input.OrderItems) { s.OrderId = Convert.ToInt32(poco.Id); selected.Add(new OrderItemPoco { Deleted = false, OrderId = s.OrderId, Quantity = s.Quantity, StockCode = s.StockCode, StockCost = s.StockCost, StockDescription = s.StockDescription }); } await _context.OrderItems.AddRangeAsync(selected); await _context.SaveChangesAsync(); return(new SimpleResult { IsSuccess = true }); }
public async Task <JsonResult> Edit([FromBody] OrderPoco input) { var result = await _order.Edit(input); return(await GenerateResult(result, _userSettings)); }