Esempio n. 1
0
        public void AddOrderDetails()
        {
            try
            {
                var options = Tester <OrderContext> .CreateNewContextOptions();

                var orderDetails = new List <OrderDetail>
                {
                    new OrderDetail
                    {
                        DiscountedCost    = 200,
                        EntityCount       = 20,
                        Total             = 4000,
                        JsonEntityDetails = JsonConvert.SerializeObject(new  { Id = 1, Name = "Hat", IsActive = true, Cost = 200 }),
                        MomentCost        = 200
                    },
                    new OrderDetail
                    {
                        DiscountedCost    = 300,
                        EntityCount       = 20,
                        Total             = 4000,
                        JsonEntityDetails = JsonConvert.SerializeObject(new  { Id = 2, Name = "Hat2", IsActive = true, Cost = 300 }),
                        MomentCost        = 300
                    },
                };
                var   contact = ProcessingTestHelper.GenerateContact();
                Order order;
                using (var db = new OrderContext(options))
                {
                    db.Contacts.Add(contact);
                    ProcessingTestHelper.PopulateDefaultOrderCtx(db);
                    var orderState1 = db.OrderStates.First();
                    var payment1    = db.PaymentMethods.First();
                    var delivery1   = db.DeliveryMethods.First();
                    var zone        = db.DeliveryZones.First();
                    order = ProcessingTestHelper.GenerateOrder(contact, orderState1, payment1, delivery1, zone);
                    db.Set <Order>().Add(order);
                    db.SaveChanges();
                }
                using (var db = new OrderContext(options))
                {
                    var repository =
                        new OrderRepository(db);
                    Assert.DoesNotThrow(() => repository.AddOrderDetails(orderDetails, order));
                    Assert.True(orderDetails.All(it => it.OrderId != 0));
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex.Message, ex);
                throw;
            }
        }