public async Task <IEnumerable <Program> > FindProgram(SearchProgram _SearchProgram, LogCommand logCommand) { //Logging Helper for Method var method_name = "GetClientAsync"; //Query Used by Dapper var query = " SELECT * from " + ProgramTable + _SearchProgram.getWhereClause(); //Log the input logCommand.LogMessage = $"{Repository}.{method_name} Starting input parameter _SearchProgram={JsonConvert.SerializeObject(_SearchProgram)}" + Environment.NewLine + $"Query: {query}"; _logHandler.HandleLog(logCommand); using (var connection = _connectionFactory.GetConnection) { //Await the response var _Program = await connection.QueryAsync <Program>(query); connection.Close(); //Log the output logCommand.LogMessage = $"{Repository}.{method_name} completed"; _logHandler.HandleLog(logCommand); return(_Program); } }
public void When_SearchWordsNotOnFiles_Should_NotFound_files() { //Arrange var mockFilesystem = Substitute.For <IFileSystem>(); const string file1Name = "file1"; const string content1 = "word1 word2 word1"; mockFilesystem.File.ReadAllText(file1Name).Returns(content1); const string file2Name = "file2"; const string content2 = "word2 word2 word2"; mockFilesystem.File.ReadAllText(file2Name).Returns(content2); const string file3Name = "file3"; const string content3 = "word1 word2 word2"; mockFilesystem.File.ReadAllText(file3Name).Returns(content3); string[] files = { file1Name, file2Name, file3Name }; mockFilesystem.Directory.GetFiles(Arg.Any <string>(), Arg.Any <string>()).Returns(files); var search = new SearchProgram("", mockFilesystem); //Act var filesFound = search.SearchWord("word4", 2).ToList(); //Assert filesFound.Count.Should().Be(0); }
public void When_Read_WithoutFiles_Should_Count_NoFiles_Read() { //Arrange string[] files = { }; var mockFilesystem = Substitute.For <IFileSystem>(); mockFilesystem.Directory.GetFiles(Arg.Any <string>(), Arg.Any <string>()).Returns(files); //Act var search = new SearchProgram("", mockFilesystem); //Assert search.FilesFoundCount().Should().Be(0); }
public ActionResult ListFaculties(bool?StudentSelected, bool?FacultySelected, bool?currStud, bool?currFac, string SearchProgram, string currentProgram, string SearchKeyword, string currentFilter, int?CountryId, int?currentCountry, int?RegionId, int?currentRegion, int?page) { ViewBag.CurrentFilter = string.IsNullOrEmpty(SearchKeyword) ? currentFilter : SearchKeyword; ViewBag.CurrentCountry = CountryId.HasValue ? CountryId : currentCountry; ViewBag.CurrentRegion = RegionId.HasValue ? RegionId : currentRegion; ViewBag.CurrentProgram = string.IsNullOrEmpty(SearchProgram) ? currentProgram : SearchProgram; ViewBag.CurrentStudent = StudentSelected.HasValue ? StudentSelected : currStud; ViewBag.CurrentFaculty = FacultySelected.HasValue ? FacultySelected : currFac; var programs = from faculties in db.Faculties select faculties.Program; ViewBag.Programs = programs.ToList().Distinct().Take(10); AddFields(); if (SearchKeyword != null) { page = 1; } else { SearchKeyword = currentFilter; } if (!CountryId.HasValue) { CountryId = currentCountry; } if (!RegionId.HasValue) { RegionId = currentRegion; } if (string.IsNullOrEmpty(SearchProgram)) { SearchProgram = currentProgram; } if (!StudentSelected.HasValue) { StudentSelected = currStud; } if (!FacultySelected.HasValue) { FacultySelected = currFac; } var facultiesFiltered = db.Faculties.Where(f => f.Display.HasValue && f.Display.Value && ((f.FacultyApplicationDate.HasValue && EntityFunctions.TruncateTime(f.FacultyApplicationDate.Value) >= EntityFunctions.TruncateTime(DateTime.Now)) || (f.StudentApplicationDate.HasValue && EntityFunctions.TruncateTime(f.StudentApplicationDate.Value) >= EntityFunctions.TruncateTime(DateTime.Now)))).OrderByDescending(l => l.IsFeatured).ThenBy(l => l.StudentApplicationDate.Value).ThenBy(l => l.FacultyApplicationDate.Value).ToList(); if (!string.IsNullOrEmpty(SearchKeyword)) { facultiesFiltered = facultiesFiltered.Where(f => f.Name.ToLower().Contains(SearchKeyword.ToLower())).ToList(); } if (CountryId.HasValue && CountryId != -1) { facultiesFiltered = facultiesFiltered.Where(f => f.CountryId.HasValue && f.CountryId == CountryId).ToList(); } if (RegionId.HasValue && RegionId != -1 && CountryId.HasValue && CountryId == -1) { facultiesFiltered = facultiesFiltered.Where(f => f.CountryObj != null && f.CountryObj.RegionId == RegionId).ToList(); } if (!string.IsNullOrEmpty(SearchProgram)) { facultiesFiltered = facultiesFiltered.Where(f => f.Program.ToLower().Contains(SearchProgram.ToLower())).ToList(); } //TO DO - logika so datumi za sporedba so momentalen datum if ((StudentSelected.HasValue && StudentSelected.Value)) { facultiesFiltered = facultiesFiltered.Where(f => (f.StudentPlacesAvailable.HasValue && f.StudentPlacesAvailable.Value > 0 && f.StudentApplicationDate.HasValue && f.StudentApplicationDate.Value >= DateTime.Today && f.StudentEnrollmentDate.HasValue && (StudentSelected.HasValue && StudentSelected.Value))).ToList().OrderByDescending(l => l.IsFeatured).ThenBy(l => l.StudentApplicationDate.Value).ToList(); } else if ((FacultySelected.HasValue && FacultySelected.Value)) { facultiesFiltered = facultiesFiltered.Where(f => (f.FacultyPlacesAvailable.HasValue && f.FacultyPlacesAvailable.Value > 0 && f.FacultyApplicationDate.HasValue && f.FacultyApplicationDate.Value >= DateTime.Today && f.FacultyEnrollmentDate.HasValue && (FacultySelected.HasValue && FacultySelected.Value))).ToList().OrderByDescending(l => l.IsFeatured).ThenBy(l => l.FacultyApplicationDate.Value).ToList(); } foreach (var fax in facultiesFiltered) { fax.CoursesString = string.Join(", ", fax.Courses.Select(x => x.SubjectObj.Name)); } SearchViewModel svm = new SearchViewModel(); svm.SearchKeyword = SearchKeyword; svm.CountryId = (CountryId.HasValue ? CountryId.Value : -1); svm.RegionId = (RegionId.HasValue ? RegionId.Value : -1); ViewBag.SearchViewModel = svm; int pageSize = 10; int pageNumber = (page ?? 1); return(View(facultiesFiltered.ToPagedList(pageNumber, pageSize))); }