示例#1
0
        public void GetSales_Expand_Items()
        {
            var tokens = ODataClientHelper.GetServerPaging(SalesServiceRootUrl + "Sales?$expand=Items");
            var purchases = default(IList<SaleHeader>);
            using (var db = new SaleDbContext())
            {
                purchases = db.SaleHeaders.Include("Items").ToArray();
            }

            CompareCollection(purchases, tokens, Compare);
        }
示例#2
0
        public void GetSaleLineItemsServerPaging()
        {
            var transaction = GetSaleLineItem();
            var tokens = ODataClientHelper.GetServerPaging(string.Format("{0}Sales({1})/Items", SalesServiceRootUrl, transaction._SaleHeaderId));
            var transactions = default(IList<SaleLineItem>);
            using (var db = new SaleDbContext())
            {
                transactions = db.SaleLineItems.Where(d => d._SaleHeaderId == transaction._SaleHeaderId).ToArray();
            }

            CompareCollection(transactions, tokens, Compare);
        }
示例#3
0
        public void GetSalesFilterByTotalNumber()
        {
            var tokens = ODataClientHelper.GetServerPaging(SalesServiceRootUrl + "Sales?$filter=TotalNumber gt 50");
            var purchases = default(IList<SaleHeader>);
            using (var db = new SaleDbContext())
            {
                purchases = db.SaleHeaders.Where(s => s.TotalNumber > 50).ToArray();
            }

            CompareCollection(purchases, tokens, Compare);
        }
示例#4
0
        public void GetContactsServerPaging()
        {
            var contact = GetContact();
            var tokens = ODataClientHelper.GetServerPaging(string.Format("{0}Sales({1})/CustomerContacts", SalesServiceRootUrl, contact._SaleHeaderId));
            var contacts = default(IList<Contact>);
            using (var db = new SaleDbContext())
            {
                contacts = db.Contacts.Where(c => c._SaleHeaderId == contact._SaleHeaderId).ToArray();
            }

            CompareCollection(contacts, tokens, Compare);
        }
示例#5
0
        public void GetSaleById_Expand_Items()
        {
            var purchase = GetSale();
            var token = ODataClientHelper.InvokeGet(string.Format("{0}Sales({1})?$expand=Items", SalesServiceRootUrl, purchase.Id));
            using (var db = new SaleDbContext())
            {
                purchase = db.SaleHeaders.Include("Items").First(s => s.Id == purchase.Id);
            }

            Compare(purchase, token);
        }
示例#6
0
 private static void UpdateSaleLineItem(Guid id)
 {
     using (var db = new SaleDbContext())
     {
         var transaction = db.SaleLineItems.Find(id);
         transaction.ProductDescription += " changed";
         transaction.Modified = DateTimeOffset.UtcNow;
         transaction.ModifiedBy = "test";
         db.SaveChanges();
     }
 }
示例#7
0
        public void GetContactsFilterByMethod()
        {
            var contact = GetContact();
            var tokens = ODataClientHelper.GetServerPaging(string.Format("{0}Sales({1})/CustomerContacts?$filter=Method eq Home.Services.SaleService.ContactMethod'Phone'", SalesServiceRootUrl, contact._SaleHeaderId));
            var contacts = default(IList<Contact>);
            using (var db = new SaleDbContext())
            {
                contacts = db.Contacts.Where(c => c._SaleHeaderId == contact._SaleHeaderId && c.Method == ContactMethod.Phone).ToArray();
            }

            CompareCollection(contacts, tokens, Compare);
        }
示例#8
0
 private static void UpdateContact(Guid id)
 {
     using (var db = new SaleDbContext())
     {
         var contact = db.Contacts.Find(id);
         contact.Value += " changed";
         contact.Modified = DateTimeOffset.UtcNow;
         contact.ModifiedBy = "test";
         db.SaveChanges();
     }
 }
示例#9
0
 private static void UpdateSale(Guid id)
 {
     using (var db = new SaleDbContext())
     {
         var purchase = db.SaleHeaders.Find(id);
         purchase.CustomerName += " changed";
         purchase.Modified = DateTimeOffset.UtcNow;
         purchase.ModifiedBy = "test";
         db.SaveChanges();
     }
 }
示例#10
0
 private static SaleLineItem GetSaleLineItem()
 {
     using (var db = new SaleDbContext())
     {
         return db.SaleLineItems.First();
     }
 }
示例#11
0
 private static SaleHeader GetSale()
 {
     using (var db = new SaleDbContext())
     {
         return db.SaleHeaders.First();
     }
 }
示例#12
0
 private static Contact GetContact()
 {
     using (var db = new SaleDbContext())
     {
         return db.Contacts.First();
     }
 }
示例#13
0
        public void TestInitialize()
        {
            TestCleanup();

            var totalNumber = default(int);
            using (var db = new SaleDbContext())
            {
                if (db.SaleHeaders.Any())
                {
                    totalNumber = db.SaleHeaders.Max(s => s.TotalNumber);
                }
            }

            var sales = new List<SaleHeader>(55);

            for (int i = 0; i < sales.Capacity; i++)
            {
                var now = GenerateFakeNow();
                var random = new Random(i);

                var sale = new SaleHeader()
                {
                    DayNumber = sales.Count(s => s.Created.Date == now.Date) + 1,
                    TotalNumber = totalNumber + i + 1,
                    SalesPersonName = GenerateSalesPersonName(i),
                    CustomerName = string.Format("customer {0}", i + 1),
                    Status = GenerateEnumValue<SaleStatus>(),
                };
                sale.NumberText = sale.GenerateSaleNumber();
                sale.CustomerContacts = new[]
                {
                    new Contact()
                    {
                        Method = ContactMethod.Phone,
                        Value = string.Format("contact method phone number {0}", i + 1),
                    },
                    new Contact()
                    {
                        Method = GenerateEnumValue<ContactMethod>(),
                        Value = string.Format("contact method {0}", i + 1),
                    },
                };
                sale.Items = new List<SaleLineItem>();
                var length = random.Next(1, 5);
                for (int j = 0; j < length; j++)
                {
                    var line = new SaleLineItem()
                    {
                        ProductName = GenerateProductName(),
                        ProductDescription = null,
                        Quantity = random.Next(1, 2),
                        UnitPrice = (decimal)((random.NextDouble() + 0.1) * 10000),
                        Status = GenerateEnumValue<SaleStatus>(),
                    };
                    if (j % 2 == 0)
                    {
                        line.DynamicProperties.Add("Certificate", GenerateCertificate());
                        line.DynamicProperties.Add("Cut", GenerateCut());
                        line.DynamicProperties.Add("Caret", GenerateCaret());
                        line.DynamicProperties.Add("Color", GenerateColor());
                        line.DynamicProperties.Add("Clarity", GenerateClarity());
                    }

                    sale.Items.Add(line);
                }

                FillCommonValues(sale, now);

                sales.Add(sale);
            }

            using (var db = new SaleDbContext())
            {
                db.SaleHeaders.AddRange(sales);
                db.SaleLineItems.AddRange(sales.SelectMany(s => s.Items));
                db.Contacts.AddRange(sales.SelectMany(s => s.CustomerContacts));
                db.SaveChanges();
            }
        }
示例#14
0
 public void TestCleanup()
 {
     using (var db = new SaleDbContext())
     {
         db.Database.ExecuteSqlCommand("DELETE tc_customer_contact");
         db.Database.ExecuteSqlCommand("DELETE tc_sale_line");
         db.Database.ExecuteSqlCommand("DELETE tc_sale_header");
         db.SaveChanges();
     }
 }