Exemplo n.º 1
0
            public void ConvertsDateFilterParametersToUTC()
            {
                // Arrange
                var productionDateStart = DateTime.Now.AddDays(-5);
                var productionDateEnd   = DateTime.Now;
                var expectedStart       = productionDateStart.ToUniversalTime();
                var expectedEnd         = productionDateEnd.ToUniversalTime();

                if (productionDateStart == expectedStart || productionDateEnd == expectedEnd)
                {
                    Assert.Inconclusive("Production dates are already in UTC");
                }

                FilterLotParameters actualParameters = null;

                MockLotService
                .Setup(m => m.GetLotSummaries(It.IsAny <FilterLotParameters>()))
                .Callback((FilterLotParameters param) => actualParameters = param)
                .Returns(new SuccessResult <ILotQualitySummariesReturn>(Fixture.Create <ILotQualitySummariesReturn>()));

                // Act
                LotsControler.Get(productionStart: productionDateStart, productionEnd: productionDateEnd);

                // Assert
                Assert.IsNotNull(actualParameters);
                Assert.AreEqual(expectedStart, actualParameters.ProductionStartRangeStart);
                Assert.AreEqual(expectedEnd, actualParameters.ProductionStartRangeEnd);
            }
Exemplo n.º 2
0
 public IResult <ILotQualitySummariesReturn> GetLotSummaries(FilterLotParameters parameters = null)
 {
     try
     {
         return(_lotServiceProvider.GetLots(parameters));
     }
     catch (Exception ex)
     {
         _exceptionLogger.LogException(ex);
         return(new FailureResult <ILotQualitySummariesReturn>(null, ex.Message));
     }
 }
Exemplo n.º 3
0
        public IResult <ILotQualitySummariesReturn> GetLots(FilterLotParameters parameters)
        {
            var predicateResult = LotPredicateBuilder.BuildPredicate(_lotUnitOfWork, parameters);

            if (!predicateResult.Success)
            {
                return(predicateResult.ConvertTo <ILotQualitySummariesReturn>());
            }

            var selectAttributes = AttributeNameProjectors.SelectActiveAttributeNames(_lotUnitOfWork);
            var selectLotSummary = LotProjectors.SplitSelectLotQualitySummary(_lotUnitOfWork, _timeStamper.CurrentTimeStamp);

            return(new SuccessResult <ILotQualitySummariesReturn>(new LotSummariesReturn
            {
                AttributeNamesAndTypes = selectAttributes.ExpandAll().Invoke().ToList(),
                LotSummaries = _lotUnitOfWork.LotRepository
                               .Filter(predicateResult.ResultingObject)
                               .OrderByLot()
                               .SplitSelect(selectLotSummary)
            }));
        }
Exemplo n.º 4
0
            public void CreatesFilterLotParameterObjectCorrectly()
            {
                // Arrange
                const LotTypeEnum         expectedLotType = LotTypeEnum.GRP;
                const LotProductionStatus expectedStatus  = LotProductionStatus.Produced;

                FilterLotParameters actualParameters = null;

                MockLotService
                .Setup(m => m.GetLotSummaries(It.IsAny <FilterLotParameters>()))
                .Callback((FilterLotParameters param) => actualParameters = param)
                .Returns(new SuccessResult <ILotQualitySummariesReturn>(Fixture.Create <ILotQualitySummariesReturn>()));

                // Act
                LotsControler.Get(expectedLotType, expectedStatus);

                // Assert
                Assert.IsNotNull(actualParameters);
                Assert.AreEqual(expectedLotType, actualParameters.LotType);
                Assert.AreEqual(expectedStatus, actualParameters.ProductionStatus);
            }
Exemplo n.º 5
0
        internal static IResult <Expression <Func <Lot, bool> > > BuildPredicate(ILotUnitOfWork lotUnitOfWork, FilterLotParameters parameters = null)
        {
            var predicate = PredicateBuilder.True <Lot>();

            if (parameters != null)
            {
                if (parameters.LotType != null)
                {
                    predicate = predicate.And(LotPredicates.FilterByLotType(parameters.LotType.Value).ExpandAll());
                }

                if (parameters.ProductType != null)
                {
                    predicate = predicate.And(LotPredicates.FilterByProductType(lotUnitOfWork, parameters.ProductType.Value).ExpandAll());
                }

                if (!string.IsNullOrWhiteSpace(parameters.ProductKey))
                {
                    var productKeyResult = KeyParserHelper.ParseResult <IProductKey>(parameters.ProductKey);
                    if (!productKeyResult.Success)
                    {
                        return(productKeyResult.ConvertTo <Expression <Func <Lot, bool> > >(null));
                    }
                    predicate = predicate.And(LotPredicates.FilterByProductKey(lotUnitOfWork, new ProductKey(productKeyResult.ResultingObject)).ExpandAll());
                }

                if (parameters.ProductionStartRangeStart != null || parameters.ProductionStartRangeEnd != null)
                {
                    predicate = predicate.And(LotPredicates.FilterByLotProductionStart(lotUnitOfWork, parameters.ProductionStartRangeStart, parameters.ProductionStartRangeEnd).ExpandAll());
                }

                if (parameters.ProductionStatus != null)
                {
                    predicate = predicate.And(LotPredicates.FilterByProductionStatus(parameters.ProductionStatus.Value).ExpandAll());
                }

                if (parameters.QualityStatus != null)
                {
                    predicate = predicate.And(LotPredicates.FilterByQualityStatus(parameters.QualityStatus.Value).ExpandAll());
                }

                if (parameters.ProductSpecComplete != null)
                {
                    predicate = predicate.And(LotPredicates.FilterByProductSpecComplete(parameters.ProductSpecComplete.Value).ExpandAll());
                }

                if (parameters.ProductSpecOutOfRange != null)
                {
                    predicate = predicate.And(LotPredicates.FilterByProductSpecOutOfRange(parameters.ProductSpecOutOfRange.Value).ExpandAll());
                }

                if (!string.IsNullOrWhiteSpace(parameters.StartingLotKey))
                {
                    var lotKeyResult = KeyParserHelper.ParseResult <ILotKey>(parameters.StartingLotKey);
                    if (!lotKeyResult.Success)
                    {
                        return(lotKeyResult.ConvertTo <Expression <Func <Lot, bool> > >(null));
                    }

                    predicate = predicate.And(LotPredicates.FilterByStartingLotKey(lotKeyResult.ResultingObject).ExpandAll());
                }
            }

            return(new SuccessResult <Expression <Func <Lot, bool> > >(predicate.ExpandAll()));
        }