protected override void Execute(CodeActivityContext executionContext) { // TODO not very happy about these being outside try catch but need to think of way // of retrying a workflow even when we don't have a context and org service! var workflowContext = GetWorkflowContext(executionContext); var organisationService = GetOrganizationService(workflowContext.UserId, executionContext); var tracingService = GetTraceService(executionContext); var trace = new DynamicsLoggingService(tracingService, organisationService.GetUniqueOrganisationName(), workflowContext.CorrelationId); var config = organisationService.GetFExConfiguration(workflowContext.PrimaryEntityId, ConfigAttribute.SchedulingAttributes, trace); try { var repo = new DynamicsRepository(organisationService, trace); var nextRunDate = new CalculateNextRunDateJob(repo, config, trace, workflowContext.Depth, workflowContext.CorrelationId).Execute(); CurrentRevision.Set(executionContext, config.Revision); NextRunDate.Set(executionContext, nextRunDate.NextDate.UtcDateTime); } catch (Exception exp) { var msg = "Error has Occured Running CalculateNextRunDate Activity. Seting Last Run Status to Error and logging."; HandleException(exp, msg, config, organisationService, trace); } }
public void CanCalculateNextRunDate() { var trace = new Mock <ILoggingService>().Object; var service = new OrganisationServiceFactory().Create(); var config = service.GetFExConfiguration(new Guid("dcdda8b0-a34b-e711-811a-e0071b65dea1"), ConfigAttribute.SchedulingAttributes, trace); var repo = new AssertableDynamicsRepo(service); var job = new CalculateNextRunDateJob(repo, config, trace, 1, Guid.NewGuid()); job.Execute(); Assert.AreEqual(repo.SaveNextRunDateCallCount, 1); }