示例#1
0
        public void GetAllEngines()
        {
            var data = new List <Engine>
            {
                new Engine {
                    Name = "Engine1"
                },
                new Engine {
                    Name = "Engine2"
                },
                new Engine {
                    Name = "Engine3"
                },
            }.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.GetAllEngines();

            Assert.AreEqual(3, EnginesFound.Count());
            Assert.AreEqual("Engine1", EnginesFound[0].Name);
            Assert.AreEqual("Engine2", EnginesFound[1].Name);
            Assert.AreEqual("Engine3", EnginesFound[2].Name);
        }
        //Main logic//
        //Get logic//

        /// <summary>
        /// Populate the data grid with information about all existing engines in the database
        /// </summary>
        private void PopulateDataGridViewDefault()
        {
            dataGridView.Rows.Clear();
            EngineBusiness engineBusiness = new EngineBusiness();
            var            enginesList    = engineBusiness.GetAllEngines();

            DataPopulator(enginesList);
        }
示例#3
0
        private void btnEngines_Click(object sender, EventArgs e)
        {
            HideSpecificInfo();
            lblInfoEngine.Visible = true;
            btnNewEngine.Visible  = true;

            dataGridView.Rows.Clear();

            dataGridView.ColumnCount = 6;

            dataGridView.Columns[0].Name = "ID";
            dataGridView.Columns[1].Name = "Име";
            dataGridView.Columns[2].Name = "Гориво";
            dataGridView.Columns[3].Name = "Мощност";
            dataGridView.Columns[4].Name = "Работен обем";
            dataGridView.Columns[5].Name = "Разход на 100 километра";

            dataGridView.AutoSizeRowsMode =
                DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
            dataGridView.ColumnHeadersBorderStyle =
                DataGridViewHeaderBorderStyle.Single;
            dataGridView.CellBorderStyle   = DataGridViewCellBorderStyle.Single;
            dataGridView.RowHeadersVisible = false;
            dataGridView.SelectionMode     =
                DataGridViewSelectionMode.FullRowSelect;
            dataGridView.MultiSelect = false;

            EngineBusiness engineBusiness = new EngineBusiness();
            var            enginesList    = engineBusiness.GetAllEngines();

            foreach (var engine in enginesList)
            {
                string[] row =
                {
                    engine.Id.ToString(),
                    engine.Name,
                    FuelENGToBG(engine.FuelType),
                    engine.Power.ToString(),
                    engine.Displacement.ToString(),
                    engine.EconomyPerHundredKm.ToString()
                };
                dataGridView.Rows.Add(row);
            }
        }