public void Setup() { _target = new CostLineItemUpdater(_efContextMock.Object, _revisionServiceMock.Object, _templateServiceMock.Object, new CostSectionFinder(), _costExchangeRateServiceMock.Object); var cost = new Cost(); var costStageRevision = new CostStageRevision() { CostLineItems = new List <CostLineItem> { new CostLineItem { } } }; var costTemplateVersion = new CostTemplateVersion(); var costTemplate = new CostTemplate(); var fieldDefinitions = new CustomFormData(); var usd = new Currency(); var euro = new Currency(); var gbp = new Currency(); cost.Id = _costId; costStageRevision.Id = _costStageRevisionId; cost.LatestCostStageRevision = costStageRevision; cost.LatestCostStageRevisionId = _costStageRevisionId; cost.CostTemplateVersion = costTemplateVersion; cost.CostTemplateVersionId = _costTemplateVersionId; costTemplateVersion.CostTemplate = costTemplate; costTemplateVersion.Id = _costTemplateVersionId; costTemplate.FieldDefinitions = fieldDefinitions; euro.Code = "EUR"; usd.Code = "USD"; gbp.Code = "GBP"; euro.Id = Guid.NewGuid(); usd.Id = _usdCurrencyId; gbp.Id = _gbpCurrencyId; var costs = new List <Cost> { cost }; _costStageRevisions = new List <CostStageRevision> { costStageRevision }; var currencies = new List <Currency> { euro, usd, gbp }; _efContextMock.MockAsyncQueryable(costs.AsQueryable(), c => c.Cost); _efContextMock.MockAsyncQueryable(_costStageRevisions.AsQueryable(), c => c.CostStageRevision); _efContextMock.MockAsyncQueryable(currencies.AsQueryable(), c => c.Currency); var stageDetails = new PgStageDetailsForm { ContentType = new core.Builders.DictionaryValue { Id = Guid.NewGuid(), Key = "Video", Value = "Video" }, CostType = dataAccess.Entity.CostType.Production.ToString(), ProductionType = new core.Builders.DictionaryValue { Id = Guid.NewGuid(), Key = "Full Production", Value = "Full Production" }, Title = "Cost Title" }; _revisionServiceMock.Setup(csr => csr.GetStageDetails <PgStageDetailsForm>(_costStageRevisionId)).ReturnsAsync(stageDetails); var costTemplateVersionModel = new CostTemplateVersionModel(); var productionDetailCollection = new List <ProductionDetailsTemplateModel>(); var productionDetails = new ProductionDetailsTemplateModel(); _form = new ProductionDetailsFormDefinitionModel { Name = FormName, Label = "Full production", ProductionType = Constants.ProductionType.FullProduction }; var section = new CostLineItemSectionTemplateModel(); var item = new CostLineItemSectionTemplateItemModel(); section.Name = SectionName; item.Name = ItemName; section.Items = new List <CostLineItemSectionTemplateItemModel> { item }; _form.CostLineItemSections = new List <CostLineItemSectionTemplateModel> { section }; productionDetails.Forms = new List <ProductionDetailsFormDefinitionModel> { _form }; productionDetails.Type = "Video"; productionDetailCollection.Add(productionDetails); costTemplateVersionModel.ProductionDetails = productionDetailCollection; _templateServiceMock.Setup(ts => ts.GetCostTemplateVersionModel(It.IsAny <Guid>())).ReturnsAsync(costTemplateVersionModel); _userIdentity = new UserIdentity { Id = _userId, IpAddress = "127.0.0.1" }; var expectedExchangeRates = new List <ExchangeRate>() { new ExchangeRate { FromCurrency = _usdCurrencyId, Rate = 1 }, }; _costExchangeRateServiceMock.Setup(cer => cer.GetExchangeRatesByDefaultCurrency(It.IsAny <Guid>())) .ReturnsAsync(expectedExchangeRates); }
public async Task CreateCost_whenCyclonAgencyAnd_shouldSetIsExternalPurchaseEnabledToFalse(bool isCycloneAgency, string budgetRegion, bool isExternalPurchasesEnabled) { // Arrange var userId = Guid.NewGuid(); var agencyId = Guid.NewGuid(); var agencyAbstractTypeId = Guid.NewGuid(); var projectId = "Gdam Porject Id"; var agency = new Agency { Id = agencyId, Name = "Name", Labels = isCycloneAgency ? new[] { Constants.Agency.CycloneLabel, Constants.Agency.PAndGLabel, $"{core.Constants.BusinessUnit.CostModulePrimaryLabelPrefix}P&G" } : new[] { Constants.Agency.PAndGLabel, $"{core.Constants.BusinessUnit.CostModulePrimaryLabelPrefix}P&G" }, AbstractTypes = new List <AbstractType> { new AbstractType { Id = Guid.NewGuid(), ObjectId = agencyId, } } }; agency.AbstractTypes.First().Agency = agency; var costUser = new CostUser { Id = userId, Agency = agency }; var abstractTypeAgency = new AbstractType { Id = agencyAbstractTypeId, Agency = agency, ObjectId = agencyId, Parent = new AbstractType { Agency = agency } }; EFContext.AbstractType.Add(abstractTypeAgency); EFContext.CostUser.Add(costUser); EFContext.SaveChanges(); var costTemplateVersion = new CostTemplateVersion { Id = Guid.NewGuid(), CostTemplate = new CostTemplate { Id = Guid.NewGuid(), CostType = CostType.Production } }; CostTemplateVersionServiceMock.Setup(ctv => ctv.GetLatestTemplateVersion(It.Is <Guid>(id => id == costTemplateVersion.CostTemplate.Id))) .ReturnsAsync(costTemplateVersion); var stageDetailsForm = new PgStageDetailsForm { ProjectId = projectId, BudgetRegion = new AbstractTypeValue { Key = budgetRegion }, Agency = new PgStageDetailsForm.AbstractTypeAgency { Id = abstractTypeAgency.ObjectId, AbstractTypeId = abstractTypeAgency.Id, } }; ProjectServiceMock.Setup(p => p.GetByGadmid(projectId)).ReturnsAsync(new Project { GdamProjectId = projectId, AgencyId = agencyId }); var stageDetails = new StageDetails { Data = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(JsonConvert.SerializeObject(stageDetailsForm)) }; var createCostModel = new CreateCostModel { TemplateId = costTemplateVersion.CostTemplate.Id, StageDetails = stageDetails }; PgStageBuilderMock.Setup(sb => sb.GetStages(It.IsAny <PgStageRule>(), null)) .ReturnsAsync(new Dictionary <string, StageModel> { { CostStages.New.ToString(), new StageModel { Key = CostStages.New.ToString(), Transitions = new Dictionary <string, StageModel> { { CostStages.OriginalEstimate.ToString(), new StageModel() } } } }, { CostStages.OriginalEstimate.ToString(), new StageModel { Key = CostStages.OriginalEstimate.ToString() } } }); RuleServiceMock.Setup(r => r.GetCompiledByRuleType <SupportingDocumentRule>(RuleType.SupportingDocument)).ReturnsAsync(new List <CompiledRule <SupportingDocumentRule> >()); // Act var result = await CostBuilder.CreateCost(costUser, createCostModel); // Assert result.Cost.IsExternalPurchasesEnabled.Should().Be(isExternalPurchasesEnabled); }
public void Setup() { _target = new CostCurrencyUpdater(_efContextMock.Object, _revisionServiceMock.Object); var costTemplateVersion = new CostTemplateVersion(); var costTemplate = new CostTemplate(); var fieldDefinitions = new CustomFormData(); var usd = new Currency(); var euro = new Currency(); _cost.Id = _costId; _costStageRevision.Id = _costStageRevisionId; _costStageRevision.StageDetailsId = Guid.NewGuid(); _cost.LatestCostStageRevision = _costStageRevision; _cost.LatestCostStageRevisionId = _costStageRevisionId; _cost.CostTemplateVersion = costTemplateVersion; _cost.CostTemplateVersionId = _costTemplateVersionId; costTemplateVersion.CostTemplate = costTemplate; costTemplateVersion.Id = _costTemplateVersionId; costTemplate.FieldDefinitions = fieldDefinitions; euro.Code = "EUR"; usd.Code = "USD"; euro.Id = Guid.NewGuid(); usd.Id = Guid.NewGuid(); var customFormData = "{\"costNumber\":\"AC1489594599188\",\"isAIPE\":false,\"projectId\":\"58c968410c885409aca51028\",\"title\":\"Full Prod\",\"description\":\"58c968410c885409aca51028\",\"contentType\":{\"id\":\"17cc6250-099a-11e7-84b7-1bf5c65c8e1a\",\"name\":\"Video\"},\"productionType\":{\"id\":\"17bec46a-099a-11e7-84b2-137a2ddbf0ee\",\"name\":\"Full Production\"},\"agencyProducer\":[\"Agency Producer 1\"],\"initialBudget\":1231231,\"budgetRegionId\":\"0f701f02-099a-11e7-945b-4b7e51cf96b3\",\"budgetRegion\":\"GREATER CHINA AREA\",\"organisation\":\"Other\",\"agencyCurrency\":\"USD\",\"campaign\":\"ad58c968410c885409aca51028\",\"agencyTrackingNumber\":\"58c968410c885409aca51028\"}"; _stageFormData.Data = customFormData; _stageFormData.Id = _costStageRevision.StageDetailsId; var costs = new List <Cost> { _cost }; var costStageRevisions = new List <CostStageRevision> { _costStageRevision }; var currencies = new List <Currency> { euro, usd }; _efContextMock.MockAsyncQueryable(costs.AsQueryable(), c => c.Cost); _efContextMock.MockAsyncQueryable(costStageRevisions.AsQueryable(), c => c.CostStageRevision); _efContextMock.MockAsyncQueryable(currencies.AsQueryable(), c => c.Currency); _efContextMock.MockAsyncQueryable(new[] { _stageFormData }.AsQueryable(), d => d.CustomFormData); _stageDetails.ContentType = new core.Builders.DictionaryValue { Id = Guid.NewGuid(), Key = "Video", Value = "Video" }; _stageDetails.CostType = CostType.Production.ToString(); _stageDetails.ProductionType = new core.Builders.DictionaryValue { Id = Guid.NewGuid(), Key = "Production", Value = "Production" }; _stageDetails.Title = "Cost Title"; _revisionServiceMock.Setup(csr => csr.GetStageDetails <PgStageDetailsForm>(_costStageRevisionId)).ReturnsAsync(_stageDetails); _revisionServiceMock.Setup(csr => csr.GetProductionDetails <PgProductionDetailsForm>(_costStageRevisionId)).ReturnsAsync(_productionDetails); }