public void AddNewApprovals_Fails() { // Arrange var costId = Guid.NewGuid(); var updateApprovalsModel = CreateUpdateApprovalsModel(); EFContext.Role.Add(new Role { Id = Guid.NewGuid(), Name = "cost.approver" }); EFContext.CostUser.AddRange(updateApprovalsModel.SelectMany(am => am.ApprovalMembers).Select(m => new CostUser { Id = m.Id })); EFContext.Cost.Add(new Cost { Id = costId }); EFContext.SaveChanges(); ApprovalServiceMock.Setup(a => a.GetApprovalsByCostStageRevisionId(It.IsAny <Guid>(), false)).ReturnsAsync(new List <Approval>()); // Act, Assert Assert.ThrowsAsync <InvalidOperationException>(() => CostApprovalService.UpdateApprovals(costId, Guid.Empty, User, updateApprovalsModel)); }
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)); }
public async Task AddNewApprovalMembers() { // Arrange var costStageRevisionId = Guid.NewGuid(); var oldRevisionId = Guid.NewGuid(); var costId = Guid.NewGuid(); var revision = SetupCostStageRevision(costStageRevisionId, costId, true); var existingApprovals = CreateExistingApprovals(revision); var updateApprovalsModel = CreateUpdateApprovalsModel(); EFContext.CostUser.AddRange(updateApprovalsModel.SelectMany(am => am.ApprovalMembers).Select(m => new CostUser { Id = m.Id, UserBusinessRoles = new List <UserBusinessRole> { new UserBusinessRole { BusinessRole = new BusinessRole { Key = Constants.BusinessRole.Ipm } }, new UserBusinessRole { BusinessRole = new BusinessRole { Key = Constants.BusinessRole.BrandManager } } } })); EFContext.Approval.AddRange(existingApprovals); EFContext.Role.Add(new Role { Id = Guid.NewGuid(), Name = "cost.approver" }); var oldRevision = SetupCostStageRevision(oldRevisionId, costId, true); EFContext.CostStageRevision.AddRange(oldRevision); ApprovalServiceMock.Setup(a => a.GetApprovalsByCostStageRevisionId(It.IsAny <Guid>(), false) ) .ReturnsAsync(existingApprovals.Select(a => new Approval { Id = a.Id, Type = a.Type, Status = a.Status, CostStageRevisionId = a.CostStageRevisionId, CreatedById = a.CreatedById, ApprovalMembers = new List <ApprovalMember>(), Requisitioners = new List <Requisitioner>(), Created = a.Created, Modified = a.Modified, ValidBusinessRoles = a.ValidBusinessRoles }).ToList()); EFContext.Role.Add(new Role { Id = Guid.NewGuid(), Name = "cost.approver" }); EFContext.SaveChanges(); var ipmApprovalModel = new Builders.Response.ApprovalModel { Type = ApprovalType.IPM, ValidBusinessRoles = new [] { Constants.BusinessRole.Ipm } }; var brandApprovalModel = new Builders.Response.ApprovalModel { Type = ApprovalType.Brand, ValidBusinessRoles = new [] { Constants.BusinessRole.BrandManager } }; CostBuilderMock.Setup(b => b.GetApprovals(It.IsAny <CostType>(), It.IsAny <IStageDetails>(), It.IsAny <Guid>(), costStageRevisionId, costId)) .ReturnsAsync(new List <Builders.Response.ApprovalModel> { ipmApprovalModel, brandApprovalModel }); // Act await CostApprovalService.UpdateApprovals(costId, costStageRevisionId, User, updateApprovalsModel); // Assert EFContext.Entry(revision).Collection(r => r.Approvals).Load(); var ipmApproval = await EFContext.Approval .Include(a => a.ApprovalMembers) .FirstAsync(a => a.CostStageRevisionId == costStageRevisionId && a.Type == ApprovalType.IPM); var brandApproval = await EFContext.Approval .Include(a => a.ApprovalMembers) .FirstAsync(a => a.CostStageRevisionId == costStageRevisionId && a.Type == ApprovalType.Brand); ipmApproval.ApprovalMembers.Count.Should().Be(1); brandApproval.ApprovalMembers.Count.Should().Be(1); }