public void Setup() { LoggerMock = new Mock <ILogger>(); ApprovalServiceMock = new Mock <IApprovalService>(); AmqSettingsMock = new Mock <IOptions <AmqSettings> >(); AmqSettingsMock.SetupGet(o => o.Value).Returns(new AmqSettings()); EFContext = EFContextFactory.CreateInMemoryEFContext(); _technicalFeeService = new Mock <ITechnicalFeeService>(); RevisionPermissionService = new Mock <ICostStageRevisionPermissionService>(); CostStageRevisionService = new Mock <ICostStageRevisionService>(); CostBuilderMock = new Mock <ICostBuilder>(); var costBuilders = new EditableList <Lazy <ICostBuilder, PluginMetadata> > { new Lazy <ICostBuilder, PluginMetadata>( () => CostBuilderMock.Object, new PluginMetadata { BuType = BuType.Pg }) }; var userServiceMock = new Mock <IUserService>(); var configuration = new MapperConfiguration(config => config.AddProfiles( typeof(AdminProfile), typeof(SupportingDocumentProfile) ) ); var mapper = new Mapper(configuration); ActivityLogServiceMock = new Mock <IActivityLogService>(); _eventServiceMock = new Mock <IEventService>(); CostApprovalService = new CostApprovalService(ApprovalServiceMock.Object, _technicalFeeService.Object, EFContext, costBuilders, userServiceMock.Object, ActivityLogServiceMock.Object, _eventServiceMock.Object, RevisionPermissionService.Object, CostStageRevisionService.Object ); User = new UserIdentity { Email = "UserName", AgencyId = Guid.NewGuid(), Id = Guid.NewGuid() }; Service = new CostStageRevisionService( LoggerMock.Object, mapper, EFContext, new[] { new Lazy <ICostBuilder, PluginMetadata>( () => CostBuilderMock.Object, new PluginMetadata { BuType = BuType.Pg }) } ); }
// TODO cover this logc by unit tests private void AddCoupaApprovalEmail(List <EmailNotificationMessage <CostNotificationObject> > notifications, Cost cost, CostUser costOwner, Guid costStageRevisionId, DateTime timestamp) { var previousCostStage = _costStageService.GetPreviousCostStage(cost.LatestCostStageRevision.CostStageId).Result; if (previousCostStage == null) { // No need to send COUPA apprvoal email because this is the first time cost gets submitted for Brand Approval return; } var latestRevisionOfPreviousStage = CostStageRevisionService.GetLatestRevision(previousCostStage.Id).Result; if (latestRevisionOfPreviousStage == null) { throw new Exception($"Couldn't find latest revision for stage {previousCostStage.Id}"); } var previousPaymentAmount = _pgPaymentService.GetPaymentAmount(latestRevisionOfPreviousStage.Id, false).Result; var currentPaymentAmount = _pgPaymentService.GetPaymentAmount(costStageRevisionId, false).Result; if (currentPaymentAmount.TotalCostAmount == previousPaymentAmount.TotalCostAmount) { return; } // Send COUPA approval email because total amount changed var paymentDetails = _customObjectDataService.GetCustomData <PgPaymentDetails>(costStageRevisionId, CustomObjectDataKeys.PgPaymentDetails).Result; if (!string.IsNullOrEmpty(paymentDetails?.PoNumber)) { var actionType = core.Constants.EmailNotificationActionType.Submitted; var parent = core.Constants.EmailNotificationParents.Coupa; var coupaNotification = new EmailNotificationMessage <CostNotificationObject>(actionType); MapEmailNotificationObject(coupaNotification.Object, cost, costOwner); PopulateOtherFields(coupaNotification, parent, timestamp, cost.Id, cost.LatestCostStageRevision.Id); AddSharedTo(coupaNotification); var notificationCost = coupaNotification.Object.Cost; notificationCost.PurchaseOrder = new PurchaseOrder(); Mapper.Map(currentPaymentAmount, notificationCost.PurchaseOrder); Mapper.Map(paymentDetails, notificationCost.PurchaseOrder); coupaNotification.Parameters.EmailService.AdditionalEmails.Add(AppSettings.CoupaApprovalEmail); notifications.Add(coupaNotification); } }