public async Task CanEditIONumber_When__Trafficking_FAStageAndStatusIsNotDraft_Should_ReturnFalse(CostStageRevisionStatus status) { // Arrange var costStageObj = new CostStage { Key = CostStages.OriginalEstimate.ToString() }; var cost = new Cost { Id = Guid.NewGuid(), CostStages = new List <CostStage> { costStageObj }, LatestCostStageRevision = new CostStageRevision { CostStage = costStageObj }, Status = status, CostType = CostType.Trafficking }; _efContext.Add(cost); _efContext.SaveChanges(); // Act var canEditIONumber = await _pgRuleService.CanEditIONumber(cost.Id); // Assert canEditIONumber.Should().BeFalse(); }
public async Task ReturnNull_WhenNoPreviousRevision() { // Arrange var costStageKey = CostStages.FirstPresentation.ToString(); var costId = Guid.NewGuid(); var createdById = Guid.NewGuid(); var revision2 = new CostStageRevision { Id = Guid.NewGuid(), CreatedById = createdById, Created = DateTime.UtcNow }; var costStage = new CostStage { Key = costStageKey, Cost = new Cost { Id = costId }, CostStageRevisions = new List <CostStageRevision> { revision2 } }; EFContext.CostStage.Add(costStage); await EFContext.SaveChangesAsync(); // Act var previousRevision = await Service.GetPreviousRevision(revision2.Id); // Assert previousRevision.Should().BeNull(); }
public async Task CanEditIONumber_When_Production_FAStageAndStatusDraft_Should_ReturnFalse() { // Arrange var costStageObj = new CostStage { Key = CostStages.FinalActual.ToString() }; var cost = new Cost { Id = Guid.NewGuid(), CostStages = new List <CostStage> { costStageObj }, LatestCostStageRevision = new CostStageRevision { CostStage = costStageObj }, Status = CostStageRevisionStatus.Draft, CostType = CostType.Production }; _efContext.Add(cost); _efContext.SaveChanges(); // Act var canEditIONumber = await _pgRuleService.CanEditIONumber(cost.Id); // Assert canEditIONumber.Should().BeFalse(); }
public async Task CanEditIONumber_When_AIPE_OEStageDraft_Should_ReturnFalse() { // Arrange var currentStage = new CostStage { Key = CostStages.OriginalEstimate.ToString() }; var cost = new Cost { Id = Guid.NewGuid(), CostStages = new List <CostStage> { new CostStage { Key = CostStages.Aipe.ToString() }, currentStage }, LatestCostStageRevision = new CostStageRevision { CostStage = currentStage }, Status = CostStageRevisionStatus.Draft }; _efContext.Add(cost); _efContext.SaveChanges(); // Act var canEditIONumber = await _pgRuleService.CanEditIONumber(cost.Id); // Assert canEditIONumber.Should().BeFalse(); }
public void HasPreviousRevisions_HasRevisions() { //Arrange var cost = new Cost(); var latestRevision = new CostStageRevision(); var latestRevisionId = Guid.NewGuid(); var previousRevision = new CostStageRevision(); var previousRevisionId = Guid.NewGuid(); var costStage = new CostStage(); latestRevision.CostStage = costStage; latestRevision.Id = latestRevisionId; previousRevision.Id = previousRevisionId; costStage.CostStageRevisions.Add(latestRevision); costStage.CostStageRevisions.Add(previousRevision); cost.LatestCostStageRevision = latestRevision; //Act var result = cost.HasPreviousRevision(); //Assert result.Should().BeTrue(); }
public async Task Update_AgencyCurrency_From_BudgetForm_For_Aipe_InitialStage_Cost() { //Arrange var userId = _userId; var costId = _costId; var costStageRevisionId = _costStageRevisionId; const string initialAgencyCurrency = "GBP"; const string expectedAgencyCurrency = "EUR"; _stageDetails.AgencyCurrency = initialAgencyCurrency; var entries = new ExcelCellValueLookup { ["currency.agency"] = new ExcelCellValue { Value = expectedAgencyCurrency } }; var aipeStage = new CostStage { Key = CostStages.Aipe.ToString() }; _costStageRevision.CostStage = aipeStage; _costStageRevision.IsPaymentCurrencyLocked = false; //Act ServiceResult result = await _target.Update(entries, userId, costId, costStageRevisionId); //Assert result.Should().NotBeNull(); result.Success.Should().BeTrue(); _stageFormData.Data.Should().Contain(expectedAgencyCurrency); }
/// <summary> /// Get latest revision of Cost Stage with corresponding status /// <para>Required: Cost Stage has data of Revisions</para> /// </summary> public static CostStageRevision LatestRevision(this CostStage costStage) { return(costStage.CostStageRevisions .Where(csr => csr.Status != CostStageRevisionStatus.ReopenRejected) .OrderByDescending(csr => csr.Created) .FirstOrDefault()); }
public void GetPreviousRevision_HasOnePreviousRevision() { //Arrange var cost = new Cost(); var latestRevision = new CostStageRevision(); var latestRevisionId = Guid.NewGuid(); var previousRevision = new CostStageRevision(); var previousRevisionId = Guid.NewGuid(); var costStage = new CostStage(); latestRevision.CostStage = costStage; latestRevision.Id = latestRevisionId; latestRevision.Modified = DateTime.Now; latestRevision.Created = DateTime.Now; previousRevision.Id = previousRevisionId; previousRevision.Modified = DateTime.Now.AddSeconds(-1); previousRevision.Created = DateTime.Now.AddSeconds(-1); costStage.CostStageRevisions.Add(latestRevision); costStage.CostStageRevisions.Add(previousRevision); cost.LatestCostStageRevision = latestRevision; //Act var result = cost.GetPreviousRevision(); //Assert result.Should().NotBeNull(); result.Should().Be(previousRevision); }
public async Task GetPreviousCostStage_whenThereIsPreviousStage_shouldReturnPreviousCostStage() { // Arrange var costId = Guid.NewGuid(); var previousCostStage = new CostStage { Id = Guid.NewGuid(), CostId = costId, StageOrder = 0 }; var currentCostStage = new CostStage { Id = Guid.NewGuid(), CostId = costId, StageOrder = 1 }; _efContext.CostStage.AddRange(previousCostStage, currentCostStage); _efContext.SaveChanges(); // Act var costStage = await CostStageService.GetPreviousCostStage(currentCostStage.Id); // Assert costStage.Should().NotBeNull(); costStage.Id.Should().Be(previousCostStage.Id); }
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 Cost MockCost() { var costId = Guid.NewGuid(); var costStageId = Guid.NewGuid(); var costStageRevisionId = Guid.NewGuid(); var costStage = new CostStage { Id = costStageId }; var costStageRevision = new CostStageRevision { Id = costStageRevisionId, CostStage = costStage, CostStageId = costStageId }; var cost = new Cost { Id = costId, Status = CostStageRevisionStatus.Draft, LatestCostStageRevisionId = costStageRevisionId, LatestCostStageRevision = costStageRevision }; EFContext.Cost.Add(cost); EFContext.SaveChanges(); return(cost); }
public async Task GrNumbers_whenMultipleStages_shouldReturnGrNumberForEachVersionOfEachStage() { // Arrange var costSubmitted = GetCostRevisionStatusChanged(CostStageRevisionStatus.PendingCancellation); var costId = costSubmitted.AggregateId; var cost = SetupPurchaseOrderView(costId); var costStage1 = cost.LatestCostStageRevision.CostStage; var revision1 = cost.LatestCostStageRevision; var grNumber1 = "gr-number-1"; var revision2 = new CostStageRevision { Id = Guid.NewGuid() }; costStage1.CostStageRevisions.Add(revision2); var grNumber2 = "gr-number-2"; var costStage2 = new CostStage(); var revision3 = new CostStageRevision { Id = Guid.NewGuid(), CostStage = costStage2 }; costStage2.CostStageRevisions.Add(revision3); var grNumber3 = "gr-number-3"; _customDataServiceMock.Setup(cd => cd.GetCustomData <PgPurchaseOrderResponse>( It.Is <IEnumerable <Guid> >(ids => ids.Contains(revision1.Id) && ids.Contains(revision2.Id) && ids.Contains(revision2.Id)), CustomObjectDataKeys.PgPurchaseOrderResponse) ) .ReturnsAsync(new List <PgPurchaseOrderResponse> { new PgPurchaseOrderResponse { GrNumber = grNumber1 }, new PgPurchaseOrderResponse { GrNumber = grNumber2 }, new PgPurchaseOrderResponse { GrNumber = grNumber3 } }); // Act var purchase = await PgPurchaseOrderService.GetPurchaseOrder(costSubmitted); // Assert purchase.GrNumbers.Should().NotBeNull(); purchase.GrNumbers.Should().HaveCount(3); purchase.GrNumbers.Should().Contain(grNumber1); purchase.GrNumbers.Should().Contain(grNumber2); purchase.GrNumbers.Should().Contain(grNumber3); }
public async Task GetCostStagesLatestRevisions_OneStage() { // Arrange var currency = new Currency { Code = "AFN", DefaultCurrency = false, Description = "", Id = Guid.NewGuid(), Symbol = "symbol" }; var cost = new Cost { Id = Guid.NewGuid(), PaymentCurrency = currency }; const string costNumber = "AC1489594599188"; var costStage = new CostStage { Id = Guid.NewGuid(), CostId = cost.Id, CreatedById = Guid.NewGuid(), Created = DateTime.Now, Modified = DateTime.Now, Key = CostStages.OriginalEstimate.ToString(), StageOrder = 2, Cost = cost }; var costStageRevision = new CostStageRevision { StageDetails = new CustomFormData { Data = JsonConvert.SerializeObject(new PgStageDetailsForm { CostNumber = costNumber }, _serializerSettings) }, Id = Guid.NewGuid(), CostStage = costStage }; _efContext.CostStageRevision.Add(costStageRevision); _efContext.SaveChanges(); CostStageRevisionServiceMock.Setup(a => a.GetLatestRevisionWithPaymentCurrency(It.IsAny <Guid>())).ReturnsAsync(costStageRevision); // Act var result = await CostStageService.GetStagesLatestRevision(cost.Id, BuType.Pg); // Assert result.Should().HaveCount(1); result[0].Currency.Should().Be(currency); result[0].LatestRevision.Should().Be(costStageRevision); }
public async Task ReturnPreviousRevisionOfFromPreviousStage() { // Arrange var costStageKey1 = CostStages.OriginalEstimate.ToString(); var costStageKey2 = CostStages.FirstPresentation.ToString(); var costId = Guid.NewGuid(); var createdById = Guid.NewGuid(); var revision1 = new CostStageRevision { Id = Guid.NewGuid(), CreatedById = createdById, Created = DateTime.UtcNow, Status = CostStageRevisionStatus.Approved }; var revision2 = new CostStageRevision { Id = Guid.NewGuid(), CreatedById = createdById, Created = DateTime.UtcNow.AddMilliseconds(1) }; var costStage1 = new CostStage { Key = costStageKey1, Cost = new Cost { Id = costId }, CostStageRevisions = new List <CostStageRevision> { revision1 } }; var costStage2 = new CostStage { Key = costStageKey2, Cost = new Cost { Id = costId }, CostStageRevisions = new List <CostStageRevision> { revision2 } }; EFContext.CostStage.Add(costStage1); EFContext.CostStage.Add(costStage2); await EFContext.SaveChangesAsync(); // Act var previousRevision = await Service.GetPreviousRevision(revision2.Id); // Assert previousRevision.Id.Should().Be(revision1.Id); }
public async Task Do_Not_Update_AgencyCurrency_From_BudgetForm_For_LockedPaymentCurrency() { //Arrange var userId = _userId; var costId = _costId; var costStageRevisionId = _costStageRevisionId; const string initialAgencyCurrency = "GBP"; const string expectedAgencyCurrency = "EUR"; _stageDetails.AgencyCurrency = initialAgencyCurrency; var entries = new ExcelCellValueLookup { ["currency.agency"] = new ExcelCellValue { Value = expectedAgencyCurrency } }; var originalEstimateStage = new CostStage { Key = CostStages.OriginalEstimate.ToString() }; var originalEstimateRevisionStage = new CostStage { Key = CostStages.OriginalEstimateRevision.ToString() }; _costStageRevision.CostStage = originalEstimateRevisionStage; _costStageRevision.IsPaymentCurrencyLocked = true; var firstRevision = new CostStageRevision(); firstRevision.CostStage = originalEstimateStage; firstRevision.IsPaymentCurrencyLocked = false; originalEstimateRevisionStage.CostStageRevisions = new List <CostStageRevision> { firstRevision, _costStageRevision }; //Act ServiceResult result = await _target.Update(entries, userId, costId, costStageRevisionId); //Assert result.Should().NotBeNull(); result.Success.Should().BeFalse(); result.Errors.Should().NotBeNull(); result.Errors.Should().HaveCount(1); _stageFormData.Data.Should().NotContain(expectedAgencyCurrency); }
public CostStageRevision UpdateCostStageDetails(CostStage costStage, CostStageRevision revision) { var stageDetailsForm = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(revision.StageDetails.Data); if (costStage.Cost.CostType == CostType.Buyout && costStage.Key == CostStages.FinalActual.ToString()) { stageDetailsForm[nameof(PgStageDetailsForm.ApprovalStage)] = CostStages.FinalActual.ToString(); } var serializationSettings = new JsonSerializerSettings { Formatting = Formatting.None, ContractResolver = new CamelCasePropertyNamesContractResolver() }; revision.StageDetails.Data = JsonConvert.SerializeObject(stageDetailsForm, serializationSettings); return(revision); }
public async Task ReturnNull_WhenPreviousRevisionOfTheSameStage_AndStatusIsNotApprovedOrPendingApproval(CostStageRevisionStatus status) { // Arrange var costStageKey = CostStages.FirstPresentation.ToString(); var costId = Guid.NewGuid(); var createdById = Guid.NewGuid(); var revision1 = new CostStageRevision { Id = Guid.NewGuid(), CreatedById = createdById, Created = DateTime.UtcNow, Status = status }; var revision2 = new CostStageRevision { Id = Guid.NewGuid(), CreatedById = createdById, Created = DateTime.UtcNow.AddMilliseconds(1) }; var costStage = new CostStage { Key = costStageKey, Cost = new Cost { Id = costId }, CostStageRevisions = new List <CostStageRevision> { revision1, revision2 } }; EFContext.CostStage.Add(costStage); await EFContext.SaveChangesAsync(); // Act var previousRevision = await Service.GetPreviousRevision(revision2.Id); // Assert previousRevision.Should().BeNull(); }
/// <summary> /// Convert from CostStage to CostStageModel - correct data used for frontend to view /// <para>Required: Cost Stage has data of Revisions</para> /// </summary> public static CostStageModel ToCostStageModel(this CostStage costStage, List <ExchangeRate> exchangeRates, Guid defaultPaymentCurrencyId) { var model = new CostStageModel { Id = costStage.Id, CostId = costStage.CostId, Key = costStage.Key, Name = costStage.Name, }; if (costStage.CostStageRevisions.Any()) { var ordered = costStage.CostStageRevisions.OrderBy(csr => csr.Created).Where(r => r.Status != CostStageRevisionStatus.ReopenRejected).ToArray(); var latest = ordered.LastOrDefault(r => r.Approvals.All(a => a.Status == ApprovalStatus.Approved)) ?? ordered.Last(); model.Status = ordered.Last().Status; model.cost = new CostStageModel.Cost(); var totals = latest.GetRevisionTotals(exchangeRates, defaultPaymentCurrencyId); model.cost.Total = totals.total; model.cost.TotalInLocalCurrency = totals.totalInLocalCurrency; model.cost.LocalCurrencySymbol = costStage.Cost.PaymentCurrency?.Symbol; model.cost.LocalCurrencyCode = costStage.Cost.PaymentCurrency?.Code; model.Revisions = ordered .Select(csr => new CostStageModel.CostStageRevision { Id = csr.Id, Name = csr.Name, Status = csr.Status }) .ToList(); } return(model); }
private dataAccess.Entity.Cost BuildCost(Guid costId, CostUser[] costUsers, dataAccess.Entity.Project project) { const string agencyName = "Saatchi"; const string brandName = "P&G"; const string costNumber = "P101"; const CostStages costStageName = CostStages.OriginalEstimate; var cost = new dataAccess.Entity.Cost { Parent = new AbstractType() }; var costOwner = costUsers[0]; var latestRevision = new CostStageRevision(); var costStage = new CostStage(); var brand = new dataAccess.Entity.Brand(); var agency = new dataAccess.Entity.Agency(); cost.CostNumber = costNumber; cost.LatestCostStageRevision = latestRevision; cost.Project = project; cost.Parent.Agency = agency; costOwner.Agency = agency; costOwner.Id = Guid.NewGuid(); latestRevision.CostStage = costStage; agency.Name = agencyName; brand.Name = brandName; cost.Id = costId; costStage.Name = costStageName.ToString(); latestRevision.Id = Guid.NewGuid(); return(cost); }
private void SetupDataSharedAcrossTests() { const string agencyLocation = "United Kingdom"; const string agencyName = "Saatchi"; const string brandName = "P&G"; const string costNumber = "P101"; const CostStages costStageName = CostStages.OriginalEstimate; const string costOwnerGdamUserId = "57e5461ed9563f268ef4f19d"; const string costOwnerFullName = "Mr Cost Owner"; const string projectName = "Pampers"; const string projectGdamId = "57e5461ed9563f268ef4f19c"; const string projectNumber = "PandG01"; var projectId = Guid.NewGuid(); _cost = new Cost(); var costOwner = new CostUser { UserBusinessRoles = new List <UserBusinessRole> { new UserBusinessRole { BusinessRole = new BusinessRole { Key = Constants.BusinessRole.FinanceManager, Value = Constants.BusinessRole.FinanceManager } } } }; var approverUser = new CostUser { UserBusinessRoles = new List <UserBusinessRole> { new UserBusinessRole { BusinessRole = new BusinessRole { Key = Constants.BusinessRole.Ipm, Value = Constants.BusinessRole.Ipm } } } }; var insuranceUser = new CostUser { UserBusinessRoles = new List <UserBusinessRole> { new UserBusinessRole { BusinessRole = new BusinessRole { Key = Constants.BusinessRole.InsuranceUser, Value = Constants.BusinessRole.InsuranceUser } } } }; var latestRevision = new CostStageRevision(); var costStage = new CostStage(); var project = new Project(); var brand = new Brand(); var agency = new Agency(); var country = new Country(); agency.Country = country; approverUser.Id = _approverUserId; _cost.CreatedBy = costOwner; _cost.CreatedById = _costOwnerId; _cost.Owner = costOwner; _cost.OwnerId = _costOwnerId; _cost.CostNumber = costNumber; _cost.LatestCostStageRevision = latestRevision; _cost.Project = project; costOwner.Agency = agency; costOwner.Id = _costOwnerId; insuranceUser.Id = _insuranceUserId; 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; costOwner.Id = _costOwnerId; latestRevision.Id = _costStageRevisionId; project.Id = projectId; project.Name = projectName; project.GdamProjectId = projectGdamId; project.AdCostNumber = projectNumber; country.Name = agencyLocation; var agencies = new List <Agency> { agency }; var brands = new List <Brand> { brand }; var costs = new List <Cost> { _cost }; var costStages = new List <CostStageRevision> { latestRevision }; var costUsers = new List <CostUser> { approverUser, costOwner, insuranceUser }; var countries = new List <Country> { country }; var projects = new List <Project> { project }; _efContextMock.MockAsyncQueryable(agencies.AsQueryable(), c => c.Agency); _efContextMock.MockAsyncQueryable(brands.AsQueryable(), c => c.Brand); _efContextMock.MockAsyncQueryable(costs.AsQueryable(), c => c.Cost); _efContextMock.MockAsyncQueryable(costStages.AsQueryable(), c => c.CostStageRevision); _efContextMock.MockAsyncQueryable(costUsers.AsQueryable(), c => c.CostUser); _efContextMock.MockAsyncQueryable(countries.AsQueryable(), c => c.Country); _efContextMock.MockAsyncQueryable(projects.AsQueryable(), c => c.Project); _efContextMock.MockAsyncQueryable(new List <NotificationSubscriber> { new NotificationSubscriber { CostId = _cost.Id, CostUserId = _costOwnerId, CostUser = costOwner } }.AsQueryable(), a => a.NotificationSubscriber); _stageDetails = new PgStageDetailsForm { Title = "Test Title", BudgetRegion = new AbstractTypeValue { Name = Constants.BudgetRegion.AsiaPacific }, ContentType = new core.Builders.DictionaryValue { Value = Constants.ContentType.Audio }, ProductionType = new core.Builders.DictionaryValue { Value = Constants.ProductionType.PostProductionOnly } }; _costStageRevisionServiceMock.Setup(c => c.GetStageDetails <PgStageDetailsForm>(_cost.LatestCostStageRevision)).Returns(_stageDetails); }
public BillingExpenseData BuildExpenses(CostStage costStage, IList <BillingExpense> billingExpenses, IList <FinancialYear> financialYears) { var billingExpensesLookup = CreateLookup(billingExpenses); var data = new BillingExpenseData(); financialYears.ForEach(fy => data.FinancialYears.Add(fy.ShortName)); data.Sections.Add(new BillingExpenseDataSection { Key = Constants.BillingExpenseSection.ContractTerms, Label = "Billing to P&G for contract terms" }); data.Sections.Add(new BillingExpenseDataSection { Key = Constants.BillingExpenseSection.IncurredCosts, Label = "Incurred costs, pre, bonus payments, etc." }); data.Header.Rows.Add(new BillingExpenseRow { Key = Constants.BillingExpenseItem.BalancePrepaid, Label = "BALANCE FROM PRIOR FY/PREPAID", Type = "currency" }); var noOfMonthsRow = new BillingExpenseRow { Key = Constants.BillingExpenseItem.NumberOfMonthsFY, Label = "No. of months in contract term per FY", Type = "number" }; data.Header.Rows.Add(noOfMonthsRow); data.Sections[0].Rows.Add(new BillingExpenseRow { Key = Constants.BillingExpenseItem.UsageBuyoutFee, Label = "Base Compensation", Type = "currency" }); data.Sections[0].Rows.Add(new BillingExpenseRow { Key = Constants.BillingExpenseItem.PensionAndHealth, Label = "Pension & Health", Type = "currency" }); data.Sections[1].Rows.Add(new BillingExpenseRow { Key = Constants.BillingExpenseItem.Bonus, Label = "Bonus", Type = "currency" }); data.Sections[1].Rows.Add(new BillingExpenseRow { Key = Constants.BillingExpenseItem.AgencyFee, Label = "Agency fee (PRE or other)", Type = "currency" }); data.Sections[1].Rows.Add(new BillingExpenseRow { Key = Constants.BillingExpenseItem.OtherCosts, Label = "Other incurred costs (including non-reclaimable taxes)", Type = "currency" }); data.Sections[0].Totals = new BillingExpenseTotalRow { SectionKey = Constants.BillingExpenseSection.ContractTerms, Key = Constants.BillingExpenseSectionTotal.ContractTerms, Label = "Total billing for contract terms" }; data.Sections[1].Totals = new BillingExpenseTotalRow { SectionKey = Constants.BillingExpenseSection.IncurredCosts, Key = Constants.BillingExpenseSectionTotal.IncurredCosts, Label = "Total billing for incurred costs, bonuses, etc." }; financialYears.ForEach(year => { data.Sections.ForEach(section => { section.Rows.ForEach(row => { if (row.Key != Constants.BillingExpenseItem.NumberOfMonthsFY) { row.Cells.Add( GetOrCreateItem(billingExpensesLookup, section.Key, row.Key, year.ShortName) ); } }); }); }); var totalMonths = 0; financialYears.ForEach(year => { noOfMonthsRow.Cells.Add(GetNumberOfMonthsItem(billingExpensesLookup, costStage, year)); totalMonths += year.Months; }); noOfMonthsRow.Total = totalMonths; data.Summary.Rows.Add(new BillingExpenseCalculatedRow { Key = Constants.BillingExpenseSummaryItem.TotalContractTermsAndIncurredCosts, Label = "Total billing for contract terms & bonuses, etc.", Type = "currency" }); data.Summary.Rows.Add(new BillingExpenseCalculatedRow { Key = Constants.BillingExpenseSummaryItem.ExpensePerFY, Label = "Expense per FY", Type = "currency" }); data.Summary.Rows.Add(new BillingExpenseCalculatedRow { Key = Constants.BillingExpenseSummaryItem.BalanceToBeMoved, Label = "Balance to be moved to prepaid", Type = "currency" }); return(data); }
public async Task GetApprovedOrLastRevision_Should_Get_Last_Revision_For_Not_Approved_Stage() { // Arrange var lastRevisionId = Guid.NewGuid(); var cost = new Cost { Id = Guid.NewGuid(), LatestCostStageRevisionId = lastRevisionId }; var previsiousId = Guid.NewGuid(); var costStageOe = new CostStage { Id = Guid.NewGuid(), CostId = cost.Id, CreatedById = Guid.NewGuid(), Created = DateTime.Now, Modified = DateTime.Now, Key = CostStages.OriginalEstimate.ToString(), StageOrder = 2, Cost = cost }; var firstRevisionCreated = DateTime.UtcNow; var costStageRevisions = new List <CostStageRevision> { new CostStageRevision { CostStage = costStageOe, Id = Guid.NewGuid(), Created = firstRevisionCreated, Approvals = new List <Approval> { new Approval { Status = ApprovalStatus.Rejected } }, CostLineItems = new List <CostLineItem> { new CostLineItem { Name = "ABCD", ValueInDefaultCurrency = 1000, ValueInLocalCurrency = 1000 } } }, new CostStageRevision { Id = previsiousId, CostStage = costStageOe, Created = firstRevisionCreated.AddDays(1), Approvals = new List <Approval> { new Approval { Status = ApprovalStatus.Rejected } }, CostLineItems = new List <CostLineItem> { new CostLineItem { Name = "ABCD", ValueInDefaultCurrency = 2000, ValueInLocalCurrency = 2000 } } }, new CostStageRevision { Id = lastRevisionId, CostStage = costStageOe, Created = firstRevisionCreated.AddDays(2), Approvals = new List <Approval> { new Approval { Status = ApprovalStatus.Rejected } }, CostLineItems = new List <CostLineItem> { new CostLineItem { Name = "ABCD", ValueInDefaultCurrency = 3000, ValueInLocalCurrency = 3000 } } } }; _efContext.CostStageRevision.AddRange(costStageRevisions); _efContext.SaveChanges(); // Act var result = await CostStageService.GetApprovedOrLastRevision(cost.Id, CostStages.OriginalEstimate.ToString()); // Assert result.LatestRevision.Id.ShouldBeEquivalentTo(previsiousId); }
private Cost SetCostStage(out Guid approvedRevisionId) { approvedRevisionId = Guid.NewGuid(); var cost = new Cost { Id = Guid.NewGuid(), CostStages = new List <CostStage>(), PaymentCurrency = new Currency { Code = "AFN", DefaultCurrency = false, Description = "", Id = Guid.NewGuid(), Symbol = "symbol" } }; var costStageOe = new CostStage { Id = Guid.NewGuid(), Cost = cost, CreatedById = Guid.NewGuid(), Created = DateTime.Now, Modified = DateTime.Now, Key = CostStages.OriginalEstimate.ToString(), StageOrder = 2, CostStageRevisions = new List <CostStageRevision> { new CostStageRevision { Id = Guid.NewGuid(), Approvals = new List <Approval> { new Approval { Status = ApprovalStatus.Rejected } }, CostLineItems = new List <CostLineItem> { new CostLineItem { Name = "ABCD", ValueInDefaultCurrency = 1000, ValueInLocalCurrency = 1000 } } }, new CostStageRevision { Id = approvedRevisionId, Approvals = new List <Approval> { new Approval { Status = ApprovalStatus.Approved } }, CostLineItems = new List <CostLineItem> { new CostLineItem { Name = "ABCD", ValueInDefaultCurrency = 2000, ValueInLocalCurrency = 2000 } }, StageDetails = new CustomFormData { Data = JsonConvert.SerializeObject(new PgStageDetailsForm(), _serializerSettings) } }, new CostStageRevision { Id = Guid.NewGuid(), Approvals = new List <Approval> { new Approval { Status = ApprovalStatus.Rejected } }, CostLineItems = new List <CostLineItem> { new CostLineItem { Name = "ABCD", ValueInDefaultCurrency = 3000, ValueInLocalCurrency = 3000 } }, StageDetails = new CustomFormData { Data = JsonConvert.SerializeObject(new PgStageDetailsForm(), _serializerSettings) } } } }; cost.CostStages.Add(costStageOe); _efContext.Cost.AddRange(cost); _efContext.SaveChanges(); cost.LatestCostStageRevision = costStageOe.CostStageRevisions.Last(); _efContext.SaveChanges(); return(cost); }
private void SetupDataSharedAcrossTests() { const string agencyLocation = "United Kingdom"; const string agencyName = "Saatchi"; const string brandName = "P&G"; const string costNumber = "P101"; const CostStages costStageName = CostStages.OriginalEstimate; const string costOwnerGdamUserId = "57e5461ed9563f268ef4f19d"; const string costOwnerFullName = "Mr Cost Owner"; const string projectName = "Pampers"; const string projectGdamId = "57e5461ed9563f268ef4f19c"; const string projectNumber = "PandG01"; var projectId = Guid.NewGuid(); _cost = new Cost(); var costOwner = new CostUser { UserBusinessRoles = new List <UserBusinessRole> { new UserBusinessRole { BusinessRole = new BusinessRole { Key = Constants.BusinessRole.FinanceManager, Value = Constants.BusinessRole.FinanceManager } } } }; var approverUser = new CostUser { UserBusinessRoles = new List <UserBusinessRole> { new UserBusinessRole { BusinessRole = new BusinessRole { Key = Constants.BusinessRole.Ipm, Value = Constants.BusinessRole.Ipm } } } }; var insuranceUser = new CostUser { UserBusinessRoles = new List <UserBusinessRole> { new UserBusinessRole { BusinessRole = new BusinessRole { Key = Constants.BusinessRole.InsuranceUser, Value = Constants.BusinessRole.InsuranceUser } } } }; var latestRevision = new CostStageRevision(); var costStage = new CostStage(); var project = new dataAccess.Entity.Project(); var brand = new Brand(); var agency = new dataAccess.Entity.Agency(); var country = new Country(); agency.Country = country; approverUser.Id = _approverUserId; _cost.CostNumber = costNumber; _cost.LatestCostStageRevision = latestRevision; _cost.Project = project; _cost.Owner = costOwner; costOwner.Agency = agency; costOwner.Id = _costOwnerId; insuranceUser.Id = _insuranceUserId; 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; costOwner.Id = _costOwnerId; latestRevision.Id = _costStageRevisionId; project.Id = projectId; project.Name = projectName; project.GdamProjectId = projectGdamId; project.AdCostNumber = projectNumber; country.Name = agencyLocation; var agencies = new List <dataAccess.Entity.Agency> { agency }; var brands = new List <Brand> { brand }; var costs = new List <Cost> { _cost }; var costStages = new List <CostStageRevision> { latestRevision }; var costUsers = new List <CostUser> { approverUser, costOwner, insuranceUser }; var countries = new List <Country> { country }; var projects = new List <dataAccess.Entity.Project> { project }; var insuranceUsers = new List <string> { _insuranceUserGdamId }; _efContextMock.MockAsyncQueryable(agencies.AsQueryable(), c => c.Agency); _efContextMock.MockAsyncQueryable(brands.AsQueryable(), c => c.Brand); _efContextMock.MockAsyncQueryable(costs.AsQueryable(), c => c.Cost); _efContextMock.MockAsyncQueryable(costStages.AsQueryable(), c => c.CostStageRevision); _efContextMock.MockAsyncQueryable(costUsers.AsQueryable(), c => c.CostUser); _efContextMock.MockAsyncQueryable(countries.AsQueryable(), c => c.Country); _efContextMock.MockAsyncQueryable(projects.AsQueryable(), c => c.Project); _costUserServiceMock.Setup(cus => cus.GetInsuranceUsers(It.IsAny <dataAccess.Entity.Agency>())).Returns(Task.FromResult(insuranceUsers)); _efContextMock.MockAsyncQueryable(new List <NotificationSubscriber> { new NotificationSubscriber { CostId = _cost.Id, CostUserId = _costOwnerId, CostUser = costOwner } }.AsQueryable(), a => a.NotificationSubscriber); }
public async Task GetCostStagesLatestRevisions_2ApprovedFAs() { // Arrange var currency = new Currency { Code = "USD", DefaultCurrency = false, Description = "", Id = Guid.NewGuid(), Symbol = "$" }; var cost = new Cost { Id = Guid.NewGuid(), PaymentCurrency = currency }; var costStageRevisionId = Guid.NewGuid(); const string costNumber = "PGU0000001V0029"; var costStageOe = new CostStage { Id = Guid.NewGuid(), CostId = cost.Id, CreatedById = Guid.NewGuid(), Created = DateTime.Now, Modified = DateTime.Now, Key = CostStages.OriginalEstimate.ToString(), StageOrder = 1, Cost = cost }; var costStageFP = new CostStage { Id = Guid.NewGuid(), CostId = cost.Id, CreatedById = Guid.NewGuid(), Created = DateTime.Now, Modified = DateTime.Now, Key = CostStages.FirstPresentation.ToString(), StageOrder = 2 }; var costStageFA = new CostStage { Id = Guid.NewGuid(), CostId = cost.Id, CreatedById = Guid.NewGuid(), Created = DateTime.Now, Modified = DateTime.Now, Key = CostStages.FinalActual.ToString(), StageOrder = 3 }; var costStageRevisionFA1 = new CostStageRevision { Id = Guid.NewGuid(), StageDetailsId = costStageRevisionId, StageDetails = new CustomFormData { Id = costStageRevisionId, Data = JsonConvert.SerializeObject(new PgStageDetailsForm { CostNumber = costNumber }, _serializerSettings) }, CostStage = costStageFA, Status = CostStageRevisionStatus.Approved, IsLineItemSectionCurrencyLocked = true, IsPaymentCurrencyLocked = true }; var costStageRevisionFA2 = new CostStageRevision { Id = Guid.NewGuid(), StageDetailsId = costStageRevisionId, StageDetails = new CustomFormData { Id = costStageRevisionId, Data = JsonConvert.SerializeObject(new PgStageDetailsForm { CostNumber = costNumber }, _serializerSettings) }, CostStage = costStageFA, Status = CostStageRevisionStatus.PendingTechnicalApproval, IsLineItemSectionCurrencyLocked = true, IsPaymentCurrencyLocked = true }; var costStageRevisionPaymentTotalFA1 = new CostStageRevisionPaymentTotal { Id = Guid.NewGuid(), CostStageRevision = costStageRevisionFA1, LineItemTotalType = "CostTotal", LineItemFullCost = 41000, LineItemTotalCalculatedValue = 25500, IsProjection = false, StageName = CostStages.FinalActual.ToString(), CalculatedAt = DateTime.Now }; var costStageRevisionPaymentTotalFA2 = new CostStageRevisionPaymentTotal { Id = Guid.NewGuid(), CostStageRevision = costStageRevisionFA2, LineItemTotalType = "CostTotal", LineItemFullCost = 35000, LineItemTotalCalculatedValue = -6000,//35000-41000 IsProjection = false, StageName = CostStages.FinalActual.ToString(), CalculatedAt = DateTime.Now }; _efContext.CostStage.AddRange(costStageOe, costStageFP, costStageFA); _efContext.CostStageRevision.AddRange(costStageRevisionFA1, costStageRevisionFA2); _efContext.Currency.Add(currency); _efContext.SaveChanges(); var costStageRevisionPaymentTotals = new List <CostStageRevisionPaymentTotal> { costStageRevisionPaymentTotalFA1, costStageRevisionPaymentTotalFA2 }; CostStageRevisionServiceMock.Setup(a => a.GetLatestRevisionWithPaymentCurrency(It.IsAny <Guid>())).ReturnsAsync(costStageRevisionFA2); CostStageRevisionServiceMock.Setup(a => a.GetAllCostPaymentTotalsFinalActual(It.IsAny <Guid>(), It.IsAny <Guid>())).ReturnsAsync(costStageRevisionPaymentTotals); // Act var result = await CostStageService.GetStagesLatestRevision(cost.Id, BuType.Pg); // Assert result.Should().HaveCount(3); ((string)result[2].StageDetails.costNumber).Should().Be(costNumber); result[2].LatestRevision.Should().Be(costStageRevisionFA2); result[2].DisplayGRAmount.Should().Be(19500); }
private void SetupRevision(out UserIdentity user, out Guid costStageRevisionId, out Guid newCostStageId, out CostStageRevision currentCostStageRevision, out CostStage newCostStage) { // Arrange var userId = Guid.NewGuid(); user = new UserIdentity { AgencyId = Guid.NewGuid(), BuType = BuType.Pg, Email = "*****@*****.**", FirstName = "Test", FullName = "Test Test", LastName = "Test", GdamUserId = "58888a9b0c885449176a5fa5", Id = userId, ModuleId = Guid.NewGuid(), }; var costId = Guid.NewGuid(); var costStageId = Guid.NewGuid(); costStageRevisionId = Guid.NewGuid(); var stageDetailsId = Guid.NewGuid(); var productionDetailsId = Guid.NewGuid(); var costLineItemId = Guid.NewGuid(); newCostStageId = Guid.NewGuid(); var currentCostStage = new CostStage { CostId = costId, Created = DateTime.UtcNow, CreatedById = userId, Id = costStageId, Modified = DateTime.UtcNow, Key = CostStages.New.ToString(), StageOrder = 0, Cost = new Cost { CostType = CostType.Production } }; var costLineItem = new CostLineItem { CostStageRevisionId = costStageRevisionId, Created = DateTime.UtcNow, CreatedById = user.Id, Id = costLineItemId, LocalCurrencyId = Guid.NewGuid(), Modified = DateTime.UtcNow, Name = "cast", TemplateSectionId = Guid.NewGuid(), ValueInDefaultCurrency = Decimal.Parse("1.2", CultureInfo.InvariantCulture), ValueInLocalCurrency = Decimal.Parse("1.0", CultureInfo.InvariantCulture), }; currentCostStageRevision = new CostStageRevision { Status = CostStageRevisionStatus.Draft, CostStageId = costStageId, Created = DateTime.UtcNow, CreatedById = Guid.NewGuid(), Id = costStageRevisionId, Modified = DateTime.UtcNow, Name = CostStageRevisionStatus.Draft.ToString(), ProductDetailsId = productionDetailsId, ProductDetails = new CustomFormData { Id = productionDetailsId, Data = JsonConvert.SerializeObject(new Dictionary <string, dynamic>()) }, StageDetails = new CustomFormData { Id = stageDetailsId, Data = JsonConvert.SerializeObject(new Dictionary <string, dynamic>()) }, StageDetailsId = stageDetailsId, CostStage = currentCostStage, CostLineItems = new List <CostLineItem> { costLineItem }, SupportingDocuments = new List <SupportingDocument> { new SupportingDocument(userId) { Id = Guid.NewGuid(), Name = "Name", Key = "key", SupportingDocumentRevisions = new List <SupportingDocumentRevision> { new SupportingDocumentRevision(userId) { Id = Guid.NewGuid(), FileName = "FileName", GdnId = "GDNID" } } } }, CostFormDetails = new List <CostFormDetails>(), }; newCostStage = new CostStage { CostId = costId, Created = DateTime.UtcNow, CreatedById = userId, Id = newCostStageId, Modified = DateTime.UtcNow, Key = CostStages.New.ToString(), StageOrder = 0 }; // IStageDetails stageDetails, CostType costType, IEnumerable<string> stageKeys _efContext.CostStageRevision.Add(currentCostStageRevision); _efContext.CustomFormData.Add(new CustomFormData { Data = "emptyString", Id = Guid.NewGuid() }); _costBuilderMock.Setup(s => s.BuildSupportingDocuments(It.IsAny <IStageDetails>(), It.IsAny <CostType>(), It.IsAny <IEnumerable <string> >(), It.IsAny <Guid>(), It.IsAny <bool>())) .ReturnsAsync(new List <SupportingDocumentModel>()); _efContext.SaveChanges(); }
private BillingExpenseItem GetNumberOfMonthsItem(IDictionary <string, BillingExpense> lookup, CostStage costStage, FinancialYear year) { var readOnly = false; if (costStage.Name == CostStages.FinalActual.ToString()) { readOnly = true; } else if (year.IsPastYear()) { readOnly = true; } var item = GetOrCreateItem(lookup, Constants.BillingExpenseSection.Header, Constants.BillingExpenseItem.NumberOfMonthsFY, year.ShortName, year.Months); item.ReadOnly = readOnly; return(item); }
private void SetupPurchaseOrderCost(Cost cost, CostStageRevision latestRevision, CostUser costOwner, Guid previousRevisionId, Guid latestRevisionId, string poNumber) { const string brandApproverGdamUserId = "57e5461ed9563f268ef4f1ta"; const string brandApproverName = "John Smith"; var costId = Guid.NewGuid(); var costOwnerId = Guid.NewGuid(); var projectId = Guid.NewGuid(); var previousStageId = Guid.NewGuid(); var latestStageId = Guid.NewGuid(); var previousRevision = new CostStageRevision(); var previousStage = new CostStage(); var latestStage = new CostStage(); var project = new Project(); var brand = new Brand(); var agency = new Agency(); var country = new Country(); var brandApproval = new Approval(); var brandApprover = new ApprovalMember(); var brandApproverAsCostUser = new CostUser(); previousRevision.CostStage = previousStage; previousRevision.Id = previousRevisionId; previousStage.Id = previousRevision.CostStageId = previousStageId; latestStage.Id = latestRevision.CostStageId = latestStageId; previousStage.Name = CostStages.OriginalEstimate.ToString(); latestStage.Name = CostStages.FinalActual.ToString(); cost.CostStages.AddRange(new[] { previousStage, latestStage }); //China non-Cyclone Agencies should create a notification for non-backup approver when the cost total amount has changed SetupDataSharedAcrossTests(agency, country, cost, latestRevision, project, costOwner, costOwnerId, latestStage, brand, costId, latestRevisionId, projectId, Constants.BudgetRegion.China); brandApproval.ApprovalMembers = new List <ApprovalMember> { brandApprover }; brandApprover.CostUser = brandApproverAsCostUser; brandApproval.Type = ApprovalType.Brand; brandApproverAsCostUser.GdamUserId = brandApproverGdamUserId; brandApproverAsCostUser.FullName = brandApproverName; var approvals = new List <Approval> { brandApproval }; ApprovalServiceMock.Setup(a => a.GetApprovalsByCostStageRevisionId(It.IsAny <Guid>(), true)).ReturnsAsync(approvals); var pgPaymentDetails = new PgPaymentDetails { PoNumber = poNumber }; CostStageServiceMock.Setup(cssm => cssm.GetPreviousCostStage(latestStageId)).Returns(Task.FromResult(previousStage)); CostStageRevisionServiceMock.Setup(csrsm => csrsm.GetLatestRevision(previousStageId)).Returns(Task.FromResult(previousRevision)); CustomObjectDataServiceMock .Setup(codsm => codsm.GetCustomData <PgPaymentDetails>(latestRevisionId, CustomObjectDataKeys.PgPaymentDetails)) .Returns(Task.FromResult(pgPaymentDetails)); CustomObjectDataServiceMock .Setup(codsm => codsm.GetCustomData <PgPaymentDetails>(previousRevisionId, CustomObjectDataKeys.PgPaymentDetails)) .Returns(Task.FromResult(pgPaymentDetails)); }
protected void InitDataForReopenedFA( bool isAipe = false, string stageKey = "Aipe", string budgetRegion = "AAK (Asia)", List <CostLineItemView> items = null, List <CostLineItemView> previousFAItems = null, string targetBudget = "0", List <CostStageRevisionPaymentTotal> payments = null, List <CostStageRevisionPaymentTotal> previousFAPayments = null, string contentType = Constants.ContentType.Video, string productionType = Constants.ProductionType.FullProduction, CostType costType = CostType.Production, string agencyCurrency = "USD", Guid?dpvCurrency = null, Guid?dpvId = null, string vendorCategory = null ) { SetupCurrencies(); var previousCostStageRevisionId = Guid.NewGuid(); _costStageRevisionId = Guid.NewGuid(); var _costPreviousStageRevisionId = Guid.NewGuid(); var costId = Guid.NewGuid(); var costStageId = Guid.NewGuid(); var paymentCurrencyId = dpvCurrency ?? _efContext.Currency.FirstOrDefault(c => c.Code == agencyCurrency)?.Id; _stage = new CostStage { Key = stageKey, Id = costStageId }; _contentType = contentType; _productionType = productionType; _stageDetails = GetStageDetails(isAipe, budgetRegion, targetBudget, costType, agencyCurrency); _productionDetails = GetProductionDetails(dpvCurrency, dpvId, vendorCategory); _revision = new CostStageRevision { Id = _costStageRevisionId, StageDetails = new CustomFormData { Data = JsonConvert.SerializeObject(_stageDetails) }, ProductDetails = new CustomFormData { Data = JsonConvert.SerializeObject(_productionDetails) }, CostStage = _stage, Status = CostStageRevisionStatus.Approved, Approvals = new List <Approval>() }; _previousRevision = new CostStageRevision { Id = _costPreviousStageRevisionId, StageDetails = new CustomFormData { Data = JsonConvert.SerializeObject(_stageDetails) }, ProductDetails = new CustomFormData { Data = JsonConvert.SerializeObject(_productionDetails) }, CostStage = _stage, Status = CostStageRevisionStatus.Approved, Approvals = new List <Approval>() }; _cost = new Cost { Id = costId, CostType = costType, LatestCostStageRevisionId = _costStageRevisionId, LatestCostStageRevision = _revision, Project = new Project(), Parent = new AbstractType { Agency = new Agency() }, PaymentCurrencyId = paymentCurrencyId, ExchangeRate = _efContext.ExchangeRate.FirstOrDefault(er => er.FromCurrency == paymentCurrencyId)?.Rate }; _stage.Cost = _cost; _stage.Name = "Final Actual"; var previousRevision = new CostStageRevision { Id = previousCostStageRevisionId }; //add previous stage revision to the stage _stage.CostStageRevisions.Add(_previousRevision); _costApprovedEvent = new CostStageRevisionStatusChanged(_cost.Id, _previousRevision.Id, CostStageRevisionStatus.Approved, BuType.Pg); _costApprovedEvent = new CostStageRevisionStatusChanged(_cost.Id, _revision.Id, CostStageRevisionStatus.Approved, BuType.Pg); _paymentDetailsData = new PgPaymentDetails(); _costLineItems = new List <CostLineItemView>(); if (items != null) { _costLineItems.AddRange(items); } var _previousCostLineItems = new List <CostLineItemView>(); if (items != null) { _previousCostLineItems.AddRange(previousFAItems); } var paymentsList = new List <CostStageRevisionPaymentTotal>(); if (payments != null) { foreach (var payment in payments) { payment.CostStageRevision = _revision; } paymentsList.AddRange(payments); } var previousPaymentsList = new List <CostStageRevisionPaymentTotal>(); if (previousFAPayments != null) { foreach (var payment in previousFAPayments) { payment.CostStageRevision = _previousRevision; } previousPaymentsList.AddRange(previousFAPayments); } //set upp last stage revision data _costStageRevisionServiceMock.Setup(csr => csr.GetRevisionById(_costPreviousStageRevisionId)).ReturnsAsync(_previousRevision); _costStageRevisionServiceMock.Setup(csr => csr.GetPreviousRevision(costStageId)).ReturnsAsync(previousRevision); _costStageRevisionServiceMock.Setup(csr => csr.GetStageDetails <PgStageDetailsForm>(It.Is <CostStageRevision>(r => r.Id == _costPreviousStageRevisionId))) .Returns(_stageDetails); _costStageRevisionServiceMock.Setup(csr => csr.GetProductionDetails <PgProductionDetailsForm>(It.Is <CostStageRevision>(r => r.Id == _costPreviousStageRevisionId))) .Returns(_productionDetails); _costStageRevisionServiceMock.Setup(csr => csr.GetCostStageRevisionPaymentTotals(_costPreviousStageRevisionId, It.IsAny <bool>())).ReturnsAsync((List <CostStageRevisionPaymentTotal>)null); _costStageRevisionServiceMock.Setup(csr => csr.GetCostStageRevisionPaymentTotals(previousCostStageRevisionId, It.IsAny <bool>())).ReturnsAsync(previousPaymentsList); _costStageRevisionServiceMock.Setup(csr => csr.GetAllCostPaymentTotals(costId, costStageId)).ReturnsAsync(previousPaymentsList); _costStageRevisionServiceMock.Setup(csr => csr.GetAllCostPaymentTotalsFinalActual(costId, costStageId)).ReturnsAsync(previousPaymentsList); _customDataServiceMock.Setup(cd => cd.GetCustomData <PgPaymentDetails>(_costPreviousStageRevisionId, CustomObjectDataKeys.PgPaymentDetails)) .ReturnsAsync(_paymentDetailsData); _costStageRevisionServiceMock.Setup(csr => csr.GetCostLineItems(_costPreviousStageRevisionId)).ReturnsAsync(_previousCostLineItems); //set up latest stage revision data _costStageRevisionServiceMock.Setup(csr => csr.GetRevisionById(_costStageRevisionId)).ReturnsAsync(_revision); _costStageRevisionServiceMock.Setup(csr => csr.GetPreviousRevision(costStageId)).ReturnsAsync(previousRevision); _costStageRevisionServiceMock.Setup(csr => csr.GetStageDetails <PgStageDetailsForm>(It.Is <CostStageRevision>(r => r.Id == _costStageRevisionId))) .Returns(_stageDetails); _costStageRevisionServiceMock.Setup(csr => csr.GetProductionDetails <PgProductionDetailsForm>(It.Is <CostStageRevision>(r => r.Id == _costStageRevisionId))) .Returns(_productionDetails); _costStageRevisionServiceMock.Setup(csr => csr.GetCostStageRevisionPaymentTotals(_costStageRevisionId, It.IsAny <bool>())).ReturnsAsync((List <CostStageRevisionPaymentTotal>)null); _costStageRevisionServiceMock.Setup(csr => csr.GetCostStageRevisionPaymentTotals(previousCostStageRevisionId, It.IsAny <bool>())).ReturnsAsync(paymentsList); _costStageRevisionServiceMock.Setup(csr => csr.GetAllCostPaymentTotals(costId, costStageId)).ReturnsAsync(paymentsList); _customDataServiceMock.Setup(cd => cd.GetCustomData <PgPaymentDetails>(_costStageRevisionId, CustomObjectDataKeys.PgPaymentDetails)) .ReturnsAsync(_paymentDetailsData); _costStageRevisionServiceMock.Setup(csr => csr.GetCostLineItems(_costStageRevisionId)).ReturnsAsync(_costLineItems); _efContext.Cost.Add(_cost); _efContext.SaveChanges(); }
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); }