public void OrAllGroupsAreFalse() { var lot = new LotBuilder() .Expired() .AvailableOnStock() .Interdicted() .Build(); var result = Specification .Create(lot) .IsNot <Expired>() .AndIs <AvailableOnStock>() .AndIsNot <Interdicted>() .OrIs <Expired>() .AndIsNot <AvailableOnStock>() .AndIs <Interdicted>() .OrIs <Expired>() .AndIs <AvailableOnStock>() .AndIsNot <Interdicted>() .GetResult(); Assert.False(result.IsValid); Assert.Equal(3, result.TotalOfErrors); Assert.True(result.HasError <AvailableOnStock>()); Assert.True(result.HasError <Interdicted>()); Assert.True(result.HasError <Expired>()); }
public void NoErrorMessage() { var lots = new List <Lot>(); var lot1 = new LotBuilder() .NotExpired() .AvailableOnStock() .NotInterdicted() .Build(); var lot2 = new LotBuilder() .Expired() .AvailableOnStock() .Interdicted() .Build(); lots.Add(lot1); lots.Add(lot2); var result = Specification .Create <Lot>(lots) .ThatAre <Expired>() .GetResults(); Assert.Equal(string.Empty, result.ErrorMessages); }
public void TwoFailuresOneSuccess() { var lot = new LotBuilder() .Expired() .Interdicted() .AvailableOnStock() .Build(); string fullErrorMessage = new StringBuilder() .AppendLine(new Expired().GetErrorMessageWhenExpectingFalse(lot)) .Append(new Interdicted().GetErrorMessageWhenExpectingFalse(lot)) .ToString(); var result = Specification .Create(lot) .IsNot <Expired>() .AndIsNot <Interdicted>() .AndIs <AvailableOnStock>() .GetResult(); Assert.False(result.IsValid); Assert.Equal(fullErrorMessage, result.ErrorMessage); Assert.Equal(2, result.TotalOfErrors); Assert.True(result.HasError <Expired>()); Assert.True(result.HasError <Interdicted>()); Assert.False(result.HasError <AvailableOnStock>()); }
public void CustomMessage() { var lots = new List <Lot>(); var lot1 = new LotBuilder() .Expired() .Build(); var lot2 = new LotBuilder() .Expired() .Build(); lots.Add(lot1); lots.Add(lot2); const string customErrorMessage = "This is a Custom Error Message"; string fullErrorMessage = new StringBuilder() .AppendLine(customErrorMessage) .Append(customErrorMessage) .ToString(); var result = Specification .Create <Lot>(lots) .ThatAreNot <Expired>() .UseThisErrorMessageIfFails(customErrorMessage) .GetResults(); Assert.Equal(fullErrorMessage, result.ErrorMessages); }
public void AsWarning() { var lots = new List <Lot>(); var lot1 = new LotBuilder() .Expired() .AvailableOnStock() .Build(); var lot2 = new LotBuilder() .NotExpired() .AvailableOnStock() .Build(); lots.Add(lot1); lots.Add(lot2); string expectedWarningMessage = new Expired().GetErrorMessageWhenExpectingFalse(lot2); var result = Specification .Create <Lot>(lots) .ThatAreNot <Expired>().AsWarning() .AndAre <AvailableOnStock>() .GetResults(); Assert.True(result.AreAllCandidatesValid); Assert.Equal(0, result.TotalOfErrors); Assert.Equal(1, result.TotalOfWarnings); Assert.False(result.HasError <Expired>()); Assert.True(result.HasWarning <Expired>()); Assert.True(result.HasWarning <Expired>(lot1)); Assert.Equal(expectedWarningMessage, result.WarningMessages); }
public void HasWarningCandidateNotFound() { var lots = new List <Lot>(); var lot1 = new LotBuilder() .Expired() .AvailableOnStock() .Build(); var lot2 = new LotBuilder() .NotExpired() .AvailableOnStock() .Build(); var lot3 = new LotBuilder() .NotExpired() .AvailableOnStock() .Build(); lots.Add(lot1); lots.Add(lot2); var result = Specification .Create <Lot>(lots) .ThatAreNot <Expired>().AsWarning() .AndAre <AvailableOnStock>() .GetResults(); Assert.False(result.HasWarning <Expired>(lot3)); }
private List <CompleteDocInfoDTOData> CreateCompleteDocInfos(List <ProductBarCodeByCompleteApplyDTO> barCodeDTOs) { List <CompleteDocInfoDTOData> docInfoList = new List <CompleteDocInfoDTOData>(); CompleteDocInfoDTOData docInfoDTO = new CompleteDocInfoDTOData(); docInfoDTO.BusinessDate = Base.Context.LoginDate; docInfoDTO.CompleteList = new List <WOInfoDTOData>(); docInfoList.Add(docInfoDTO); foreach (ProductBarCodeByCompleteApplyDTO barCodeDTO in barCodeDTOs) { ItemMaster item = new ItemMaster.EntityKey(barCodeDTO.ItemID).GetEntity(); CompleteApplyDocLine completeApplyDocLine = new CompleteApplyDocLine.EntityKey(barCodeDTO.CompleteApplyDocLine).GetEntity(); WOInfoDTOData woInfoDTO = new WOInfoDTOData(); woInfoDTO.CompleteQty = (decimal)(barCodeDTO.ActualLength / 1000.0); //生成批号数据 LotMaster.EntityKey lotKey = LotBuilder.CreateLot(item, barCodeDTO.BarCode, barCodeDTO.ActualLength); woInfoDTO.LotMaster = lotKey.ID; woInfoDTO.LotNo = lotKey.GetEntity().LotCode; woInfoDTO.MOKey = new WOKeyData(); woInfoDTO.MOKey.ID = completeApplyDocLine.MOKey.ID; //扩展字段 woInfoDTO.DescFlexField = GetRcvRptDocLineDescFlexField(completeApplyDocLine); docInfoDTO.CompleteList.Add(woInfoDTO); } return(docInfoList); }
public void ReturnsEmpty() { var lots = new List <Lot>(); var lot1 = new LotBuilder() .Expired() .Interdicted() .NotAvailableOnStock() .Build(); var lot2 = new LotBuilder() .Expired() .NotInterdicted() .NotAvailableOnStock() .Build(); var lot3 = new LotBuilder() .NotExpired() .Interdicted() .AvailableOnStock() .Build(); lots.Add(lot1); lots.Add(lot2); lots.Add(lot3); IEnumerable <Lot> result = Specification .Create <Lot>(lots) .ThatAre <Expired>() .AndAre <Interdicted>() .AndAre <AvailableOnStock>() .GetMatched(); Assert.False(result.Any()); }
public override object Do(object obj) { GenProductBarCodesByRMA bpObj = (GenProductBarCodesByRMA)obj; if (bpObj.ProductBarCodeDTOs == null || bpObj.ProductBarCodeDTOs.Count == 0) { return(null); } //生成销售退回收货单 CreateReceivementProxy createRcv = new CreateReceivementProxy(); createRcv.RcvHeadDTOs = CreateRcvHeadDTOs(bpObj.ProductBarCodeDTOs); List <BusinessEntity.EntityKey> resultKeys = createRcv.Do(); if (resultKeys == null || resultKeys.Count == 0) { return(null); } using (Session s = Session.Open()) { List <ProductBarCodeByRMADTO> barCodeDTOs = new List <ProductBarCodeByRMADTO>(bpObj.ProductBarCodeDTOs); foreach (BusinessEntity.EntityKey resultKey in resultKeys) { Receivement rcv = new Receivement.EntityKey(resultKey.ID).GetEntity(); foreach (RcvLine rcvLine in rcv.RcvLines) { ProductBarCodeByRMADTO barCodeDTO = FindProductBarCodeDTO(barCodeDTOs, rcvLine); barCodeDTOs.Remove(barCodeDTO); //生成批号数据 LotMaster.EntityKey lotKey = LotBuilder.CreateLot(rcvLine.ItemInfo.ItemID, barCodeDTO.BarCode, barCodeDTO.ActualLength); //设置收货行批号 SetRcvLineLotInfo(rcvLine, lotKey); //生成成品条码记录 ProductBarCode productBarCode = ProductBarCode.Create(); productBarCode.OrgKey = new Base.Organization.Organization.EntityKey(barCodeDTO.OrgID); productBarCode.BarCode = barCodeDTO.BarCode; productBarCode.ActualLength = barCodeDTO.ActualLength; productBarCode.ItemKey = rcvLine.ItemInfo.ItemIDKey; productBarCode.LotKey = lotKey; productBarCode.OperatorsKey = new CBO.HR.Operator.Operators.EntityKey(barCodeDTO.QcOperator); productBarCode.RMAKey = new SM.RMA.RMA.EntityKey(barCodeDTO.RMA); productBarCode.RMALineKey = new SM.RMA.RMALine.EntityKey(barCodeDTO.RMALine); productBarCode.ReceivementKey = rcvLine.ReceivementKey; productBarCode.RcvLineKey = rcvLine.Key; productBarCode.ProductBarCodeKind = ProductBarCodeKindEnum.RMR; } } s.Commit(); } return(null); }
public void OrAllGroupsAreFalse() { var lots = new List <Lot>(); var lot1 = new LotBuilder() .LotNumber("Lot1") .NotExpired() .AvailableOnStock() .NotInterdicted() .Build(); var lot2 = new LotBuilder() .LotNumber("Lot2") .Expired() .AvailableOnStock() .Interdicted() .Build(); lots.Add(lot1); lots.Add(lot2); var result = Specification .Create <Lot>(lots) .ThatAre <Expired>() .AndAre <AvailableOnStock>() .AndAreNot <Interdicted>() .OrAre <Expired>() .AndAreNot <AvailableOnStock>() .AndAreNot <Interdicted>() .OrAreNot <Expired>() .AndAreNot <AvailableOnStock>() .AndAre <Interdicted>() .GetResults(); Assert.False(result.AreAllCandidatesValid); Assert.False(result.ValidCandidates.Any()); Assert.Equal(2, result.InvalidCandidates.Count()); Assert.Equal(2, result.AllCandidates.Count()); Assert.Contains(lot2, result.InvalidCandidates); Assert.Contains(lot1, result.InvalidCandidates); Assert.True(result.HasError <Expired>()); Assert.True(result.HasError <Interdicted>()); Assert.True(result.HasError <AvailableOnStock>()); Assert.True(result.HasError <Expired>(lot1)); Assert.True(result.HasError <Interdicted>(lot1)); Assert.True(result.HasError <AvailableOnStock>(lot1)); Assert.True(result.HasError <Expired>(lot2)); Assert.True(result.HasError <Interdicted>(lot2)); Assert.True(result.HasError <AvailableOnStock>(lot2)); }
public void TwoFailuresOneSuccess() { var lots = new List <Lot>(); var lot1 = new LotBuilder() .NotExpired() .Interdicted() .Build(); var lot2 = new LotBuilder() .Expired() .NotInterdicted() .Build(); var lot3 = new LotBuilder() .NotExpired() .NotInterdicted() .Build(); lots.Add(lot1); lots.Add(lot2); lots.Add(lot3); ISpecificationResults <Lot> result = Specification .Create <Lot>(lots) .ThatAreNot <Expired>() .AndAre <Interdicted>() .GetResults(); Assert.False(result.AreAllCandidatesValid); Assert.Single(result.ValidCandidates); Assert.Equal(2, result.InvalidCandidates.Count()); Assert.Equal(3, result.AllCandidates.Count()); Assert.Contains(lot1, result.ValidCandidates); Assert.Contains(lot2, result.InvalidCandidates); Assert.Contains(lot3, result.InvalidCandidates); Assert.False(result.HasError <AvailableOnStock>()); Assert.True(result.HasError <Expired>()); Assert.True(result.HasError <Interdicted>()); Assert.True(result.HasError <Expired>(lot2)); Assert.True(result.HasError <Interdicted>(lot2)); Assert.False(result.HasError <Expired>(lot3)); Assert.True(result.HasError <Interdicted>(lot3)); }
public void NoErrorMessage() { var lot = new LotBuilder() .NotExpired() .Build(); var result = Specification .Create(lot) .Is <Expired>() .GetResult(); Assert.False(result.IsValid); Assert.Equal(1, result.TotalOfErrors); Assert.True(result.HasError <Expired>()); Assert.Equal(string.Empty, result.ErrorMessage); }
public void OrFirstTrue() { var lot = new LotBuilder() .Expired() .AvailableOnStock() .Build(); var result = Specification .Create(lot) .Is <Expired>() .OrIsNot <AvailableOnStock>() .GetResult(); Assert.True(result.IsValid); Assert.Equal(0, result.TotalOfErrors); Assert.False(result.HasError <AvailableOnStock>()); }
public void ErrorMessageExpectingFalse() { var lot = new LotBuilder() .Expired() .Build(); var result = Specification .Create(lot) .IsNot <Expired>() .GetResult(); string expectedMessage = new Expired().GetErrorMessageWhenExpectingFalse(lot); Assert.False(result.IsValid); Assert.Equal(expectedMessage, result.ErrorMessage); Assert.Equal(1, result.TotalOfErrors); Assert.True(result.HasError <Expired>()); }
public void NoErrorMessageWithCustomMessage() { const string customErrorMessage = "This is a custom error message"; var lot = new LotBuilder() .NotExpired() .Build(); var result = Specification .Create(lot) .Is <Expired>() .UseThisErrorMessageIfFails(customErrorMessage) .GetResult(); Assert.False(result.IsValid); Assert.Equal(customErrorMessage, result.ErrorMessage); Assert.Equal(1, result.TotalOfErrors); Assert.True(result.HasError <Expired>()); }
public void AsWarning() { var lot = new LotBuilder() .Expired() .AvailableOnStock() .Build(); string expectedWarningMessage = new Expired().GetErrorMessageWhenExpectingFalse(lot); var result = Specification .Create(lot) .IsNot <Expired>().AsWarning() .AndIs <AvailableOnStock>() .GetResult(); Assert.True(result.IsValid); Assert.Equal(0, result.TotalOfErrors); Assert.Equal(1, result.TotalOfWarnings); Assert.False(result.HasError <Expired>()); Assert.True(result.HasWarning <Expired>()); Assert.Equal(expectedWarningMessage, result.WarningMessage); }
public void OrCondition() { var lots = new List <Lot>(); var lot1 = new LotBuilder() .Expired() .Interdicted() .NotAvailableOnStock() .Build(); var lot2 = new LotBuilder() .Expired() .NotInterdicted() .NotAvailableOnStock() .Build(); var lot3 = new LotBuilder() .NotExpired() .Interdicted() .AvailableOnStock() .Build(); lots.Add(lot1); lots.Add(lot2); lots.Add(lot3); IEnumerable <Lot> result = Specification .Create <Lot>(lots) .ThatAre <Expired>() .AndAre <Interdicted>() .OrAre <AvailableOnStock>() .GetMatched(); Assert.Equal(2, result.Count()); Assert.Contains(lot1, result); Assert.DoesNotContain(lot2, result); Assert.Contains(lot3, result); }
public void EnumerableExtension() { var lots = new List <Lot>(); var lot1 = new LotBuilder() .Expired() .Interdicted() .NotAvailableOnStock() .Build(); var lot2 = new LotBuilder() .Expired() .NotInterdicted() .NotAvailableOnStock() .Build(); var lot3 = new LotBuilder() .NotExpired() .Interdicted() .NotAvailableOnStock() .Build(); lots.Add(lot1); lots.Add(lot2); lots.Add(lot3); IEnumerable <Lot> result = lots .GetCandidates() .ThatAre <Expired>() .AndAre <Interdicted>() .GetMatched(); Assert.Single(result); Assert.Contains(lot1, result); Assert.DoesNotContain(lot2, result); Assert.DoesNotContain(lot3, result); }
public void SimpleOr() { var lots = new List <Lot>(); var lot1 = new LotBuilder() .NotExpired() .Interdicted() .Build(); var lot2 = new LotBuilder() .NotExpired() .NotInterdicted() .Build(); lots.Add(lot1); lots.Add(lot2); ISpecificationResults <Lot> result = Specification .Create <Lot>(lots) .ThatAre <Expired>() .OrAre <Interdicted>() .GetResults(); Assert.False(result.AreAllCandidatesValid); Assert.Single(result.ValidCandidates); Assert.Single(result.InvalidCandidates); Assert.Equal(2, result.AllCandidates.Count()); Assert.True(result.HasError <Expired>()); Assert.True(result.HasError <Interdicted>()); Assert.False(result.HasError <Expired>(lot1)); Assert.True(result.HasError <Expired>(lot2)); Assert.True(result.HasError <Interdicted>(lot2)); }
public void AllFaling() { var lots = new List <Lot>(); var lot1 = new LotBuilder() .LotNumber("Lot1") .Expired() .Interdicted() .AvailableOnStock() .Build(); var lot2 = new LotBuilder() .LotNumber("Lot2") .Expired() .NotInterdicted() .NotAvailableOnStock() .Build(); var lot3 = new LotBuilder() .LotNumber("Lot3") .NotExpired() .Interdicted() .NotAvailableOnStock() .Build(); lots.Add(lot1); lots.Add(lot2); lots.Add(lot3); string fullErrorMessages = new StringBuilder() .Append(new Interdicted().GetErrorMessageWhenExpectingTrue(lot2)) .ToString(); ISpecificationResults <Lot> result = Specification .Create <Lot>(lots) .ThatAre <Expired>() .AndAre <Interdicted>() .AndAreNot <AvailableOnStock>() .GetResults(); Assert.False(result.AreAllCandidatesValid); Assert.False(result.ValidCandidates.Any()); Assert.Equal(3, result.InvalidCandidates.Count()); Assert.Equal(3, result.AllCandidates.Count()); Assert.True(result.HasError <Expired>()); Assert.True(result.HasError <Interdicted>()); Assert.True(result.HasError <AvailableOnStock>()); Assert.False(result.HasError <Expired>(lot1)); Assert.False(result.HasError <Expired>(lot2)); Assert.True(result.HasError <Expired>(lot3)); Assert.True(result.HasError <Interdicted>(lot2)); Assert.False(result.HasError <Interdicted>(lot1)); Assert.False(result.HasError <Interdicted>(lot3)); Assert.False(result.HasError <AvailableOnStock>(lot2)); Assert.False(result.HasError <AvailableOnStock>(lot3)); Assert.True(result.HasError <AvailableOnStock>(lot1)); Assert.Equal(3, result.TotalOfErrors); Assert.Equal(0, result.TotalOfWarnings); Assert.Equal(fullErrorMessages, result.ErrorMessages); }
public override object Do(object obj) { GenProductBarCodesByShip bpObj = (GenProductBarCodesByShip)obj; if (bpObj.ProductBarCodeDTOs == null || bpObj.ProductBarCodeDTOs.Count == 0) { return(null); } //销售订单转调出单 SOToTransOutBP soToTransOut = new SOToTransOutBP(); soToTransOut.SOToTransOutDTOs = CreateSOToTransOutDTOs(bpObj.ProductBarCodeDTOs); soToTransOut.SplitMergeRule = new List <string>(); List <SOToTransOutResultDTO> resultDTOs = soToTransOut.Do(); if (resultDTOs == null || resultDTOs.Count == 0) { return(null); } using (Session s = Session.Open()) { List <ProductBarCodeByShipDTO> barCodeDTOs = new List <ProductBarCodeByShipDTO>(bpObj.ProductBarCodeDTOs); foreach (SOToTransOutResultDTO resultDTO in resultDTOs) { TransferOut transferOut = new TransferOut.EntityKey(resultDTO.TransOut).GetEntity(); foreach (TransOutLine transOutline in transferOut.TransOutLines) { ProductBarCodeByShipDTO barCodeDTO = FindProductBarCodeDTO(barCodeDTOs, transOutline); barCodeDTOs.Remove(barCodeDTO); //生成批号数据 LotMaster.EntityKey lotKey = LotBuilder.CreateLot(transOutline.ItemInfo.ItemID, barCodeDTO.BarCode, barCodeDTO.ActualLength); //设置调出行批号 SetTransOutLineLotInfo(transOutline, lotKey); //记录来源关系 ShipPlanLine shipPlanline = ShipPlanLine.Finder.FindByID(barCodeDTO.ShipPlanLine); transOutline.DescFlexSegments.PrivateDescSeg3 = shipPlanline.ID.ToString(); //来源出货计划行ID transOutline.DescFlexSegments.PrivateDescSeg4 = shipPlanline.ShipPlan.DocNo; //来源出货计划单号 transOutline.DescFlexSegments.PrivateDescSeg5 = shipPlanline.DocLineNo.ToString(); //来源出货计划行号 //生成成品条码记录 ProductBarCode productBarCode = ProductBarCode.Create(); productBarCode.OrgKey = new Base.Organization.Organization.EntityKey(barCodeDTO.OrgID); productBarCode.BarCode = barCodeDTO.BarCode; productBarCode.ActualLength = barCodeDTO.ActualLength; productBarCode.ItemKey = transOutline.ItemInfo.ItemIDKey; productBarCode.LotKey = lotKey; productBarCode.OperatorsKey = new CBO.HR.Operator.Operators.EntityKey(barCodeDTO.QcOperator); productBarCode.ScanBy = barCodeDTO.ScanBy; productBarCode.ScanOn = DateTime.Now; // barCodeDTO.ScanOn; productBarCode.ShipPlanKey = new ShipPlan.EntityKey(barCodeDTO.ShipPlan); productBarCode.ShipPlanLineKey = new ShipPlanLine.EntityKey(barCodeDTO.ShipPlanLine); productBarCode.TransferOutKey = transOutline.TransferOutKey; productBarCode.TransferOutLineKey = transOutline.Key; productBarCode.ProductBarCodeKind = ProductBarCodeKindEnum.Ship; } } s.Commit(); } return(null); }