public void Search_AppList_Query() { //Arrage AppListSearchRequest request = new AppListSearchRequest { AppName = "Test AppName", Category = "All", Version = "1.0.0", Enable = "1" }; TResult <AppListViewModel> expectedResponse = new TResult <AppListViewModel> { data = new AppListViewModel { Search = request, AppList = _appList }, Rtncode = FaultInfoRcConstants.OK, RtnMsg = "OK" }; _appListService.GetAppList(Arg.Any <string>(), Arg.Any <DynamicParameters>()).Returns(_appList); //Act TResult <AppListViewModel> actualResponse = _targetObj.SearchAppList(request); //Assert Assert.AreEqual(expectedResponse.Rtncode, actualResponse.Rtncode); Assert.AreEqual(expectedResponse.RtnMsg, actualResponse.RtnMsg); Assert.AreEqual(expectedResponse.data.AppList.Count(), actualResponse.data.AppList.Count()); }
public void Test_SearchAppList() { //Arrange string sqlAppendStr = @" AND LOWER(apList.AppName) LIKE LOWER(@AppName) "; DynamicParameters parameters = new DynamicParameters(); parameters.Add(@"@AppName", "%" + "Portal App 2.0" + "%", DbType.String); //Act _targetObj.GetAppList(sqlAppendStr, parameters); }
/// <summary> /// search 條件 /// </summary> /// <param name="request"></param> /// <returns></returns> public TResult <AppListViewModel> SearchAppList(AppListSearchRequest request) { string sqlAppendStr = ""; DynamicParameters parameters = new DynamicParameters(); //AppName if (!string.IsNullOrEmpty(request.AppName)) { sqlAppendStr += @"AND LOWER(apList.AppName) LIKE LOWER(@AppName) "; parameters.Add(@"@AppName", "%" + request.AppName.ToLower().Trim() + "%", DbType.String); } //Category if (!string.IsNullOrEmpty(request.Category)) { if (request.Category != "All" && request.Category != "None") { sqlAppendStr += @"AND apList.Category = @Category "; parameters.Add(@"@Category", request.Category.Trim(), DbType.String); } } //Version if (!string.IsNullOrEmpty(request.Version)) { sqlAppendStr += @"AND apOs.Version LIKE @Version "; parameters.Add(@"@Version", "%" + request.Version.Trim() + "%", DbType.String); } //Status if (!string.IsNullOrEmpty(request.Enable)) { if (request.Enable != "All" && request.Enable != "None") { sqlAppendStr += @"AND apOs.Status =@Status "; parameters.Add(@"@Status", request.Enable.Trim(), DbType.String); } } //同時傳入這兩個參數 StartDate & EndDate 才要組這串 between 條件 if (!string.IsNullOrEmpty(request.StartDate?.ToString()) && !string.IsNullOrEmpty(request.EndDate?.ToString())) { sqlAppendStr += @"AND(apOs.CreateDT >= @StartDate AND apOs.CreateDT <= @EndDate) "; parameters.Add(@"@StartDate", request.StartDate, DbType.DateTime); parameters.Add(@"@EndDate", request.EndDate.Value.AddHours(23).AddMinutes(59).AddSeconds(59).AddMilliseconds(999), DbType.DateTime); } else { if (!string.IsNullOrEmpty(request.StartDate?.ToString())) { sqlAppendStr += @"AND apOs.CreateDT >= @StartDate "; parameters.Add(@"@StartDate", request.StartDate, DbType.DateTime); } if (!string.IsNullOrEmpty(request.EndDate?.ToString())) { sqlAppendStr += @"AND apOs.CreateDT <= @EndDate "; parameters.Add(@"@EndDate", request.EndDate.Value.AddHours(23).AddMinutes(59).AddSeconds(59).AddMilliseconds(999), DbType.DateTime); } } sqlAppendStr += @" ORDER BY apList.IsTop DESC, apOs.CreateDT DESC, apList.AppID DESC "; List <AppListItem> appListItem = _appListService.GetAppList(sqlAppendStr, parameters); AppListViewModel viewModel = new AppListViewModel { Search = request, AppList = appListItem }; return(TResult <AppListViewModel> .OK(viewModel, "OK")); }