public void Init()
        {
            _pgStageBuilderMock = new Mock <IPgStageBuilder>();
            _projectService     = new Mock <IProjectService>();
            var currencyService = new Mock <IPgCurrencyService>();

            _agencyService = new Mock <IAgencyService>();
            var ruleService = GetService <IRuleService>();

            _costStageRevisionService        = new Mock <ICostStageRevisionService>();
            _pgLedgerMaterialCodeServiceMock = new Mock <IPgLedgerMaterialCodeService>();
            _efContext = new Mock <EFContext>();
            _costNumberGeneratorServiceMock = new Mock <ICostNumberGeneratorService>();
            _costNumberGeneratorServiceMock.Setup(x => x.Generate(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>())).Returns(Task.FromResult(_costNumber));
            _costLineItemServiceMock = new Mock <ICostLineItemService>();
            _costTemplateServiceMock = new Mock <ICostTemplateVersionService>();
            _permissionServiceMock   = new Mock <IPermissionService>();
            _pgCostServiceMock       = new Mock <IPgCostService>();
            _pgTotalsBuilder         = new PgCostSectionTotalsBuilder();
            _pgPaymentServiceMock    = new Mock <IPgPaymentService>();
            _exchangeRateServiceMock = new Mock <IExchangeRateService>();
            _efContext.MockAsyncQueryable(new[]
            {
                new Cost
                {
                    LatestCostStageRevision = new CostStageRevision
                    {
                        CostStage = new CostStage
                        {
                            Key = nameof(CostStages.OriginalEstimate)
                        }
                    }
                }
            }.AsQueryable(), c => c.Cost);

            _pgCostBuilder = new PgCostBuilder(
                _pgStageBuilderMock.Object,
                ruleService,
                _costStageRevisionService.Object,
                _agencyService.Object,
                _projectService.Object,
                _efContext.Object,
                _costNumberGeneratorServiceMock.Object,
                currencyService.Object,
                _pgLedgerMaterialCodeServiceMock.Object,
                _costLineItemServiceMock.Object,
                _costTemplateServiceMock.Object,
                _permissionServiceMock.Object,
                _pgCostServiceMock.Object,
                _pgTotalsBuilder,
                _pgPaymentServiceMock.Object,
                _exchangeRateServiceMock.Object
                );
        }
        public void InitalCostTest()
        {
            const decimal intialCost = 1000;
            const decimal cost       = 2000;

            ICostBuilder target = CreateICostBuilder();

            target.InitalCost = intialCost;
            target.AddToTotalCost(cost);
            const decimal expected = intialCost;
            decimal       actual   = 0;

            actual = target.InitalCost;
            Assert.AreEqual(expected, actual, " Because InitalCost set was {1} but {0} was returned", actual, expected);
        }
        public void TotalCostTest()
        {
            const decimal intialCost = 1000;
            const decimal cost       = 2000;

            ICostBuilder target = CreateICostBuilder();

            target.InitalCost = intialCost;
            decimal       methodResult = target.AddToTotalCost(cost);
            const decimal expected     = intialCost + cost;
            decimal       actual       = 0;

            actual = target.TotalCost;
            Assert.AreEqual(expected, actual, " Because TotalCost expected was {1} but {0} was returned", actual, expected);
            Assert.AreEqual(methodResult, actual, " Because The result return by AddToTotalCost() and the TotalCost Properties are not the Same");
        }
        public void AddToTotalCostTest()
        {
            //initalize Components
            const decimal intialCost = 1000;
            ICostBuilder  target     = CreateICostBuilder();

            target.InitalCost = intialCost;
            const decimal cost     = 2000;
            const decimal expected = intialCost + cost;
            decimal       actual   = 0;

            //try Catch is use to differentiate between

            actual = target.AddToTotalCost(cost);



            Assert.AreEqual(expected, actual, "Initial cost + Additional Cost is not the result return");
        }
        public void GetUnitCostTest()
        {
            // Initialization

            const decimal intialCost = 1000;
            const decimal cost       = 2000;

            ICostBuilder target = CreateICostBuilder();

            target.InitalCost = intialCost;
            target.AddToTotalCost(cost);

            const decimal expected = 300;
            const decimal unitCost = 100;

            decimal actual = 0;

            actual = target.GetUnitCost(unitCost);
            Assert.AreEqual(expected, actual, " Because UnitCost for {0} should have been {2} but {1} was returned", cost, actual, expected);
        }
示例#6
0
        private async Task <CostSearchItem> CostSearchItem(Cost cost, ICostBuilder costBuilder)
        {
            Currency currency             = null;
            var      customObjectFormData =
                await _efContext.CustomObjectData.FirstOrDefaultAsync(
                    cofd => cofd.ObjectId == cost.LatestCostStageRevision.Id && cofd.Name == CustomObjectDataKeys.PgPaymentDetails);

            var stageDetailsForm = JsonConvert.DeserializeObject <PgStageDetailsForm>(cost.LatestCostStageRevision.StageDetails.Data);

            var productionDetailsForm = new PgProductionDetailsForm();

            if (cost.LatestCostStageRevision.ProductDetails != null)
            {
                productionDetailsForm = JsonConvert.DeserializeObject <PgProductionDetailsForm>(cost.LatestCostStageRevision.ProductDetails.Data);
            }

            PgPaymentDetails paymentDetails = null;

            if (customObjectFormData?.Data != null)
            {
                paymentDetails = JsonConvert.DeserializeObject <PgPaymentDetails>(customObjectFormData.Data);
            }

            var approvers =
                cost.LatestCostStageRevision.Approvals
                .SelectMany(a => a.ApprovalMembers)
                .Where(am => !am.IsExternal)
                .Select(am => new Approver
            {
                CostUserId = am.CostUser.Id,
                Name       = $"{am.CostUser.FirstName} {am.CostUser.LastName}",
                Role       = am.CostUser.UserBusinessRoles?.FirstOrDefault()?.BusinessRole?.Value ?? "Sap Approver",
                Status     = am.Status.ToString()
            });

            if (!string.IsNullOrEmpty(stageDetailsForm.AgencyCurrency))
            {
                currency = await _efContext.Currency.FirstOrDefaultAsync(c => c.Code == stageDetailsForm.AgencyCurrency);
            }

            if (productionDetailsForm?.DirectPaymentVendor?.CurrencyId != null)
            {
                currency = await _efContext.Currency.FirstOrDefaultAsync(c => c.Id == productionDetailsForm.DirectPaymentVendor.CurrencyId);
            }

            if (currency == null)
            {
                currency = await _efContext.Currency.FirstOrDefaultAsync(c => c.DefaultCurrency);
            }

            var costSearchItem = _mapper.Map <CostSearchItem>(cost);
            var totals         = await costBuilder.GetRevisionTotals(cost.LatestCostStageRevision.Id);

            costSearchItem.GrandTotal = totals.totalInLocalCurrency;
            costSearchItem.GrandTotalDefaultCurrency = totals.total;
            costSearchItem.ApprovalMembers           = new List <Approver>();
            costSearchItem.ApprovalMembers.AddRange(approvers);
            costSearchItem.LatestRevisionId = cost.LatestCostStageRevision.Id;

            costSearchItem.UserGroups  = (await _permissionService.GetObjectUserGroups(cost.Id, null)).ToList();
            costSearchItem.BrandId     = cost.Project.BrandId.ToString();
            costSearchItem.AgencyId    = cost.ParentId.ToString();
            costSearchItem.IoNumber    = paymentDetails?.IoNumber;
            costSearchItem.Initiatives = cost.LatestCostStageRevision.ExpectedAssets?.Select(a => a.Initiative).Distinct().ToList();
            _mapper.Map(stageDetailsForm, costSearchItem);
            costSearchItem.Stage    = cost.LatestCostStageRevision.CostStage.Name;
            costSearchItem.StageKey = cost.LatestCostStageRevision.CostStage.Key;

            return(_mapper.Map(currency, costSearchItem));
        }