public void GetAllTowns()
        {
            var data = new List <Town>
            {
                new Town {
                    Name = "Town1"
                },
                new Town {
                    Name = "Town2"
                },
                new Town {
                    Name = "Town3"
                },
            }.AsQueryable();

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

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

            var mockContext = new Mock <CarDealershipContext>();

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

            var service    = new TownBusiness(mockContext.Object);
            var TownsFound = service.GetAllTowns();

            Assert.AreEqual(3, TownsFound.Count());
            Assert.AreEqual("Town1", TownsFound[0].Name);
            Assert.AreEqual("Town2", TownsFound[1].Name);
            Assert.AreEqual("Town3", TownsFound[2].Name);
        }
        //Main logic//
        //Get logic//

        /// <summary>
        /// Populate the data grid with information about all existing towns in the database
        /// </summary>
        private void PopulateDataGridViewDefault()
        {
            dataGridView.Rows.Clear();
            TownBusiness townBusiness = new TownBusiness();
            var          townList     = townBusiness.GetAllTowns();

            DataPopulator(townList);
        }
Example #3
0
        private void btnTowns_Click(object sender, EventArgs e)
        {
            HideSpecificInfo();
            lblInfoTown.Visible = true;
            btnNewTown.Visible  = true;

            dataGridView.Rows.Clear();

            dataGridView.ColumnCount = 2;

            dataGridView.Columns[0].Name = "ID";
            dataGridView.Columns[1].Name = "Име";

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

            TownBusiness townBusiness = new TownBusiness();
            var          townsList    = townBusiness.GetAllTowns();

            foreach (var town in townsList)
            {
                string[] row =
                {
                    town.Id.ToString(),
                    town.Name,
                };
                dataGridView.Rows.Add(row);
            }
        }