Beispiel #1
0
        public void SortEnginesByEconomyPerHundredKmAscending()
        {
            var data = new List <Engine>
            {
                new Engine {
                    Name = "Engine1", EconomyPerHundredKm = 3.0M
                },
                new Engine {
                    Name = "Engine2", EconomyPerHundredKm = 10.3M
                },
                new Engine {
                    Name = "Engine3", EconomyPerHundredKm = 8.0M
                },
            }.AsQueryable();

            var mockSet = new Mock <DbSet <Engine> >();

            mockSet.As <IQueryable <Engine> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <Engine> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <Engine> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <Engine> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var mockContext = new Mock <CarDealershipContext>();

            mockContext.Setup(m => m.Engines).Returns(mockSet.Object);

            var service      = new EngineBusiness(mockContext.Object);
            var EnginesFound = service.SortEnginesByEconomyPerHundredKmAscending();

            Assert.AreEqual(3, EnginesFound.Count());
            Assert.AreEqual("Engine1", EnginesFound[0].Name);
            Assert.AreEqual("Engine3", EnginesFound[1].Name);
            Assert.AreEqual("Engine2", EnginesFound[2].Name);
        }
        /// <summary>
        /// Populate the data grid with information sorted by engines' economy in ascending order
        /// </summary>
        private void PopulateDataGridViewSortEnginesByEconomyPerHundredKmAscending()
        {
            dataGridView.Rows.Clear();
            EngineBusiness engineBusiness = new EngineBusiness();
            var            enginesList    = engineBusiness.SortEnginesByEconomyPerHundredKmAscending();

            DataPopulator(enginesList);
        }