public async void QueryModelList_ReturnsModelsAscendingByName(int brandId) { // Arrange var mockRepo = new Mock <IVehicleCatalogRepository>(); mockRepo.Setup(repo => repo.GetModels(brandId)) .Returns(Task.FromResult <IEnumerable <Model.Model> >(new List <Model.Model>() { new Model.Model() { Id = 1, Name = "Codel 1", BrandId = brandId }, new Model.Model() { Id = 2, Name = "Model 2", BrandId = brandId }, new Model.Model() { Id = 3, Name = "Dodel 3", BrandId = brandId }, }.OrderBy(o => o.Name))); var mapper = _dependencyFixture.ServiceProvider.GetService <IMapper>(); var logger = Mock.Of <ILogger <ModelsController> >(); var controller = new ModelsController(mockRepo.Object, mapper, logger); // Act var result = await controller.GetModels(brandId); // Assert var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <List <ModelForList> >(okResult.Value); var topModel = returnValue.FirstOrDefault().name; Assert.Equal("Codel 1", topModel); }
private void cmbBrands_SelectedIndexChanged(object sender, EventArgs e) { if (cmbBrands.SelectedIndex == -1) { } else { Brands brands = new Brands(); brands.BrandID = cmbBrands.SelectedIndex + 1; cmbModels.DataSource = modelsController.GetModels(brands); cmbModels.DisplayMember = "ModelName"; cmbModels.ValueMember = "ModelID"; } if (cmbBrands.SelectedItem == null) { btnAddModel.Enabled = false; } else { btnAddModel.Enabled = true; } }