Esempio n. 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 }));
 }