public Func <AssetEntity, bool> Convert(GetAssetByPropertyValueRequestModel model) { var value = model.Value; if (model.Property == "is cash") { return(new Func <AssetEntity, bool>(s => s.IsCash == value)); } if (model.Property == "is convertible") { return(new Func <AssetEntity, bool>(s => s.IsConvertible == value)); } if (model.Property == "is fixincome") { return(new Func <AssetEntity, bool>(s => s.IsFixIncome == value)); } if (model.Property == "is swap") { return(new Func <AssetEntity, bool>(s => s.IsSwap == value)); } if (model.Property == "is future") { return(new Func <AssetEntity, bool>(s => s.IsFuture == value)); } else { logger.LogError("Could not convert the search parameter to a valid predicate!"); throw new ConversionException("Could not convert the search parameter to a valid predicate!"); } }
public async Task <IList <long> > GetAssetsByPropertyValues([FromBody] GetAssetByPropertyValueRequestModel model) { var predicate = assetSearchPredicateConverter.Convert(model); return(await assetRepository.GetAssetsByProperty(predicate)); }
public void Test_AssetSearchPredicateConverterWithValue(bool value) { var iscashrequestModel = new GetAssetByPropertyValueRequestModel { Property = "is cash", Value = value }; var predicate = assetPredicateConverter.Convert(iscashrequestModel); var iscashentityList = new List <AssetEntity>() { new AssetEntity { IsCash = value } }; Assert.IsTrue(iscashentityList.Where(predicate).Count() == 1); var isconvertiblerequestModel = new GetAssetByPropertyValueRequestModel { Property = "is convertible", Value = value }; predicate = assetPredicateConverter.Convert(isconvertiblerequestModel); var isconvertibleentityList = new List <AssetEntity>() { new AssetEntity { IsConvertible = value } }; Assert.IsTrue(isconvertibleentityList.Where(predicate).Count() == 1); var isswaprequestModel = new GetAssetByPropertyValueRequestModel { Property = "is swap", Value = value }; predicate = assetPredicateConverter.Convert(isswaprequestModel); var isswapentityList = new List <AssetEntity>() { new AssetEntity { IsSwap = value } }; Assert.IsTrue(isswapentityList.Where(predicate).Count() == 1); var isfixincomerequestModel = new GetAssetByPropertyValueRequestModel { Property = "is fixincome", Value = value }; predicate = assetPredicateConverter.Convert(isfixincomerequestModel); var isfixincomeentityList = new List <AssetEntity>() { new AssetEntity { IsFixIncome = value } }; Assert.IsTrue(isfixincomeentityList.Where(predicate).Count() == 1); var isfuturerequestModel = new GetAssetByPropertyValueRequestModel { Property = "is future", Value = value }; predicate = assetPredicateConverter.Convert(isfuturerequestModel); var isfutureentityList = new List <AssetEntity>() { new AssetEntity { IsFuture = value } }; Assert.IsTrue(isfutureentityList.Where(predicate).Count() == 1); }