Ejemplo n.º 1
0
        public void CreateActivityRun()
        {
            var personType = CodeNameResolver.GetTypeByName("AA_Person").As <EntityType>();

            const string createdRecordArgKey = "Record";

            var createActivity = new CreateActivity();

            createActivity.Save();
            ToDelete.Add(createActivity.Id);

            var nextActivity = (CreateImplementation)createActivity.As <WfActivity>().CreateWindowsActivity();

            var inputs = new Dictionary <string, object>
            {
                {
                    "Object", personType
                }
            };

            IDictionary <string, object> result = RunActivity(nextActivity, inputs);

            Assert.AreEqual(2, result.Count, "There are two results, and exit point + a value");

            Assert.IsTrue(result.ContainsKey(createdRecordArgKey));

            var resourceId = (IEntity)result[createdRecordArgKey];

            ToDelete.Add(resourceId.Id);

            var person = Entity.Get(resourceId.Id);

            Assert.IsNotNull(person, "We have a person");
        }
Ejemplo n.º 2
0
        public void EnsureAScheduledRunOnceRuns()
        {
            var schedule = new ScheduleOneOff {
                ScheduleSpecificTime = DateTime.UtcNow.AddMilliseconds(5000)
            };

            schedule.Save();

            var tos = new WfTriggerOnSchedule
            {
                Name           = "EnsureAScheduledRunOnceRuns_Job " + DateTime.Now,
                TriggerEnabled = true,
                WorkflowToRun  = CreateLoggingWorkflow("EnsureAScheduledRunOnceRuns")
            };

            tos.ScheduleForTrigger.Add(schedule.As <Schedule>());
            tos.Save();

            ToDelete.Add(tos.Id);
            ToDelete.Add(tos.WorkflowToRun.Id);
            ToDelete.Add(tos.ScheduleForTrigger.First().Id);

            var workflow = WaitForWfRun(tos);

            Assert.AreEqual(1, workflow.RunningInstances.Count(), "Ensure the workflow actually ran once");
        }
Ejemplo n.º 3
0
        public void OnlyOneExpressionPerArgument( )
        {
            var wf = new Workflow
            {
                Name = "wf" + DateTime.Now
            };
            var logging = (new LogActivity
            {
                Name = "log" + DateTime.Now
            }).As <WfActivity>( );

            wf.FirstActivity = logging;
            wf.ContainedActivities.Add(logging);

            ActivityTestHelper.AddExpressionToActivityArgument(wf, logging, "Message", "'First expression'", false);
            ActivityTestHelper.AddExpressionToActivityArgument(wf, logging, "Message", "'Second expression'", false);

            wf.Save( );
            ToDelete.Add(wf.Id);

            var messages = wf.Validate();

            Assert.Greater(messages.Count(), 0, "There are error messages");
            Assert.IsTrue(messages.Any(m => m.Contains("An expression has more than one argument to populate.")));
        }
Ejemplo n.º 4
0
        public void MultipleTriggerProblem()
        {
            var wf = CreateLoggingWorkflow();

            wf.Save();
            ToDelete.Add(wf.Id);

            var myType = CreateType("triggerTooMany_type", Person.Person_Type);

            ToDelete.Add(myType.Id);

            var myTrigger = CreateTrigger("triggerTooMany_type", myType, wf);

            ToDelete.Add(myTrigger.Id);

            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                var newEntity = Entity.Create(myType);
                newEntity.Save();
                ToDelete.Add(newEntity.Id);
            }

            Assert.AreEqual(1, wf.RunningInstances.Count(), "Only one run should be triggered");
        }
Ejemplo n.º 5
0
        public static async Task <bool> CheckIfNeedToUpdate()
        {
            try
            {
                if (await FileSystemStorageItemBase.OpenAsync(ApplicationData.Current.TemporaryFolder.Path) is FileSystemStorageFolder TempFolder)
                {
                    IEnumerable <FileSystemStorageItemBase> AllPreviousPictureList = await TempFolder.GetChildItemsAsync(false, false, Filter : ItemFilters.File, AdvanceFilter : (Name) => Name.StartsWith("BingDailyPicture_Cache", StringComparison.OrdinalIgnoreCase));

                    if (AllPreviousPictureList.All((Item) => DateTime.TryParseExact(Regex.Match(Item.Name, @"(?<=\[)(.+)(?=\])").Value, "yyyy-MM-dd HH-mm-ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out DateTime LastUpdateDate) && LastUpdateDate < DateTime.Now.Date))
                    {
                        foreach (FileSystemStorageItemBase ToDelete in AllPreviousPictureList)
                        {
                            await ToDelete.DeleteAsync(true);
                        }

                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
Ejemplo n.º 6
0
        public void DeleteActivityRunInWf()
        {
            var wf = new Workflow
            {
                Name = "DeleteActivityRunInWf"
            };

            wf.AddDefaultExitPoint()
            .AddInput <ResourceArgument>("ResourceId")
            .AddDelete("Delete", "ResourceId");

            wf.InputArgumentForAction = wf.InputArguments.First();

            wf.Save();
            ToDelete.Add(wf.Id);

            var person = new Person();

            person.Save();

            var personId = person.Id;

            var args = new Dictionary <string, object>()
            {
                { "ResourceId", person }
            };

            var run = (RunWorkflow(wf, args));

            Assert.IsTrue(run.WorkflowRunStatus_Enum == WorkflowRunState_Enumeration.WorkflowRunCompleted, "Run Completed");

            Assert.IsNull(Entity.Get(personId), "Ensure person is deleted");
        }
Ejemplo n.º 7
0
        public void WorkflowVariablesAndArgumentsCannotOverlap( )
        {
            var wf = new Workflow
            {
                Name = "wf" + DateTime.Now
            };

            wf.InputArguments.Add((new IntegerArgument
            {
                Name = "Clashing"
            }).As <ActivityArgument>( ));
            wf.Variables.Add((new IntegerArgument
            {
                Name = "Clashing"
            }).As <ActivityArgument>( ));

            var logging = (new LogActivity
            {
                Name = "log" + DateTime.Now
            }).As <WfActivity>( );

            wf.ContainedActivities.Add(logging);
            wf.FirstActivity = logging;

            wf.Save( );
            ToDelete.Add(wf.Id);


            var messages = wf.Validate();

            Assert.Greater(messages.Count(), 0, "There are error messages");
            Assert.IsTrue(messages.Any(m => m.Contains("clashed")));
        }
Ejemplo n.º 8
0
        public void LogMessage(string message, IEntity referencedObject = null)
        {
            var logActivity = new LogActivity
            {
                Name = "Log",
            };

            logActivity.Save( );
            ToDelete.Add(logActivity.Id);

            var nextActivity = ( LogActivityImplementation )logActivity.As <WfActivity>( ).CreateWindowsActivity( );

            var inputs = new Dictionary <string, object>
            {
                {
                    "Message", message
                },
                {
                    "Object", referencedObject
                }
            };

            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                RunActivity(nextActivity, inputs);
            }
        }
Ejemplo n.º 9
0
        public void TestLoopOverNoResultsInExpression()
        {
            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                var wf = new Workflow();

                wf.AddDefaultExitPoint();

                var forEach1 = new ForEachResource
                {
                    Name = "foreach1" + DateTime.Now
                };
                var forEach1As = forEach1.As <WfActivity>();

                ActivityTestHelper.AddExpressionToActivityArgument(wf, forEach1As, "List", "all([Workflow Run State]) where Name='Wibble wobble bob'");  // there shouldn't be any

                wf.FirstActivity = forEach1As;
                wf.ContainedActivities.Add(forEach1As);

                var loopExitPoint = Entity.Get <ExitPoint>(ForeachImplementation.LoopExitPointAlias);

                ActivityTestHelper.AddTransition(wf, forEach1As, forEach1As, loopExitPoint);
                ActivityTestHelper.AddTermination(wf, forEach1As);

                wf.Save();
                ToDelete.Add(wf.Id);

                var run = (RunWorkflow(wf));

                IDictionary <string, object> outputs = run.GetOutput();
            }
        }
        public void SendMailWithConfigAction(Action <Workflow, WfActivity> configurationAction, IEmailSender emailSender)
        {
            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                var emailAction = new SendEmailActivity( );

                var emailActionAs = emailAction.Cast <WfActivity>( );

                var wf = new Workflow
                {
                    Name = "Wf"
                };
                wf.AddDefaultExitPoint( );
                wf.ContainedActivities.Add(emailActionAs);

                wf.FirstActivity = emailActionAs;
                configurationAction(wf, emailActionAs);
                ActivityTestHelper.AddTermination(wf, emailActionAs);
                wf.Save( );
                ToDelete.Add(wf.Id);

                using (var scope = Factory.Current.BeginLifetimeScope(builder =>
                {
                    builder.RegisterInstance <IEmailSender>(emailSender);
                }))
                    using (Factory.SetCurrentScope(scope))
                    {
                        var wfRun = TestBase.RunWorkflow(wf);
                        Assert.That(wfRun.WorkflowRunStatus_Enum, Is.EqualTo(WorkflowRunState_Enumeration.WorkflowRunCompleted));
                    }
            }
        }
Ejemplo n.º 11
0
        public void ResourceVarWithEntityExpressionTest( )
        {
            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                Workflow workflow = CreateLoggingWorkflow("The workflow is {{TestResourceArg}}");


                var resArg = new ResourceArgument
                {
                    Name = "TestResourceArg"
                };

                ActivityTestHelper.AddVariableToWorkflow(workflow, resArg.Cast <ActivityArgument>());

                workflow.AddEntityExpressionToVariable("TestResourceArg", workflow);

                workflow.Save();

                ToDelete.Add(workflow.Id);

                var run = (RunWorkflow(workflow));

                Assert.IsTrue(run.WorkflowRunStatus_Enum == WorkflowRunState_Enumeration.WorkflowRunCompleted, "Run Completed");
            }
        }
Ejemplo n.º 12
0
        public static async Task <bool> CheckIfNeedToUpdate()
        {
            try
            {
                QueryOptions Options = new QueryOptions
                {
                    ApplicationSearchFilter = "System.FileName:BingDailyPicture_Cache*",
                    FolderDepth             = FolderDepth.Shallow,
                    IndexerOption           = IndexerOption.UseIndexerWhenAvailable
                };
                StorageFileQueryResult QueryResult = ApplicationData.Current.TemporaryFolder.CreateFileQueryWithOptions(Options);

                IReadOnlyList <StorageFile> AllPreviousPictureList = await QueryResult.GetFilesAsync();

                if (AllPreviousPictureList.All((Item) => DateTime.TryParseExact(Regex.Match(Item.Name, @"(?<=\[)(.+)(?=\])").Value, "yyyy-MM-dd HH-mm-ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out DateTime LastUpdateDate) && LastUpdateDate < DateTime.Now.Date))
                {
                    foreach (StorageFile ToDelete in AllPreviousPictureList)
                    {
                        await ToDelete.DeleteAsync(StorageDeleteOption.PermanentDelete);
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        public void UpdateRel()
        {
            var employeeType = Entity.Get <EntityType>("test:employee");
            var managerType  = Entity.Get <EntityType>("test:manager");
            var reportsToRel = Entity.Get <Relationship>("test:reportsTo");

            var bob        = new Entity(employeeType);
            var bobManager = new Entity(employeeType);

            bob.Save();
            bobManager.Save();
            ToDelete.Add(bob.Id);
            ToDelete.Add(bobManager.Id);

            var updateActivity = new UpdateFieldActivity();

            updateActivity.InputArguments.Add(new ResourceArgument {
                Name = "1"
            }.Cast <ActivityArgument>());
            updateActivity.InputArguments.Add(new ResourceArgument {
                Name = "1_value_"
            }.Cast <ActivityArgument>());
            updateActivity.InputArguments.Add(new BoolArgument {
                Name = "1_reverse"
            }.Cast <ActivityArgument>());
            updateActivity.InputArguments.Add(new BoolArgument {
                Name = "1_replace"
            }.Cast <ActivityArgument>());

            updateActivity.Save();
            ToDelete.Add(updateActivity.Id);

            var updateActionAs = updateActivity.As <WfActivity>();

            ActivityImplementationBase nextActivity = updateActionAs.CreateWindowsActivity();

            var args = new Dictionary <string, object>
            {
                {
                    "Record", bob
                },
                {
                    "1_value_", bobManager
                },
                {
                    "1", reportsToRel
                },
                {
                    "1_reverse", false
                }
            };

            RunActivity(nextActivity, args);

            var bob2      = Entity.Get(bob);
            var reportsTo = bob2.GetRelationships(reportsToRel);

            Assert.AreEqual(1, reportsTo.Count(), "Relationship set");
            Assert.AreEqual(bobManager.Id, reportsTo.First().Entity.Id, "Manager is correct");
        }
Ejemplo n.º 14
0
        public async Task GetAnimeAsync(CommandContext ctx, [RemainingText] string name)
        {
            var animes = (await Kitsu.GetAnimeAsync(name)).Data.Take(10).ToList();
            var embed  = new DiscordEmbedBuilder()
                         .WithTitle("Select anime")
                         .WithFooter(ctx.Member.GetFullName(), ctx.Member.AvatarUrl);

            for (var i = 0; i < animes.Count; i++)
            {
                var a = animes[i];
                embed.AddField($"[{i + 1}] {a.Attributes.Titles.En}({a.Attributes.Titles.JaJp})",
                               $"{a.Attributes.AverageRating?.ToString() ?? "none"}");
            }
            var index = -1;

            ToDelete.Add(ctx.Message);
            ToDelete.Add(await ctx.RespondAsync(embed: embed));
            ToDelete.Add((await Interactivity.WaitForMessageAsync(
                              x => int.TryParse(x.Content, out index) &&
                              index > 0 &&
                              index <= 10 ||
                              index == -1,
                              TimeSpan.FromSeconds(30))).Message);
            if (index == -1)
            {
                return;
            }
            var anime = animes[index - 1];

            embed.WithTitle($"{anime.Attributes.Titles.En}({anime.Attributes.Titles.EnJp})");
            embed.ClearFields();
            embed.Description = anime.Attributes.Synopsis;
            await ctx.RespondAsync(embed : embed);
        }
Ejemplo n.º 15
0
        public void GenerateReportLink( )
        {
            var report = Entity.Get <Report>("test:personReport");

            var createLinkActivity = new CreateLinkActivity( );

            createLinkActivity.Save( );
            ToDelete.Add(createLinkActivity.Id);

            var nextActivity = ( CreateLinkImplementation )createLinkActivity.As <WfActivity>( ).CreateWindowsActivity( );

            var inputs = new Dictionary <string, object>
            {
                {
                    "Resource", report
                }
            };

            IDictionary <string, object> result = RunActivity(nextActivity, inputs);

            var url = ( string )result["URL"];

            Assert.IsTrue(url.StartsWith("https://"), "Starts with Https");
            Assert.IsTrue(url.Contains(report.Id.ToString(CultureInfo.InvariantCulture)), "Url contains the correct Id");
        }
Ejemplo n.º 16
0
        public void DeleteActivityRun( )
        {
            var person = new Person( );

            person.Save( );
            ToDelete.Add(person.Id);

            var deleteActivity = new DeleteActivity( );

            deleteActivity.Save( );
            ToDelete.Add(deleteActivity.Id);

            var nextActivity = ( DeleteImplementation )deleteActivity.As <WfActivity>( ).CreateWindowsActivity( );

            var inputs = new Dictionary <string, object>
            {
                {
                    "Record", person
                }
            };

            RunActivity(nextActivity, inputs);

            Assert.That(Entity.Exists(person.Id), Is.False);
        }
Ejemplo n.º 17
0
        public void ComplexNestedWorkflow_TestInner( )
        {
            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                var personType = GetEntityType("AA_Person");
                var ageField   = GetPersonField("Age");
                var bob        = Entity.Create(personType).As <Resource>();
                bob.Name = "Test bob";

                bob.SetField(ageField, 33);
                bob.Save();
                ToDelete.Add(bob.Id);

                Workflow innerWf = CreateInnerWf();

                innerWf.Save();
                ToDelete.Add(innerWf.Id);

                var inputs = new Dictionary <string, object>
                {
                    {
                        "Resource", bob
                    }
                };

                var run = (RunWorkflow(innerWf, inputs));

                Assert.AreEqual(WorkflowRunState_Enumeration.WorkflowRunCompleted, run.WorkflowRunStatus_Enum, "Finished without errors");

                Assert.AreEqual(33, run.GetOutput()["Age"], "Age has been retrieved");
            }
        }
Ejemplo n.º 18
0
        //[Ignore("This test is the same as the failing intg workflow tests '610' and '620' due to the enforcement of cardinality. The problem is that the assignment of a relationship is not clearing the old relationship if  the cardinality does not permit it.")]
        public void ReassignReportDuringManagerCreate()
        {
            var aaManager = CodeNameResolver.GetTypeByName("AA_Manager").As <EntityType>();
            var reportsTo = Entity.Get <Relationship>(new EntityRef("test:reportsTo"));

            var oldMgr = new Entity(aaManager);

            oldMgr.Save();
            ToDelete.Add(oldMgr.Id);

            var employee1 = CreateEmployee(oldMgr, reportsTo);
            var employee2 = CreateEmployee(oldMgr, reportsTo);

            var createActivity = new CreateActivity();

            createActivity.InputArguments.Add(new ResourceArgument {
                Name = "1"
            }.Cast <ActivityArgument>());
            createActivity.InputArguments.Add(new ResourceArgument {
                Name = "1_value_"
            }.Cast <ActivityArgument>());
            createActivity.InputArguments.Add(new BoolArgument {
                Name = "1_reverse"
            }.Cast <ActivityArgument>());
            createActivity.InputArguments.Add(new BoolArgument {
                Name = "1_replace"
            }.Cast <ActivityArgument>());

            createActivity.Save();
            ToDelete.Add(createActivity.Id);

            var nextActivity = (CreateImplementation)createActivity.As <WfActivity>().CreateWindowsActivity();


            var inputs = new Dictionary <string, object>
            {
                {
                    "Object", aaManager
                },
                {
                    "1_value_", new List <Entity>()
                    {
                        employee1, employee2
                    }
                },
                {
                    "1", reportsTo
                },
                {
                    "1_reverse", true
                },
                {
                    "1_replace", true
                }
            };


            RunActivity(nextActivity, inputs);
        }
        public void SetChoice( )
        {
            var trigger = new WfTriggerUserUpdatesResource( );

            trigger.Save( );

            ToDelete.Add(trigger.Id);


            var setAction = new SetChoiceActivity( );

            setAction.Save( );
            ToDelete.Add(setAction.Id);

            var setChoiceAs = setAction.As <WfActivity>( );

            ActivityImplementationBase nextActivity = setChoiceAs.CreateWindowsActivity( );

            var args = new Dictionary <string, object>
            {
                {
                    "Resource to Update", trigger
                },
                {
                    "Field to Update", new EntityRef("core:triggeringCondition").Entity
                },
                {
                    "New Value", new EntityRef("core:triggeredOnEnumCreate").Entity
                },
            };

            RunActivity(nextActivity, args);

            trigger = Entity.Get <WfTriggerUserUpdatesResource>(trigger.Id);

            Assert.IsNotNull(trigger.TriggeringCondition, "Triggering condition should be set");
            Assert.AreEqual("core:triggeredOnEnumCreate", trigger.TriggeringCondition.Alias);

            args = new Dictionary <string, object>
            {
                {
                    "Resource to Update", trigger
                },
                {
                    "Field to Update", new EntityRef("core:triggeringCondition").Entity
                },
                {
                    "New Value", new EntityRef("core:triggeredOnEnumUpdate").Entity
                },
                {
                    "Replace Existing Values", false
                }                 // should ignore this value
            };

            RunActivity(nextActivity, args);

            Assert.IsNotNull(trigger.TriggeringCondition, "Triggering condition should be set");
            Assert.AreEqual("core:triggeredOnEnumUpdate", trigger.TriggeringCondition.Alias);
        }
Ejemplo n.º 20
0
        public void ProxyCallingItself_bug_17649()
        {
            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                // Inner Workflow
                var wf = new Workflow
                {
                    Name = "ProxyCallingItself_bug_17649 " + DateTime.Now
                };

                var isInnerArg = new BoolArgument()
                {
                    Name = "Is Inner"
                }.As <ActivityArgument>();
                wf.InputArguments.Add(isInnerArg);

                wf.AddDefaultExitPoint();

                var decision = new DecisionActivity()
                {
                    Name = "Is Inner"
                };
                var decisionAs = decision.As <WfActivity>();
                ActivityTestHelper.AddExpressionToActivityArgument(wf, decisionAs, "DecisionArgument", "[Is Inner]", false);

                wf.FirstActivity = decisionAs;
                wf.ContainedActivities.Add(decisionAs);

                WorkflowProxy innerProxy   = ActivityTestHelper.CreateWorkflowProxy(wf);
                var           innerProxyAs = innerProxy.As <WfActivity>();

                wf.ContainedActivities.Add(innerProxyAs);

                ActivityTestHelper.AddMissingExpressionParametersToWorkflow(wf);

                ActivityTestHelper.AddExpressionToActivityArgument(wf, innerProxyAs, "Is Inner", "true", false);

                ActivityTestHelper.AddTransition(wf, decisionAs, innerProxyAs, "No");
                ActivityTestHelper.AddTermination(wf, innerProxyAs);
                ActivityTestHelper.AddTermination(wf, decisionAs, "Yes");

                wf.Save();
                ToDelete.Add(wf.Id);

                wf.Validate();


                var input = new Dictionary <string, object>()
                {
                    { "Is Inner", true }
                };
                var run = (RunWorkflow(wf, input));

                Assert.AreEqual(WorkflowRunState_Enumeration.WorkflowRunCompleted, run.WorkflowRunStatus_Enum, "Finished without errors");
            }
        }
Ejemplo n.º 21
0
        private void Pf_SelectClick(object sender, RoutedEventArgs e)
        {
            int id = PostItFields.Where(x => x.IsFocused).Count();

            IsSelected = id > 0;

            PostItFields.ForEach(x => x.textField.IsEnabled = id == 0);
            ToDelete?.Invoke(this, e);
        }
Ejemplo n.º 22
0
 public void TestInitialize( )
 {
     using (new AdministratorContext( ))
     {
         _alternateExitPoint = new ExitPoint( );
         _alternateExitPoint.Save( );
         ToDelete.Add(_alternateExitPoint.Id);
     }
 }
Ejemplo n.º 23
0
        Notification RunNotify(IEntity person, TwilioNotifier notifier, bool waitForReplies, IEntity linkTo = null, string replyWorkflowString = null, Workflow replyWorkflow = null)
        {
            var inputs = new Dictionary <string, object>
            {
                { "People", person.ToEnumerable() },
                { "LinkToRecord", linkTo },
            };

            var wf = new Workflow {
                Name = "RunNotify " + DateTime.UtcNow.ToString()
            };

            wf
            .AddDefaultExitPoint()
            .AddInput <ResourceListArgument>("People", Person.Person_Type)
            .AddInput <ResourceArgument>("LinkToRecord", UserResource.UserResource_Type)
            .AddOutput <ResourceArgument>("NotificationRecord", Notification.Notification_Type)
            .AddNotify(
                "Notify", "People", "'Test'",
                waitForReplies,
                linkToRecordExpression: "LinkToRecord",
                replyMap: replyWorkflowString == null ? null :
                new Dictionary <string, Workflow> {
                { replyWorkflowString, replyWorkflow }
            })
            .AddAssignToVar("Assign", "[Notify_Notification Record]", "NotificationRecord");

            wf.Save();
            ToDelete.Add(wf.Id);

            using (var scope = Factory.Current.BeginLifetimeScope(builder =>
            {
                builder.Register(c => new TenantSmsNotifier(notifier.Id)).As <INotifier>();
            }))
                using (Factory.SetCurrentScope(scope))
                {
                    WorkflowRun run = null;

                    using (new TestWfRunContext())
                    {
                        run = RunWorkflow(wf, inputs);
                        run.Save();
                    }

                    Thread.Sleep(1000);

                    Assert.That(run.WorkflowRunStatus_Enum, Is.EqualTo(WorkflowRunState_Enumeration.WorkflowRunCompleted));

                    var results = run.GetOutput();

                    Assert.That(results.Keys, Has.Member("NotificationRecord"));

                    var entity = (IEntity)results["NotificationRecord"];
                    return(entity.As <Notification>());
                }
        }
Ejemplo n.º 24
0
        // [Ignore("Failing on first run in test environment.")]
        public void TestWorkflowRunOnReverseRelationshipUpdate()
        {
            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                var ageField = GetPersonField("Age");
                var titleRel = GetTitleRel();

                var myType = CreateMyType("Type_TestWorkflowRunOnUpdate");

                Workflow wf = CreateTestWorkflow("TestWorkflowRunOnRelationshipUpdate " + DateTime.Now, "990");

                var updateTrigger = new WfTriggerUserUpdatesResource
                {
                    WorkflowToRun = wf,
                    // ReSharper disable SpecifyACultureInStringConversionExplicitly
                    Name = "Test" + DateTime.Now.ToString(),
                    // ReSharper restore SpecifyACultureInStringConversionExplicitly
                    TriggeringCondition_Enum = TriggeredOnEnum_Enumeration.TriggeredOnEnumUpdate,
                    TriggerEnabled           = true
                };

                var task = new DisplayFormUserTask();

                var relToUpdate = Entity.Get <Relationship>("core:recordToPresent");
                updateTrigger.UpdatedRelationshipsToTriggerOn.Add(relToUpdate);         // a reverse relationship
                updateTrigger.TriggeredOnType = myType;

                updateTrigger.Save();
                ToDelete.Add(updateTrigger.Id);
                ToDelete.Add(wf.Id);

                EntityRef employee = CreateResource(myType);

                var savedEmployee = Entity.Get(employee);
                var age           = savedEmployee.GetField <int?>(ageField);
                Assert.AreEqual(null, age, "Age has been not been set by workflow");

                var rels = savedEmployee.GetRelationships(relToUpdate);

                rels.Add(task);

                using (new WorkflowRunContext(true))
                    using (var ctx = DatabaseContext.GetContext(true, preventPostSaveActionsPropagating: true))
                    {
                        savedEmployee.Save();

                        ctx.CommitTransaction();
                    }

                savedEmployee = Entity.Get(employee);
                var age1 = savedEmployee.GetField <int?>(ageField);
                Assert.That(age1, Is.EqualTo(990), "The update has not occurred and has not triggered the workflow.");
            }
        }
Ejemplo n.º 25
0
        public void ComplexNestedWorkflow( )
        {
            var personType = GetEntityType("AA_Person");
            var ageField   = GetPersonField("Age");
            var bob        = Entity.Create(personType).As <Resource>();

            bob.Name = "Test bob";

            bob.SetField(ageField, 13);
            bob.Save();
            ToDelete.Add(bob.Id);

            Workflow innerWf = CreateInnerWf();

            innerWf.Save();
            ToDelete.Add(innerWf.Id);


            var wf = new Workflow
            {
                Name = "Outer workflow" + DateTime.Now
            };

            var wfAs = wf.Cast <WfActivity>();

            wf
            .AddDefaultExitPoint()
            .AddInput <ResourceArgument>("OuterResource", personType)
            .AddOutput <IntegerArgument>("OuterAge")
            .AddWorkflowProxy("Proxy", innerWf)
            .AddExpressionToArgument("Proxy", "Resource", "OuterResource")
            .AddAssignToVar("AssignToOutput", "[Proxy_Age]", "OuterAge");

            wf.Save();
            ToDelete.Add(wf.Id);

            var inputs = new Dictionary <string, object>
            {
                {
                    "OuterResource", bob
                }
            };

            WorkflowRun run;

            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                run = RunWorkflow(wf, inputs);
            }
            Assert.AreEqual(WorkflowRunState_Enumeration.WorkflowRunCompleted, run.WorkflowRunStatus_Enum, "Finished without errors");

            Assert.AreEqual(13, run.GetOutput()["OuterAge"], "Age has been retrieved");
        }
Ejemplo n.º 26
0
        //[Ignore("This test currently fails - waiting for task Id")]
        public void CloneWorkflow()
        {
            var wf = CreateDoubleLogWorkflow();

            var cloneActivity = new CloneActivity();

            cloneActivity.InputArguments.Add(new ResourceArgument {
                Name = "1"
            }.Cast <ActivityArgument>());
            cloneActivity.InputArguments.Add(new IntegerArgument {
                Name = "1_value"
            }.Cast <ActivityArgument>());

            cloneActivity.Save();
            ToDelete.Add(cloneActivity.Id);

            var nextActivity = (CloneImplementation)cloneActivity.As <WfActivity>().CreateWindowsActivity();

            var inputs = new Dictionary <string, object>
            {
                {
                    "Record", wf
                },
                {
                    "1_value", "CLONE-" + wf.Name
                },
                {
                    "1", (new EntityRef(Resource.Name_Field.Id)).Entity
                }
            };

            IDictionary <string, object> result = RunActivity(nextActivity, inputs);

            var clone = (IEntity)result["Record"];

            var wfId    = wf.Id;
            var cloneId = clone.Id;

            CacheManager.ClearCaches();

            wf = Entity.Get <Workflow>(wfId);
            var cloneWf = Entity.Get <Workflow>(cloneId);

            Assert.AreEqual(wf.Transitions.Count, cloneWf.Transitions.Count);
            Assert.AreEqual(wf.Terminations.Count, cloneWf.Terminations.Count);
            VerifyWorkflow(wf);
            VerifyWorkflow(cloneWf);

            var wfAllIds    = wf.ContainedActivities.Select(a => a.Id);
            var cloneAllIds = cloneWf.ContainedActivities.Select(a => a.Id);

            Assert.IsEmpty(wfAllIds.Intersect(cloneAllIds));

            Assert.AreNotEqual(wf.FirstActivity.Id, cloneWf.FirstActivity.Id);
        }
Ejemplo n.º 27
0
        protected Workflow CreateWorkflow(string name)
        {
            var myWorkflow = (new Workflow()
            {
                Name = "name"
            }).AddWfExitPoint("Exit", true).AddLog("Log", "Log");

            myWorkflow.Save();
            ToDelete.Add(myWorkflow.Id);
            return(myWorkflow);
        }
Ejemplo n.º 28
0
        //[Category( "ExtendedTests" )]
        // NOTE: Cannot be run in transaction
        public void Test()
        {
            var wf = Entity
                     .Create <Workflow>()
                     .AddDefaultExitPoint()
                     .AddVariable <StringArgument>("name", "[input].Name")
                     .AddInput <ResourceArgument>("input", Resource.Resource_Type)
                     .AddDisplayForm("Display Form", new string[] { "Exit1" }, null, null, "[input]")
                     .AddUpdateField("Update Field", Person.Name_Field.As <Resource>(), "[input]", "[input].Name + 'xxx'");

            wf.Name = "UNNUMBERED_resumeMissingInput " + DateTime.Now;

            wf.Save();
            ToDelete.Add(wf.Id);

            var newResource = Entity.Create <Resource>();

            newResource.Name = "newResource " + DateTime.Now;
            newResource.Save();
            ToDelete.Add(newResource.Id);

            var inputs = new Dictionary <string, object> {
                { "input", newResource }
            };

            var run = TestBase.RunWorkflow(wf, inputs, null, true);

            Assert.That(run.WorkflowRunStatus_Enum, Is.EqualTo(WorkflowRunState_Enumeration.WorkflowRunPaused));

            var userTasks = run.TaskWithinWorkflowRun;
            var userTask  = userTasks.First().AsWritable <DisplayFormUserTask>();

            // Update the workflow
            WorkflowUpdateHelper.Update(wf.Id, () =>
            {
                var writable  = wf.AsWritable <Workflow>();
                writable.Name = writable.Name + "_";
                writable.Save();
            });


            // Complete the task
            userTask.TaskStatus_Enum     = TaskStatusEnum_Enumeration.TaskStatusCompleted;
            userTask.UserTaskCompletedOn = DateTime.Now; // set a ficticious completed time
            userTask.UserResponse        = userTask.AvailableTransitions.First();
            userTask.TaskComment         = "Comment";
            userTask.Save();

            Assert.IsTrue(WaitForWorkflowToStop(run, 30 * 1000), "Workflow run should have completed.");

            run = Entity.Get <WorkflowRun>(run);

            Assert.That(run.WorkflowRunStatus_Enum, Is.EqualTo(WorkflowRunState_Enumeration.WorkflowRunCompleted), "The run completed");
        }
Ejemplo n.º 29
0
 public static void DeleteFinally()
 {
     if (ToDelete.Count > 0)
     {
         foreach (string version in ToDelete)
         {
             CompatibleVersions.Remove(version);
         }
         ToDelete.Clear();
     }
 }
        public void InOutWorkflow( )
        {
            var wf = new Workflow();

            wf
            .AddInput <ResourceListArgument>("in")
            .AddOutput <ResourceListArgument>("out")
            .AddDefaultExitPoint()
            .AddAssignToVar("Set output", "in", "out")
            .Save( );

            var bob = new Person()
            {
                Name = "bob"
            };
            var john = new Person()
            {
                Name = "john"
            };

            bob.Save();
            john.Save();
            ToDelete.Add(bob.Id);
            ToDelete.Add(john.Id);

            var wfInput = new Dictionary <string, object>
            {
                {
                    "in", new List <IEntity>
                    {
                        bob,
                        john
                    }
                }
            };

            var run = (RunWorkflow(wf, wfInput));

            IDictionary <string, object> outputs = run.GetOutput();

            Assert.AreEqual(1, outputs.Count, "There is one output argument");

            var result = (IEnumerable <IEntity>)outputs["out"];

            var sIn     = string.Join(",", ((IEnumerable <IEntity>)wfInput["in"]).Select(e => e.Id));
            var sResult = string.Join(",", result.Select(e => e.Id));


            Assert.AreEqual(sIn, sResult, "Output is the same as input.");

            Assert.AreEqual(2, result.Count(), "There are two results");
        }