Exemple #1
0
        public void BuildsAListOfNameValueObjectsBasedOnOrigins()
        {
            var viewDataDictionary = new ViewDataDictionary();
            var order = new Order();

            var origins = new List <string>
            {
                "Test Origin 1",
                "Test Origin 2"
            };

            Mock.Arrange(() => _mockOriginRepository.GetAllOrigins()).Returns(origins.AsQueryable()).OccursOnce();
            Mock.Arrange(() => _mockDestinationRepository.GetAllDestinations()).Returns(new string[0].AsQueryable());

            var builder = new OrderViewDataBuilder(_mockOriginRepository, _mockDestinationRepository, _mockPackageTypeSelectListBuilder);

            builder.BuildViewData(viewDataDictionary, order);

            Mock.AssertAll(_mockOriginRepository);
            var result = viewDataDictionary["Origins"];

            Assert.IsNotNull(result);
            var resultList = ((IEnumerable <dynamic>)result).ToList();

            Assert.AreEqual(2, resultList.Count());

            Assert.AreEqual("Test Origin 1", resultList[0].Name);
            Assert.AreEqual("Test Origin 1", resultList[0].Value);

            Assert.AreEqual("Test Origin 2", resultList[1].Name);
            Assert.AreEqual("Test Origin 2", resultList[1].Value);
        }
 public void BuildViewData(ViewDataDictionary viewDataDictionary, Order order)
 {
     viewDataDictionary.Add("Origins", _originRepository.GetAllOrigins().Select(o => new { Name = o, Value = o }));
     viewDataDictionary.Add("Customer", order.Customer);
     viewDataDictionary.Add("PackageTypes", _packageTypeSelectListBuilder.BuildSelectList());
     viewDataDictionary.Add("Destinations", _destinationRepository.GetAllDestinations().Select(d => new { Name = d, Value = d }));
 }
        private void GenerateCustomersForCompany(SellingCompany sellingCompany, SalesHubDbContext context)
        {
            Tuple <string, string>[] customerSeedData = new[]
            {
                new Tuple <string, string>("Blauer See Delikatessen", "Europe"),
                new Tuple <string, string>("Bottom-Dollar Markets", "North America"),
                new Tuple <string, string>("Chop-suey Chinese", "North America"),
                new Tuple <string, string>("Godos Cocina Típica", "South America"),
                new Tuple <string, string>("Lazy K Kountry Store", "North America"),
                new Tuple <string, string>("Let's Stop N Shop", "North America"),
                new Tuple <string, string>("Santé Gourmet", "Europe"),
                new Tuple <string, string>("Save-a-lot Markets", "North America"),
                new Tuple <string, string>("Suprêmes délices", "Europe"),
                new Tuple <string, string>("The Big Cheese", "North America"),
                new Tuple <string, string>("The Cracker Box", "North America"),
                new Tuple <string, string>("Okudacho Sushi", "Asia"),
                new Tuple <string, string>("Oyucho Japanese Cuisine", "Asia"),
                new Tuple <string, string>("LuLu Hypermarket", "Middle East")
            };

            var customers = new List <Customer>();

            foreach (var customerData in customerSeedData)
            {
                var customer = new Customer
                {
                    CustomerName   = customerData.Item1,
                    Region         = customerData.Item2,
                    SellingCompany = sellingCompany,
                    Orders         = new List <Order>()
                };

                customers.Add(customer);
                context.Customers.Add(customer);
            }
            context.SaveChanges();

            var orders = new List <Order>();

            foreach (var customer in customers)
            {
                orders.AddRange(GenerateOrdersForCustomer(customer, context));
            }
            context.SaveChanges();

            var origins = _originRepository.GetAllOrigins().ToList();

            foreach (var order in orders)
            {
                var orderDetails = GenerateOrderDetailsForOrder(order, context, origins);

                order.ContractAmount = orderDetails.Sum(od => od.PricePerUnitOfWeight * od.Units);
                order.ContractWeight = orderDetails.Sum(od => od.Units * od.UnitWeight);
            }
            context.SaveChanges();
        }