Esempio n. 1
0
        public void SetPackageTypeKeyInTheViewData()
        {
            var viewDataDictionary = new ViewDataDictionary();
            var order        = new Order();
            var packageTypes = new List <SelectListItem>
            {
                new SelectListItem
                {
                    Text  = "Test Item",
                    Value = "Test Value"
                }
            };

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

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

            builder.BuildViewData(viewDataDictionary, order);

            var result = (IList <SelectListItem>)viewDataDictionary["PackageTypes"];

            Mock.AssertAll(_mockPackageTypeSelectListBuilder);

            Assert.AreEqual(packageTypes, result);
        }
 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 }));
 }