Пример #1
0
        private static decimal GetSplit(IReadOnlyDictionary <string, decimal?> splits, CostStages costStage)
        {
            var percent = splits.ContainsKey(costStage.ToString()) ? splits[costStage.ToString()] : 0;

            if (percent < (decimal)0.0 || percent > (decimal)1.0)
            {
                throw new Exception("Payment split can't be outside 0 - 1 range.");
            }

            return(percent ?? 0);
        }
        protected void SetPreviousRevision(CostStages costStage)
        {
            var previous = new CostStageRevision()
            {
                Id        = Guid.NewGuid(),
                Name      = costStage.ToString(),
                CostStage = new CostStage()
                {
                    Key = costStage.ToString()
                }
            };

            _costStageRevisionService.Setup(s => s.GetPreviousRevision(It.IsAny <Guid>())).ReturnsAsync(previous);
        }
        public async Task CanEditIONumber_When_NotOEAIPEStagesAndStatusIsDraft_Should_ReturnFalse(CostStages costStage)
        {
            // Arrange
            var costStageObj = new CostStage {
                Key = costStage.ToString()
            };
            var cost = new Cost
            {
                Id         = Guid.NewGuid(),
                CostStages = new List <CostStage> {
                    costStageObj
                },
                LatestCostStageRevision = new CostStageRevision
                {
                    CostStage = costStageObj
                },
                Status = CostStageRevisionStatus.Draft
            };

            _efContext.Add(cost);
            _efContext.SaveChanges();

            // Act
            var canEditIONumber = await _pgRuleService.CanEditIONumber(cost.Id);

            // Assert
            canEditIONumber.Should().BeFalse();
        }
        protected void SetupDataSharedAcrossTests(Agency agency, Country country,
                                                  Cost cost, CostStageRevision latestRevision, Project project, CostUser costOwner, Guid costOwnerId, CostStage costStage,
                                                  Brand brand, Guid costId, Guid costStageRevisionId, Guid projectId, string budgetRegion = Constants.BudgetRegion.AsiaPacific)
        {
            agency.Country  = country;
            cost.CostNumber = CostNumber;
            cost.LatestCostStageRevision = latestRevision;
            cost.Project             = project;
            costOwner.Agency         = agency;
            costOwner.Id             = costOwnerId;
            latestRevision.CostStage = costStage;
            project.Brand            = brand;

            agency.Name           = AgencyName;
            brand.Name            = BrandName;
            cost.Id               = costId;
            costStage.Name        = CostStageName.ToString();
            costOwner.FullName    = CostOwnerFullName;
            costOwner.GdamUserId  = CostOwnerGdamUserId;
            latestRevision.Id     = costStageRevisionId;
            project.Id            = projectId;
            project.Name          = ProjectName;
            project.GdamProjectId = ProjectGdamId;
            project.AdCostNumber  = ProjectNumber;
            country.Name          = AgencyLocation;

            var stageDetails = new PgStageDetailsForm
            {
                ContentType = new core.Builders.DictionaryValue
                {
                    Id  = Guid.NewGuid(),
                    Key = ContentType
                },
                CostType       = cost.CostType.ToString(),
                ProductionType = new core.Builders.DictionaryValue
                {
                    Id  = Guid.NewGuid(),
                    Key = CostProductionType
                },
                Title = CostTitle,
                AgencyTrackingNumber = AgencyTrackingNumber,
                BudgetRegion         = new AbstractTypeValue
                {
                    Key  = budgetRegion,
                    Name = budgetRegion
                }
            };
            var existingUser = EFContext.CostUser.FirstOrDefault(a => a.GdamUserId == CostOwnerGdamUserId);

            if (existingUser == null)
            {
                EFContext.Add(costOwner);
                EFContext.SaveChanges();
            }

            CostStageRevisionServiceMock.Setup(csr => csr.GetStageDetails <PgStageDetailsForm>(costStageRevisionId)).ReturnsAsync(stageDetails);
        }
        protected IStageDetails BuildStageDetails(Guid revisionId, string contentType, decimal budget, string region,
                                                  CostType costType, string productionType = null, bool?isUsage = null, CostStages costStage = CostStages.OriginalEstimate)
        {
            _costStageRevisionService.Setup(x => x.GetCostLineItems(It.IsAny <Guid>()))
            .ReturnsAsync(new List <CostLineItemView>()
            {
                new CostLineItemView()
                {
                    ValueInDefaultCurrency = budget
                }
            });
            var t = new List <CostStageRevision>()
            {
                new CostStageRevision()
                {
                    Id        = revisionId,
                    CostStage = new CostStage()
                    {
                        Key = costStage.ToString()
                    }
                }
            };

            _efContext.MockAsyncQueryable(t.AsQueryable(), x => x.CostStageRevision);

            var result = new StageDetails()
            {
                Data = new Dictionary <string, dynamic>()
            };

            result.Data.Add("initialBudget", budget);
            result.Data.Add("budgetRegion", new AbstractTypeValue {
                Key = region
            });
            if (costType == CostType.Production)
            {
                result.Data.Add("contentType", JObject.Parse("{\"id\":\"b4a1bb22-90ab-4e37-82bd-494e512827da\",\"value\":\"" + contentType + "\",\"key\":\"" + contentType + "\"}"));
                result.Data.Add("productionType",
                                JObject.Parse("{\"id\":\"b4a1bb22-90ab-4e37-82bd-494e512827dd\",\"value\":\"" + productionType + "\",\"key\":\"" + productionType + "\"}"));
            }

            result.Data.Add("costType", costType);
            if (isUsage.HasValue)
            {
                result.Data.Add("isUsage", isUsage.Value);
                result.Data.Add("usageBuyoutType", new DictionaryValue {
                    Key = contentType
                });
            }
            return(result);
        }
        protected Cost SetupPurchaseOrderView(
            Guid costId,
            IDictionary <string, dynamic> stageDetails          = null,
            IDictionary <string, dynamic> productionDetailsData = null,
            string brandName          = null,
            string costNumber         = null,
            string tNumber            = null,
            string requisitionerEmail = null,
            CostStages costStage      = CostStages.OriginalEstimate,
            string[] agencyLabels     = null,
            CostType costType         = CostType.Production,
            bool isExternalPurchase   = false
            )
        {
            var stage = new CostStage
            {
                Key  = costStage.ToString(),
                Name = costStage.ToString()
            };

            var costStageRevision = new CostStageRevision
            {
                Id           = Guid.NewGuid(),
                StageDetails = new CustomFormData
                {
                    Data = JsonConvert.SerializeObject(stageDetails ?? new Dictionary <string, dynamic>())
                },
                ProductDetails = new CustomFormData
                {
                    Data = JsonConvert.SerializeObject(productionDetailsData ?? new Dictionary <string, dynamic>())
                },
                CostStage = stage,
                Approvals = new List <Approval>
                {
                    new Approval
                    {
                        Type           = ApprovalType.Brand,
                        Requisitioners = new List <Requisitioner>
                        {
                            new Requisitioner
                            {
                                CostUser = new CostUser
                                {
                                    Email        = requisitionerEmail,
                                    FederationId = tNumber
                                }
                            }
                        },
                    }
                }
            };

            stage.CostStageRevisions = new List <CostStageRevision> {
                costStageRevision
            };

            var cost = new Cost
            {
                Id         = costId,
                CostNumber = costNumber,
                CostType   = costType,
                Project    = new Project
                {
                    Brand = new Brand {
                        Name = brandName
                    }
                },
                LatestCostStageRevision = costStageRevision,
                CostStages = new List <CostStage> {
                    stage
                },
                Parent = new AbstractType
                {
                    Agency = new Agency {
                        Labels = agencyLabels ?? new string[0]
                    }
                },
                IsExternalPurchases = isExternalPurchase
            };

            var costDbSetMock = _efContext.MockAsyncQueryable(new[] { cost }.AsQueryable(), d => d.Cost);

            costDbSetMock.Setup(c => c.FindAsync(costId)).ReturnsAsync(cost);

            _efContext.MockAsyncQueryable(new List <CostLineItem>().AsQueryable(), d => d.CostLineItem);

            return(cost);
        }