コード例 #1
0
        public void Execute_CallUninstallCommand_UninstallsNuGetPackage()
        {
            // arrange
            TestHelper.DeleteDirectoryIfExists("NuGetUnInstallTest");

            var target = new NuGet();
            WorkflowInvokerTest invoker = TestHelper.CreateWorkflowInvoker(target);

            var parameters = new Dictionary <string, object>
            {
                { "Command", NuGetCommand.Install },
                { "SourceRepository", new DirectoryInfo("TestData").FullName },
                { "LocalPath", "NuGetUnInstallTest" },
                { "PackageId", "MyPackage" },
                { "PackageVersion", "1.0.0" },
            };

            invoker.TestActivity(parameters);

            // act
            parameters["Command"]        = NuGetCommand.Uninstall;
            parameters["PackageVersion"] = "1.0.0";

            invoker.TestActivity(parameters);

            // assert
            invoker.AssertOutArgument.AreEqual("PackageInstallationPath", @"NuGetUnInstallTest\MyPackage.1.0.0");
            Assert.That(Directory.Exists(@"NuGetUnInstallTest\MyPackage.1.0.0"), Is.False);
        }
コード例 #2
0
        public void SumAddsTwoNumbers()
        {
            // Arrange
            var activity = new Sum();

            var host = WorkflowInvokerTest.Create(activity);

            // InArguments is a dynamic object of type Microsoft.Activities.WorkflowArguments
            host.InArguments.Num1 = 1;
            host.InArguments.Num2 = 2;

            try
            {
                // Act
                host.TestActivity();

                // Assert
                // Note: The host automatically captures the out arguments
                host.AssertOutArgument.AreEqual("Result", 3);

                Assert.AreEqual(3, host.OutArguments.Result);
            }
            finally
            {
                // Note: The host automatically captures tracking
                host.Tracking.Trace();
            }
        }
コード例 #3
0
        public void Execute_CallNpmFileWithInstallCommand_ExecutesJavaScriptFile()
        {
            // arrange
            TestHelper.DeleteDirectoryIfExists("nodetest");
            TestHelper.CopyFile(@"TestData\package.json", @"nodetest\package.json");

            var target = new NodeJs();
            WorkflowInvokerTest invoker = TestHelper.CreateWorkflowInvoker(target);

            var nodeExe           = new FileInfo("Node.exe".FindExePath());
            var npmJavaScriptFile = Path.Combine(nodeExe.DirectoryName, @"node_modules\npm\bin\npm-cli.js");

            // act
            var parameters = new Dictionary <string, object>
            {
                { "WorkingDirectory", "nodetest" },
                { "JavaScriptFile", npmJavaScriptFile },
                { "ApplicationParameters", "install" },
            };

            invoker.TestActivity(parameters);

            // assert
            Assert.IsTrue(Directory.Exists(@"nodetest\node_modules"));
        }
コード例 #4
0
        public static WorkflowInvokerTest CreateWorkflowInvoker(Activity targetActivity)
        {
            var invoker = new WorkflowInvokerTest(targetActivity);

            invoker.Extensions.Add(CreateLoggingExtension());

            return(invoker);
        }
コード例 #5
0
        public void WhenFalseIsFalseDoesNotThrow()
        {
            const bool expected = false;
            var input = new Dictionary<string, object> { { "Value", expected } };
            var host = new WorkflowInvokerTest(new EchoArg<bool>());
            host.TestActivity(input);

            host.AssertOutArgument.IsFalse("Result");
        }
コード例 #6
0
        public void WhenEqualAreEqualShouldNotThrow()
        {
            var expected = this.TestContext.TestName;

            var input = new Dictionary<string, object> { { "Value", expected } };
            var host = new WorkflowInvokerTest(new EchoStringArg());
            host.TestActivity(input);
            host.AssertOutArgument.AreEqual("Result", expected);
        }
コード例 #7
0
        public void CodeActivity_ContinuesWhenReturnedDelegateFails()
        {
            FailsWhenReturningCodeActivity mock = new FailsWhenReturningCodeActivity()
            {
                ContinueOnError = true
            };
            WorkflowInvokerTest invoker = new WorkflowInvokerTest(mock);

            invoker.TestActivity();
        }
コード例 #8
0
        public void NativeActivity_FailsWhenReturnedDelegateFails()
        {
            FailsWhenReturningNativeActivity mock = new FailsWhenReturningNativeActivity()
            {
                ContinueOnError = false
            };
            WorkflowInvokerTest invoker = new WorkflowInvokerTest(mock);

            Assert.Throws <NotImplementedException>(() => { invoker.TestActivity(); });
        }
コード例 #9
0
        public void WhenEqualAreNotEqualThrows()
        {
            var expected = this.TestContext.TestName;

            var input = new Dictionary<string, object> { { "Value", expected } };
            var host = new WorkflowInvokerTest(new EchoStringArg());
            host.TestActivity(input);

            AssertHelper.Throws<WorkflowAssertFailedException>(
                () => host.AssertOutArgument.AreNotEqual("Result", expected));
        }
コード例 #10
0
        public void CountPropertyHasNumberOfRecords()
        {
            // Arrange
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            // Act
            host.TestActivity();

            // Assert
            Assert.AreEqual(TrackingRecordCount, host.Tracking.Records.Count);
        }
コード例 #11
0
        public void CodeActivity_ContinuesWhenInnerTaskFails()
        {
            int delay = 1000;

            FailsAfterDelayCodeActivity mock = new FailsAfterDelayCodeActivity()
            {
                Delay           = delay,
                ContinueOnError = true
            };
            WorkflowInvokerTest invoker = new WorkflowInvokerTest(mock);

            invoker.TestActivity(TimeSpan.FromMilliseconds(delay * 2));
        }
コード例 #12
0
        public void ClearWillClearRecords()
        {
            // Arrange
            var host = new WorkflowInvokerTest(CreateTestActivity());

            // Act
            host.TestActivity();

            host.Tracking.Records.Clear();

            // Assert
            Assert.AreEqual(0, host.Tracking.Records.Count);
        }
コード例 #13
0
        public void CodeActivity_FailsWhenInnerTaskFails()
        {
            int delay = 1000;

            FailsAfterDelayCodeActivity mock = new FailsAfterDelayCodeActivity()
            {
                Delay           = delay,
                ContinueOnError = false
            };
            WorkflowInvokerTest invoker = new WorkflowInvokerTest(mock);

            Assert.Throws <NotImplementedException>(() => { invoker.TestActivity(TimeSpan.FromMilliseconds(delay * 2)); });
        }
コード例 #14
0
        public void TestDisconect()
        {
            var dbConnection = new Mock <DatabaseConnection>();
            var executed     = false;

            dbConnection.Setup(con => con.Dispose()).Callback(() => executed = true);
            dynamic arguments = new ExpandoObject();

            arguments.DatabaseConnection = dbConnection.Object;
            var host = new WorkflowInvokerTest(new DatabaseDisconnect(), arguments);
            var ex   = Record.Exception(() => host.TestActivity());

            Assert.Null(ex);
            Assert.True(executed);
        }
コード例 #15
0
        public void TestConnect()
        {
            var factory = new Mock <IDBConnectionFactory>();

            factory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(() => new DatabaseConnection());
            var connectActivity = new DatabaseConnect(factory.Object)
            {
                ConnectionString = new InArgument <string>("alpha"),
                ProviderName     = new InArgument <string>("beta")
            };
            var host = new WorkflowInvokerTest(connectActivity);
            var ex   = Record.Exception(() => host.TestActivity());

            Assert.Null(ex);
        }
コード例 #16
0
        public void TestDatabaseTransactionWithEmptyBody(bool useTransaction)
        {
            var dbConnection = new Mock <DatabaseConnection>();
            var executed     = false;

            dbConnection.Setup(con => con.BeginTransaction()).Callback(() => executed = true);
            dynamic arguments = new ExpandoObject();

            arguments.ExistingDbConnection = dbConnection.Object;
            var dbTransactionActivity = new DatabaseTransaction {
                UseTransaction = useTransaction
            };
            var host = new WorkflowInvokerTest(dbTransactionActivity, arguments);
            var ex   = Record.Exception(() => host.TestActivity());

            Assert.Null(ex);
            Assert.True(executed == useTransaction);
        }
コード例 #17
0
        public void HashAlgorithmsMatch(HashAlgorithms enumValue)
        {
            string toHash = "`~1234567890-=qwertyuiop[]\\ASDFGHJKL:\"ZXCVBNM<>?ăîșțâ";

            HashText hash = new HashText
            {
                Algorithm = enumValue,
                Encoding  = new InArgument <Encoding>(ExpressionServices.Convert((env) => System.Text.Encoding.Unicode))
            };
            Dictionary <string, object> arguments = new Dictionary <string, object>();

            arguments.Add(nameof(HashText.Input), toHash);

            WorkflowInvokerTest invoker = new WorkflowInvokerTest(hash);
            string activityString       = (string)invoker.TestActivity(arguments)[nameof(hash.Result)];

            byte[] algorithmBytes = CryptographyHelper.HashData(enumValue, Encoding.Unicode.GetBytes(toHash));

            Assert.Equal(activityString, BitConverter.ToString(algorithmBytes).Replace("-", string.Empty));
        }
コード例 #18
0
        public void Execute_CallInstallCommand_ExecutesNpmInstall()
        {
            // arrange
            TestHelper.DeleteDirectoryIfExists("npmtest");
            TestHelper.CopyFile(@"TestData\package.json", @"npmtest\package.json");

            var target = new Npm();
            WorkflowInvokerTest invoker = TestHelper.CreateWorkflowInvoker(target);

            // act
            var parameters = new Dictionary <string, object>
            {
                { "WorkingDirectory", "npmtest" },
                { "Command", "install" },
            };

            invoker.TestActivity(parameters);

            // assert
            Assert.IsTrue(Directory.Exists(@"npmtest\node_modules"));
        }
コード例 #19
0
        public void KeyedHashAlgorithmsMatch(KeyedHashAlgorithms enumValue)
        {
            string toHash = "`~1234567890-=qwertyuiop[]\\ASDFGHJKL:\"ZXCVBNM<>?ăîșțâ";
            string key    = "{>@#F09\0";

            KeyedHashText keyedHash = new KeyedHashText
            {
                Algorithm = enumValue,
                Encoding  = new VisualBasicValue <Encoding>(typeof(Encoding).FullName + "." + nameof(Encoding.Unicode))
            };
            Dictionary <string, object> arguments = new Dictionary <string, object>();

            arguments.Add(nameof(KeyedHashText.Input), toHash);
            arguments.Add(nameof(KeyedHashText.Key), key);

            WorkflowInvokerTest invoker = new WorkflowInvokerTest(keyedHash);
            string activityString       = (string)invoker.TestActivity(arguments)[nameof(keyedHash.Result)];

            byte[] algorithmBytes = CryptographyHelper.HashDataWithKey(enumValue, Encoding.Unicode.GetBytes(toHash), Encoding.Unicode.GetBytes(key));

            Assert.Equal(activityString, BitConverter.ToString(algorithmBytes).Replace("-", string.Empty));
        }
コード例 #20
0
        public void SymmetricAlgorithmsEncryptionMatches(SymmetricAlgorithms enumValue)
        {
            string toProcess = "`~1234567890-=qwertyuiop[]\\ASDFGHJKL:\"ZXCVBNM<>?ăîșțâ";
            string key       = "{>@#F09\0";

            EncryptText symmetricAlgorithm = new EncryptText
            {
                Algorithm = enumValue,
                Encoding  = new VisualBasicValue <Encoding>(typeof(Encoding).FullName + "." + nameof(Encoding.Unicode))
            };
            Dictionary <string, object> arguments = new Dictionary <string, object>();

            arguments.Add(nameof(EncryptText.Input), toProcess);
            arguments.Add(nameof(EncryptText.Key), key);

            WorkflowInvokerTest invoker = new WorkflowInvokerTest(symmetricAlgorithm);
            string activityString       = (string)invoker.TestActivity(arguments)[nameof(symmetricAlgorithm.Result)];

            byte[] algorithmBytes = CryptographyHelper.DecryptData(enumValue, Convert.FromBase64String(activityString), Encoding.Unicode.GetBytes(key));

            Assert.Equal(toProcess, Encoding.Unicode.GetString(algorithmBytes));
        }
コード例 #21
0
        public void ExistsBeforeWillThrowWhenBeforeAndAfterTheSame()
        {
            // Arrange
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            // Act
            host.TestActivity();

            // Assert
            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBefore(
                    host.Tracking.Records, "WriteLine1", "WriteLine1", ActivityInstanceState.Closed));
        }
コード例 #22
0
        public void ExistsIdArgValueFindsAMatchingArgument()
        {
            // Arrange
            var host = new WorkflowInvokerTest(CreateTestActivity());

            // Act
            host.TestActivity();

            // Assert
            Assert.IsTrue(host.Tracking.Records.ExistsIdArgValue("2", ActivityInstanceState.Executing, "BoolArg", true));
            Assert.IsTrue(host.Tracking.Records.ExistsIdArgValue("2", ActivityInstanceState.Executing, "IntArg", 1));
        }
コード例 #23
0
        public void ExistsBeforeArgMatchWithBadAfterPatternWillThrow()
        {
            // Arrange
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            // Act
            host.TestActivity();

            // Assert

            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBeforeArgMatch(
                    host.Tracking.Records,
                    "WriteLine1",
                    ActivityInstanceState.Closed,
                    "Text",
                    "WriteLine\\d",
                    "WriteLine2",
                    ActivityInstanceState.Closed,
                    "Text",
                    "Bad Pattern"));

                            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBeforeArgMatch(
                    host.Tracking.Records,
                    "WriteLine1",
                    ActivityInstanceState.Closed,
                    "Text",
                    "WriteLine\\d",
                    "WriteLine2",
                    ActivityInstanceState.Closed,
                    "Text",
                    "Bad Pattern", "fail message"));

            // Overload with startIndex
            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBeforeArgMatch(
                    host.Tracking.Records,
                    "WriteLine1",
                    ActivityInstanceState.Closed,
                    "Text",
                    "WriteLine\\d",
                    "WriteLine2",
                    ActivityInstanceState.Closed,
                    "Text",
                    "Bad Pattern",
                    1, "fail message"));

            // Overload with startIndex
            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBeforeArgMatch(
                    host.Tracking.Records,
                    "WriteLine1",
                    ActivityInstanceState.Closed,
                    "Text",
                    "WriteLine\\d",
                    "WriteLine2",
                    ActivityInstanceState.Closed,
                    "Text",
                    "Bad Pattern",
                    1));
        }
コード例 #24
0
        public void ExistsArgMatchWithNoArgumentWillThrow()
        {
            // Arrange
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            // Act
            host.TestActivity();

            // Assert
            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsArgMatch(
                    host.Tracking.Records, "WriteLine1", ActivityInstanceState.Closed, "Does Not Exist", "pattern"));
        }
コード例 #25
0
        public void ExistsArgMatchWillNotThrow()
        {
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            host.TestActivity();

            AssertTracking.ExistsArgMatch(host.Tracking.Records, "WriteLine1", ActivityInstanceState.Closed, "Text", "WriteLine\\d");
            AssertTracking.ExistsArgMatch(host.Tracking.Records, "WriteLine1", ActivityInstanceState.Closed, "Text", "WriteLine\\d", "fail message");
            AssertTracking.ExistsArgMatch(host.Tracking.Records, "WriteLine1", ActivityInstanceState.Closed, "Text", "WriteLine\\d", 0);
            AssertTracking.ExistsArgMatch(host.Tracking.Records, "WriteLine1", ActivityInstanceState.Closed, "Text", "WriteLine\\d", 0, "fail message");
        }
コード例 #26
0
        public void ExistBeforeWillNotThrowWhenBefore()
        {
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            host.TestActivity();

            AssertTracking.ExistsBefore(host.Tracking.Records, "WriteLine1", "WriteLine2", ActivityInstanceState.Closed);
            AssertTracking.ExistsBefore(
                host.Tracking.Records, "WriteLine1", "WriteLine2", ActivityInstanceState.Closed, "fail message");
            AssertTracking.ExistsBefore(
                host.Tracking.Records, "WriteLine1", "WriteLine2", ActivityInstanceState.Closed, 0);
            AssertTracking.ExistsBefore(
                host.Tracking.Records, "WriteLine1", "WriteLine2", ActivityInstanceState.Closed, 0, "fail message");

            AssertTracking.ExistsBefore(
                host.Tracking.Records,
                "WriteLine1",
                ActivityInstanceState.Closed,
                "WriteLine2",
                ActivityInstanceState.Executing);

            AssertTracking.ExistsBefore(
                host.Tracking.Records,
                "WriteLine1",
                ActivityInstanceState.Closed,
                "WriteLine2",
                ActivityInstanceState.Executing,
                0);

            AssertTracking.ExistsBefore(
                host.Tracking.Records,
                "WriteLine1",
                ActivityInstanceState.Closed,
                "WriteLine2",
                ActivityInstanceState.Executing,
                "fail message");

            AssertTracking.ExistsBefore(
                host.Tracking.Records,
                "WriteLine1",
                ActivityInstanceState.Closed,
                "WriteLine2",
                ActivityInstanceState.Executing,
                0,
                "fail message");
        }
コード例 #27
0
        public void DoesNotExistWorkflowInstanceWillNotThrow()
        {
            // Arrange
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            // Act
            host.TestActivity();

            // Assert
            // Find the following
            // 0: WorkflowInstance "Sequence" is Started at 04:18:41.3324
            // 28: WorkflowInstance "Sequence" is Completed at 04:18:41.3394

            AssertTracking.Exists(host.Tracking.Records, WorkflowInstanceRecordState.Started);

            AssertHelper.Throws<WorkflowAssertFailedException>(
                () => AssertTracking.Exists(host.Tracking.Records, WorkflowInstanceRecordState.Started, 5));

            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.Exists(host.Tracking.Records, WorkflowInstanceRecordState.Started, 5, "fail message"));

            // Verify that the workflow did not go idle
            AssertTracking.DoesNotExist(host.Tracking.Records, WorkflowInstanceRecordState.Idle);

            // No started after 2
            AssertTracking.DoesNotExist(host.Tracking.Records, WorkflowInstanceRecordState.Started, 2);

            // No started after 2
            AssertTracking.DoesNotExist(host.Tracking.Records, WorkflowInstanceRecordState.Started, 2, "fail message");
        }
コード例 #28
0
        public void FindArgValueBadIndexShouldThrow()
        {
            // Arrange
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            // Act
            host.TestActivity();

            // Assert
            AssertHelper.Throws<ArgumentOutOfRangeException>(
                () =>
                host.Tracking.Records.FindArgValue(
                    "WriteLine3", ActivityInstanceState.Executing, "Text", "WriteLine3", -1));
        }
コード例 #29
0
        public void FindArgMatchWithStartIndexDoesNotFindEarlierRecord()
        {
            // Arrange
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            // Act
            host.TestActivity();

            // Assert
            // Find the following starting at Index 20
            // 11: Activity [8] "WriteLine3" is Closed at 02:45:04.9032
            // {
            //     Arguments
            //         Text: WriteLine3
            //         TextWriter:
            // }
            Assert.IsNull(
                host.Tracking.Records.FindArgMatch(
                    WriteLine3Id, ActivityInstanceState.Closed, "Text", "WriteLine\\d", 20));
        }
コード例 #30
0
        public void FindArgMatchWillThrowOnInvalidArgs()
        {
            // Arrange
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            // Act
            host.TestActivity();

            // Invalid Display Name
            AssertHelper.Throws<ArgumentNullException>(
                () =>
                host.Tracking.Records.FindArgMatch(
                    string.Empty, ActivityInstanceState.Executing, "Text", "WriteLine\\d"));
            AssertHelper.Throws<ArgumentNullException>(
                () =>
                host.Tracking.Records.FindArgMatch(
                    string.Empty, ActivityInstanceState.Executing, "Text", "WriteLine\\d", 0));

            // Invalid Argument Name
            AssertHelper.Throws<ArgumentNullException>(
                () =>
                host.Tracking.Records.FindArgMatch("WriteLine1", ActivityInstanceState.Executing, "", "WriteLine\\d"));
            AssertHelper.Throws<ArgumentNullException>(
                () =>
                host.Tracking.Records.FindArgMatch("WriteLine1", ActivityInstanceState.Executing, "", "WriteLine\\d", 0));

            // Invalid Pattern
            AssertHelper.Throws<ArgumentNullException>(
                () => host.Tracking.Records.FindArgMatch("WriteLine1", ActivityInstanceState.Executing, "Text", ""));
            AssertHelper.Throws<ArgumentNullException>(
                () => host.Tracking.Records.FindArgMatch("WriteLine1", ActivityInstanceState.Executing, "Text", "", 0));

            // Invalid Start Index
            AssertHelper.Throws<ArgumentOutOfRangeException>(
                () =>
                host.Tracking.Records.FindArgMatch(
                    "WriteLine1", ActivityInstanceState.Executing, "Text", "WriteLine\\d", -1));
        }
コード例 #31
0
        public void ExistsWorkflowInstanceFindsMatch()
        {
            // Arrange
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            // Act
            host.TestActivity();

            // Assert
            // Find the following
            // 0: WorkflowInstance "Sequence" is Started at 04:18:41.3324
            // 28: WorkflowInstance "Sequence" is Completed at 04:18:41.3394
            Assert.IsTrue(host.Tracking.Records.Exists(WorkflowInstanceRecordState.Started));

            host.Tracking.Assert.Exists(WorkflowInstanceRecordState.Started);

            // Should not find after index 0
            Assert.IsFalse(host.Tracking.Records.Exists(WorkflowInstanceRecordState.Started, 5));

            AssertHelper.Throws<WorkflowAssertFailedException>(
                () => host.Tracking.Assert.Exists(WorkflowInstanceRecordState.Started, 5));

            // No index
            Assert.IsTrue(host.Tracking.Records.Exists(WorkflowInstanceRecordState.Completed));

            // Again with index
            Assert.IsTrue(host.Tracking.Records.Exists(WorkflowInstanceRecordState.Completed, 20));

            // Verify that the workflow did not go idle
            Assert.IsFalse(host.Tracking.Records.Exists(WorkflowInstanceRecordState.Idle));
        }
コード例 #32
0
        public void GetEnumeratorWillCopyRecords()
        {
            // Arrange
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            // Act
            host.TestActivity();

            // Forces a call to GetEnumerator
            foreach (var rec in host.Tracking.Records)
            {
                Assert.IsNotNull(rec);
            }
        }
コード例 #33
0
        public void TrackingIndexerReturnsRecord()
        {
            // Arrange
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            // Act
            host.TestActivity();

            // Assert
            Assert.AreEqual("WriteLine1", ((ActivityStateRecord)host.Tracking.Records[4]).Activity.Name);
        }
コード例 #34
0
        public void ExistsBeforeWillThrowWhenNotBefore()
        {
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            host.TestActivity();
            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBefore(
                    host.Tracking.Records, "WriteLine2", "WriteLine1", ActivityInstanceState.Closed));

            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBefore(
                    host.Tracking.Records, "WriteLine2", "WriteLine1", ActivityInstanceState.Closed, "fail message"));

            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBefore(
                    host.Tracking.Records, "WriteLine2", "WriteLine1", ActivityInstanceState.Closed, 0));

            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBefore(
                    host.Tracking.Records, "WriteLine2", "WriteLine1", ActivityInstanceState.Closed, 0, "fail message"));

            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBefore(
                    host.Tracking.Records,
                    "WriteLine2",
                    ActivityInstanceState.Executing,
                    "WriteLine1",
                    ActivityInstanceState.Closed));

            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBefore(
                    host.Tracking.Records,
                    "WriteLine2",
                    ActivityInstanceState.Executing,
                    "WriteLine1",
                    ActivityInstanceState.Closed,
                    "fail message"));

            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBefore(
                    host.Tracking.Records,
                    "WriteLine2",
                    ActivityInstanceState.Executing,
                    "WriteLine1",
                    ActivityInstanceState.Closed,
                    0));

            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBefore(
                    host.Tracking.Records,
                    "WriteLine2",
                    ActivityInstanceState.Executing,
                    "WriteLine1",
                    ActivityInstanceState.Closed,
                    0,
                    "fail message"));
        }
コード例 #35
0
        public void ExistsIdWillNotThrow()
        {
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            host.TestActivity();

            AssertTracking.ExistsId(host.Tracking.Records, "12", ActivityInstanceState.Closed);
            AssertTracking.ExistsId(host.Tracking.Records, "12", ActivityInstanceState.Closed, "fail message");
        }
コード例 #36
0
        public void FindIndexReturnsNotFoundWhenNotExists()
        {
            // Arrange
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            // Act
            host.TestActivity();

            // Assert
            Assert.AreEqual(-1, host.Tracking.Records.FindIndex("Bad Name", ActivityInstanceState.Closed));
            Assert.AreEqual(-1, host.Tracking.Records.FindIndex("Bad Name", ActivityInstanceState.Closed, 0));
        }
コード例 #37
0
        public void ExistsWorkflowInstanceWillNotThrow()
        {
            // Arrange
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            // Act
            host.TestActivity();

            // Assert
            // Find the following
            // 0: WorkflowInstance "Sequence" is Started at 04:18:41.3324
            // 28: WorkflowInstance "Sequence" is Completed at 04:18:41.3394

            AssertTracking.Exists(host.Tracking.Records, WorkflowInstanceRecordState.Started);

            AssertHelper.Throws<WorkflowAssertFailedException>(
                () => AssertTracking.Exists(host.Tracking.Records, WorkflowInstanceRecordState.Started, 5));

            // No index
            AssertTracking.Exists(host.Tracking.Records, WorkflowInstanceRecordState.Completed);

            // Again with index
            AssertTracking.Exists(host.Tracking.Records, WorkflowInstanceRecordState.Completed, 20);

            // No index, fail message
            AssertTracking.Exists(host.Tracking.Records, WorkflowInstanceRecordState.Completed, "fail message");

            // Again with index and fail message
            AssertTracking.Exists(host.Tracking.Records, WorkflowInstanceRecordState.Completed, 20, "fail message");
        }
コード例 #38
0
        public void FindIndexReturnsIndexWhenExists()
        {
            // Arrange
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            // Act
            host.TestActivity();

            // Assert
            Assert.AreEqual(5, host.Tracking.Records.FindIndex("WriteLine1", ActivityInstanceState.Closed));
            Assert.AreEqual(5, host.Tracking.Records.FindIndex("WriteLine1", ActivityInstanceState.Closed, 0));
        }
コード例 #39
0
        public void ExistBeforeWillThrowWhenBeforeDoesNotExist()
        {
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            host.TestActivity();
            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBefore(
                    host.Tracking.Records, "Bad Record", "WriteLine2", ActivityInstanceState.Closed));

            // Overload with startIndex
            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBefore(
                    host.Tracking.Records, "Bad Record", "WriteLine2", ActivityInstanceState.Closed, 1));

            // Overload with state
            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBefore(
                    host.Tracking.Records,
                    "Bad Record",
                    ActivityInstanceState.Closed,
                    "WriteLine2",
                    ActivityInstanceState.Closed));

            // Overload with state and startIndex
            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBefore(
                    host.Tracking.Records,
                    "Bad Record",
                    ActivityInstanceState.Closed,
                    "WriteLine2",
                    ActivityInstanceState.Closed,
                    1));

            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBefore(
                    host.Tracking.Records, "Bad Record", "WriteLine2", ActivityInstanceState.Closed, "fail message"));

            // Overload with startIndex
            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBefore(
                    host.Tracking.Records, "Bad Record", "WriteLine2", ActivityInstanceState.Closed, 1, "fail message"));

            // Overload with state
            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBefore(
                    host.Tracking.Records,
                    "Bad Record",
                    ActivityInstanceState.Closed,
                    "WriteLine2",
                    ActivityInstanceState.Closed, "fail message"));

            // Overload with state and startIndex
            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBefore(
                    host.Tracking.Records,
                    "Bad Record",
                    ActivityInstanceState.Closed,
                    "WriteLine2",
                    ActivityInstanceState.Closed,
                    1, "fail message"));
        }
コード例 #40
0
        public void FindIndexPredicateReturnsIndexWhenExists()
        {
            // Arrange
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            // Act
            host.TestActivity();

            // Assert
            Assert.AreEqual(28, host.Tracking.Records.FindIndex<WorkflowInstanceRecord>(rec => rec.RecordNumber > 0));
            Assert.AreEqual(28, host.Tracking.Records.FindIndex<WorkflowInstanceRecord>(rec => rec.RecordNumber > 0, 1));
        }
コード例 #41
0
        public void ExistsArgMatchWithNoArgumentMatchWillThrow()
        {
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            host.TestActivity();

            AssertHelper.Throws<WorkflowAssertFailedException>( () => AssertTracking.ExistsArgMatch(host.Tracking.Records, "WriteLine1", ActivityInstanceState.Closed, "Text", "Bad Argument"));
            AssertHelper.Throws<WorkflowAssertFailedException>(() => AssertTracking.ExistsArgMatch(host.Tracking.Records, "WriteLine1", ActivityInstanceState.Closed, "Text", "Bad Argument", "fail message"));
            AssertHelper.Throws<WorkflowAssertFailedException>(() => AssertTracking.ExistsArgMatch(host.Tracking.Records, "WriteLine1", ActivityInstanceState.Closed, "Text", "Bad Argument", 0));
            AssertHelper.Throws<WorkflowAssertFailedException>(() => AssertTracking.ExistsArgMatch(host.Tracking.Records, "WriteLine1", ActivityInstanceState.Closed, "Text", "Bad Argument", 0, "fail message"));
        }
コード例 #42
0
        public void SCNamedPipeTrigger()
        {
            var aContextServer = this.SetUpContextServer();
            var aContextClient = this.SetUpContextClient();

            const int runs = 1;

            Variable <int> runCount = new Variable <int>
            {
                Name    = nameof(runCount),
                Default = runs,
            };
            var sequence = new Sequence()
            {
                Variables  = { runCount },
                Activities =
                {
                    new NamedPipeTriggerV2()
                    {
                        ContextName = Test_ContextName,
                        Debug       = true,
                        Body        = new ActivityAction <ContextContent>
                        {
                            Argument = new DelegateInArgument <ContextContent>(typeof(ContextContent).Name),
                            Handler  = new Sequence {
                                Activities =
                                {
                                    new Assign <int>()
                                    {
                                        To    = runCount,
                                        Value = new InArgument <int>((ctx) => runCount.Get(ctx) - 1),
                                    },
                                    new WriteLine()
                                    {
                                        Text = new InArgument <string>((ctx) => $"Should be logged.")
                                    }
                                }
                            }
                        },
                        ContinueMonitoring = new VisualBasicValue <bool>($"{nameof(runCount)} > 0"),
                    }
                }
            };

            var host = new WorkflowInvokerTest(sequence);
            var task = Task.Run(() => { host.TestActivity(TimeSpan.FromSeconds(10)); });

            // Trigger initialization takes time.
            Thread.Sleep(2000);

            var setContextActivity = new SetVariableActivity
            {
                VariableName  = Test_SetVariableName,
                VariableValue = Test_SetVariableValue,
                ContextClient = new InArgument <ContextClient>((ctx) => aContextClient)
            };

            WorkflowInvoker.Invoke(setContextActivity);

            aContextClient.MyDispose();

            Thread.Sleep(100);

            task.Wait(1000);
            Assert.IsTrue(TaskStatus.RanToCompletion == task.Status);
            Assert.IsTrue(runs == host.TextLines.Where(l => l == "Should be logged.").Count());

            aContextServer.MyDispose();
        }
コード例 #43
0
        public void ExistsBeforeArgMatchWhenBeforeWillNotThrow()
        {
            // Arrange
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            // Act
            host.TestActivity();

            // Assert

            AssertTracking.ExistsBeforeArgMatch(
                host.Tracking.Records,
                "WriteLine1",
                ActivityInstanceState.Closed,
                "Text",
                "WriteLine\\d",
                "WriteLine2",
                ActivityInstanceState.Closed,
                "Text",
                "WriteLine\\d");

            AssertTracking.ExistsBeforeArgMatch(
                host.Tracking.Records,
                "WriteLine1",
                ActivityInstanceState.Closed,
                "Text",
                "WriteLine\\d",
                "WriteLine2",
                ActivityInstanceState.Closed,
                "Text",
                "WriteLine\\d", "fail message");

            // Overload with startIndex
            AssertTracking.ExistsBeforeArgMatch(
                host.Tracking.Records,
                "WriteLine1",
                ActivityInstanceState.Closed,
                "Text",
                "WriteLine\\d",
                "WriteLine2",
                ActivityInstanceState.Closed,
                "Text",
                "WriteLine\\d",
                1);

            // Overload with startIndex
            AssertTracking.ExistsBeforeArgMatch(
                host.Tracking.Records,
                "WriteLine1",
                ActivityInstanceState.Closed,
                "Text",
                "WriteLine\\d",
                "WriteLine2",
                ActivityInstanceState.Closed,
                "Text",
                "WriteLine\\d",
                1, "fail message");
        }
コード例 #44
0
        public void ExistsBeforeIdWillThrowWhenBeforeIdDoesNotExist()
        {
            // Arrange
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            // Act
            host.TestActivity();

            // Assert
            AssertHelper.Throws<WorkflowAssertFailedException>(
                () => AssertTracking.ExistsBeforeId(host.Tracking.Records, "-1", "1", ActivityInstanceState.Closed));

            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBeforeId(
                    host.Tracking.Records, "-1", "1", ActivityInstanceState.Closed, "fail message"));

            AssertHelper.Throws<WorkflowAssertFailedException>(
                () => AssertTracking.ExistsBeforeId(host.Tracking.Records, "-1", "1", ActivityInstanceState.Closed, 0));

            AssertHelper.Throws<WorkflowAssertFailedException>(
                () =>
                AssertTracking.ExistsBeforeId(
                    host.Tracking.Records, "-1", "1", ActivityInstanceState.Closed, 0, "fail message"));
        }
コード例 #45
0
        public void FindArgMatchFindsAMatchingArgument()
        {
            // Arrange
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            // Act
            host.TestActivity();

            // Assert
            // Find the following
            // 4: Activity [19] "WriteLine1" is Executing at 02:42:24.1300
            // {
            //     Arguments
            //         Text: WriteLine1
            //         TextWriter:
            // }
            var found = host.Tracking.Records.FindArgMatch(
                "WriteLine1", ActivityInstanceState.Executing, "Text", "WriteLine\\d");
            Assert.IsNotNull(found);
            Assert.AreEqual("WriteLine1", found.Activity.Name);
            Assert.AreEqual("WriteLine1", found.Activity.Name);
            Assert.AreEqual("WriteLine1", found.GetArgument<string>("Text"));

            found = host.Tracking.Records.FindArgMatch(
                "WriteLine1", ActivityInstanceState.Executing, "Text", "WriteLine\\d", 0);
            Assert.IsNotNull(found);
            Assert.AreEqual("WriteLine1", found.Activity.Name);
            Assert.AreEqual("WriteLine1", found.Activity.Name);
            Assert.AreEqual("WriteLine1", found.GetArgument<string>("Text"));
        }
コード例 #46
0
        public void ExistsIdArgMatchExistssAMatchingArgument()
        {
            // Arrange
            var activity = CreateTestActivity();
            var host = new WorkflowInvokerTest(activity);

            // Act
            host.TestActivity();

            // Assert
            // 4: Activity [19] "WriteLine1" is Executing at 02:42:24.1300
            // {
            //     Arguments
            //         Text: WriteLine1
            //         TextWriter:
            // }
            Assert.IsTrue(
                host.Tracking.Records.ExistsIdArgMatch(
                    WriteLine1Id, ActivityInstanceState.Executing, "Text", "WriteLine\\d"));
            Assert.IsTrue(
                host.Tracking.Records.ExistsIdArgMatch(
                    WriteLine1Id, ActivityInstanceState.Executing, "Text", "WriteLine\\d", 0));
        }