Esempio n. 1
0
        public void FetchAssetConfig_ValidRequestWithFilterValueString_ValidQuery()
        {
            AssetSettingsDto request = new AssetSettingsDto
            {
                TargetValues = new Dictionary <AssetTargetType, Tuple <Guid, double> >
                {
                    { AssetTargetType.IdlingBurnRateinLiPerHour, new Tuple <Guid, double>(Guid.NewGuid(), 12) },
                    { AssetTargetType.WorkingBurnRateinLiPerHour, new Tuple <Guid, double>(Guid.NewGuid(), 22) }
                },
                FilterCriteria = new List <KeyValuePair <string, Tuple <string, object> > >
                {
                    new KeyValuePair <string, Tuple <string, object> >("LIKE", Tuple.Create <string, object>("a.AssetName", "fuel"))
                }
            };

            var result = _assetSettingsRepository.FetchAssetConfig(_assetUIDs, request).Result;

            var queryExpected = string.Format(
                AssetConfigRepository.Queries.FetchAssetConfig,
                string.Join(",", _assetUIDs.Select(x => "UNHEX('" + x + "')")).Replace("-", string.Empty),     //Asset UIDs Lists
                "a.AssetName LIKE 'fuel' AND ",
                string.Join(",", request.TargetValues.Keys.Select(x => string.Format("'{0}'", x.ToString())))
                );

            _transactions.Received(1).GetAsync <AssetSettingsDto>(Arg.Is <string>(queryExpected), Arg.Is <dynamic>(request));
        }
Esempio n. 2
0
        public async Task <IList <IErrorInfo> > Validate(AssetFuelBurnRateSettingRequest request)
        {
            var assetsSettingsResponse = await _assetSettingsRepository.FetchAssetConfig(request.AssetUIds, new AssetSettingsDto
            {
                StartDate      = request.StartDate,
                TargetValues   = AssignAssetTargetValues(request.TargetValues, new AssetSettingsDto()),
                FilterCriteria = new List <KeyValuePair <string, Tuple <string, object> > >
                {
                    new KeyValuePair <string, Tuple <string, object> >("<=", new Tuple <string, object>("AC.StartDate", request.StartDate.ToDateTimeStringWithYearMonthDayFormat())),
                    new KeyValuePair <string, Tuple <string, object> >("is", new Tuple <string, object>("AC.EndDate", null))
                }
            });

            if (assetsSettingsResponse?.Count() == 0)
            {
                if (!(request.WorkTargetValue.HasValue && request.IdleTargetValue.HasValue))
                {
                    return(new List <IErrorInfo> {
                        GetValidationResult(ErrorCodes.WorkOrIdleValuesShouldNotBeNull, UtilHelpers.GetEnumDescription(ErrorCodes.WorkOrIdleValuesShouldNotBeNull), true, MethodBase.GetCurrentMethod().Name)
                    });
                }
            }
            else if (request.WorkTargetValue.HasValue != request.IdleTargetValue.HasValue)
            {
                return(new List <IErrorInfo> {
                    GetValidationResult(ErrorCodes.BothWorkAndIdleValuesShouldBeNullORShouldNotBeNull, UtilHelpers.GetEnumDescription(ErrorCodes.BothWorkAndIdleValuesShouldBeNullORShouldNotBeNull), true, MethodInfo.GetCurrentMethod().Name)
                });
            }
            return(null);
        }