public void Test() { var listOfClassrooms = new List <Classroom>(); listOfClassrooms.Add(new Classroom { Nazwa_sali = "sala", Liczba_miejsc = 30, Pow_m2 = 30.5, Uwagi = "", IdBudynek = 1, Istnieje = true, IdFunkcja_sali = 1, Poziom = "0", Dostep_dla_niepelnosprawnych = true, Uzytkownik = "Maciek", Kolejnosc = 1, IdRozkladSali = 1, LiczbaKomputerow = 20, IdKomputer = 1, Klimatyzacja = true, }); FilteringObject fo = new FilteringObject { AirConditioning = true }; Mock <IClassroomManagementRepository> mockRepository = new Mock <IClassroomManagementRepository>(); mockRepository.Setup(x => x.GetClassroomsAsync()).Returns(listOfClassrooms.As <Task <IEnumerable <Classroom> > >()); var roomsController = new RoomsController(mockRepository.Object); roomsController.Should().NotBeNull(); }
public async Task <IActionResult> GetClassroomsAsync([FromQuery] FilteringObject f) { var result = await _provider.FilterClassroomsAsync(f); string json = JsonConvert.SerializeObject(result, Formatting.Indented); return(Ok(json)); }
public async Task <IEnumerable <Classroom> > FilterClassroomsAsync(FilteringObject f) { IEnumerable <Classroom> result; using (var connection = new SqlConnection(connectionString)) { await connection.OpenAsync(); const string query = @"EXEC dbo.zss_FilterSala_sel @Budynki = @Buildings, @Klimatyzacja = @AirConditioning, @TV = @TV, @Projektor = @Projector, @TylkoSalaDydaktyczna = @OnlyEducationalClassrooms, @RozmiarSaliMin = @SizeMin, @RozmiarSaliMax = @SizeMax, @LiczbaMiejscMin = @PlacesMin, @LiczbaMiejscMax = @PlacesMax, @Dostep_dla_niepelnosprawnych = @AccessForTheDisabled, @FunkcjeSali = @ClassroomFunctions, @SearchCategory = @SearchCategory, @Search = @Search;"; DataTable buildings = new DataTable(); buildings.Columns.Add("IdBudynek", typeof(int)); buildings.Columns.Add("Nazwa", typeof(string)); if (f.Buildings != null) { int id = 0; foreach (var item in f.Buildings) { buildings.Rows.Add(id, item); id++; } } DataTable classroomFunctions = new DataTable(); classroomFunctions.Columns.Add("IdFunkcjaSali", typeof(int)); classroomFunctions.Columns.Add("Nazwa", typeof(string)); if (f.ClassroomFunctions != null) { int id = 0; foreach (var item in f.ClassroomFunctions) { classroomFunctions.Rows.Add(id, item); id++; } } // we return EducationalClassrooms because we want to get additional data for Classrooms which are EducationalClassrooms result = await connection.QueryAsync <EducationalClassroom>(query, new { Buildings = buildings.AsTableValuedParameter("dbo.BudynekTableType"), f.AirConditioning, f.TV, f.Projector, f.OnlyEducationalClassrooms, f.SizeMin, f.SizeMax, f.PlacesMin, f.PlacesMax, f.AccessForTheDisabled, ClassroomFunctions = classroomFunctions.AsTableValuedParameter("dbo.FunkcjaSaliTableType"), f.SearchCategory, f.Search }); } return(result); }