public void FetchEssentialAssets_ValidRequestWithAssetIdFilter_ValidQuery() { AssetSettingsListRequestDto request = new AssetSettingsListRequestDto { CustomerUid = Guid.NewGuid().ToString("N"), UserUid = Guid.NewGuid().ToString("N"), PageNumber = 1, PageSize = 10, SortColumn = "AssetId", SortDirection = "ASC", FilterName = "AssetId", FilterValue = "Fuel" }; _assetSettingsListRepository.FetchEssentialAssets(request); var queryExpected = string.Format(Queries.FetchAssetsForCustomerAndUserUId + Queries.SelectFoundRows, (request.PageNumber > 0) ? string.Format(Queries.LimitClause, (request.PageNumber - 1) * request.PageSize, request.PageSize) : string.Empty, // Limit offset and limit page size string.Format(Queries.OrderByClause, Constants.AssetSettingsSortConfig[(AssetSettingsSortColumns)Enum.Parse(typeof(AssetSettingsSortColumns), request.SortColumn)], request.SortDirection), // order by clause string.Format("AND " + Constants.AssetSettingsFilterConfig[(AssetSettingsFilters)Enum.Parse(typeof(AssetSettingsFilters), request.FilterName)], request.FilterValue), request.DeviceType); // where clause _stubTransactions.Received(1).GetMultipleResultSetAsync <AssetSettingsListDto, long>(Arg.Is <string>(queryExpected), Arg.Any <dynamic>()); }
public AssetSettingsListServiceTests() { _customerUid = Guid.NewGuid(); _userUid = Guid.NewGuid(); _assetUIDs = new List <Guid>(); _stubLoggingService = Substitute.For <ILoggingService>(); _stubCustomerRepository = Substitute.For <ICustomerRepository>(); _stubLoggingService.CreateLogger(typeof(AssetSettingsListService)); _assetSettingsListValidators = new List <IRequestValidator <AssetSettingsListRequest> > { new AssetSettingsListPageValidator(_stubLoggingService), new AssetSettingsFilterValidator(_stubLoggingService), new AssetSettingsSortColumnValidator(_stubLoggingService) }; _serviceRequestParametersValidators = new List <IRequestValidator <IServiceRequest> > { new CustomerUidValidator(_stubCustomerRepository, _stubLoggingService), new UserUidValidator(_stubLoggingService) }; for (int i = 0; i < 10; i++) { _assetUIDs.Add(Guid.NewGuid()); } _stubParameterAttributeCache = Substitute.For <IParameterAttributeCache>(); _stubAssetSettingsListRepository = Substitute.For <IAssetSettingsListRepository>(); _stubAssetSettingsListRepository.FetchEssentialAssets(Arg.Any <AssetSettingsListRequestDto>()).Returns( x => { var request = (AssetSettingsListRequestDto)x[0]; if (request.CustomerUid == _customerUid.ToString("N") && request.UserUid == _userUid.ToString("N")) { if ((_assetUIDs.Count / request.PageSize) < request.PageNumber) { return(new Tuple <int, IList <AssetSettingsListDto> >(0, new List <AssetSettingsListDto>())); } return(new Tuple <int, IList <AssetSettingsListDto> >(_assetUIDs.Count, _assetUIDs.Select(y => new AssetSettingsListDto { AssetUIDString = y.ToString("N"), AssetName = y.ToString("N") }).ToList())); } else { return(new Tuple <int, IList <AssetSettingsListDto> >(0, new List <AssetSettingsListDto>())); } }); _stubAssetSettingsListRepository.FetchDeviceTypesByAssetUID(Arg.Any <AssetDeviceTypeRequest>()).Returns(x => { var request = (AssetDeviceTypeRequest)x[0]; return(Tuple.Create <int, IEnumerable <DeviceTypeDto> >(3, new List <DeviceTypeDto>() { new DeviceTypeDto() { DeviceType = "PL121", AssetCount = 120 }, new DeviceTypeDto() { DeviceType = "PL142", AssetCount = 24 }, new DeviceTypeDto() { DeviceType = "PL132", AssetCount = 100 } })); }); var mapperconfig = new MapperConfiguration(cfg => { cfg.CreateMap <AssetSettingsListDto, AssetSettingsDetails>(); }); this._stubConfigurations = Options.Create <Configurations>(Substitute.For <Configurations>()); _mapper = mapperconfig.CreateMapper(); _assetSettingsListService = new AssetSettingsListService(_stubAssetSettingsListRepository, _assetSettingsListValidators, _serviceRequestParametersValidators, _stubParameterAttributeCache, _mapper, _stubLoggingService, _stubConfigurations); }