Esempio n. 1
0
        public void DelayUntilTimeNowPlus1Day1Sec()
        {
            DateTime until;

            DateTime.TryParse(DateTime.Now.ToShortTimeString(), out until);

            var days = new List<DayOfWeek>
                {
                   DateTime.Now.AddDays(1).DayOfWeek, DateTime.Now.DayOfWeek, DateTime.Now.AddDays(-1).DayOfWeek
                };

            var activity = new DelayUntilTime { OccurenceDays = days };
            dynamic input = new WorkflowArguments();
            input.Time = DateTime.Now.AddSeconds(1).TimeOfDay;

            var host = new WorkflowInvokerTest(activity);

            try
            {
                host.TestActivity(input, Constants.Timeout);

                host.Tracking.Assert.Exists(
                    "DelayUntilTime", ActivityInstanceState.Closed, "DelayUntilTime activity failed to close");
            }
            finally
            {
                host.Tracking.Trace();
            }
        }
 /// <summary>
 /// Given 
 ///   * The following components are deployed
 ///   * Workflow (compiled) V1
 ///   * ActivityLibrary.dll V1
 ///   When 
 ///   * Workflow (compiled) is constructed using reference to Activity V1
 ///   Then
 ///   * Workflow should load and return version 1.0.0.0
 /// </summary>
 public void WorkflowV1RefActivityV1DeployedActivityV1ShouldLoad()
 {
     var activity = new Workflow(XamlAssemblyResolutionOption.FullName, GetListWithActivityLibraryVersion(1));
     var host = new WorkflowInvokerTest(activity);
     host.TestActivity(Constants.Timeout);
     host.AssertOutArgument.AreEqual("AssemblyVersion", new Version(1, 0, 0, 0));
 }
        public void WhatHappensWhenAddToCollectionAddsADuplicate()
        {
            var activity = new AddDuplicateCustomerToCollectionActivity();
            var host = new WorkflowInvokerTest(activity);

            try
            {
                var output = host.TestActivity();

                host.AssertOutArgument.IsNotNull("Result");

                var collection = output["Result"] as List<Customer>;

                Assert.IsNotNull(collection);
                Assert.AreEqual(2, collection.Count);

                this.TestContext.WriteLine("Customer list count {0}", collection.Count);
                foreach (var customer in collection)
                {
                    this.TestContext.WriteLine("Customer {0}", customer.Name);
                }
            }
            finally
            {
                host.Tracking.Trace();
            }
        }
 /// <summary>
 /// Given loose XAML and a reference to ActivityLibrary (V2) ActivityLoad should load V2
 /// </summary>
 public void WhenLooseXamlRefV2ShouldLoadV2WhenFound()
 {
     var host =
         new WorkflowInvokerTest(
             StrictXamlHelper.ActivityLoad(GetWorkflowXaml(), GetListWithActivityLibraryVersion(2)));
     host.TestActivity(Constants.Timeout);
     host.AssertOutArgument.AreEqual("AssemblyVersion", new Version(2, 0, 0, 0));
 }
        public void WhenOnlyRequiredArgIsProvidedOptionalStringArgShouldUseDefault()
        {
            var host = new WorkflowInvokerTest(new ActivityWithOptionalStringArg { RequiredArg = "Required Value" });

            host.TestActivity(Constants.Timeout);
            host.AssertOutArgument.AreEqual(
                "Result", string.Format("Required Value: {0}", ActivityWithOptionalStringArg.DefaultOptionalValue));
        }
        public void WhenOptionalAndRequiredArgIsProvidedOptionalArgShouldUseOptionalValueInputs()
        {
            const int Expected = 2;
            var host = new WorkflowInvokerTest(new ActivityWithOptionalArgs { UseContext = true });

            host.TestActivity(GetInputs("Required Value", Expected));
            host.AssertOutArgument.AreEqual("Result", string.Format("Required Value: {0}", Expected));
            host.Tracking.Trace();
        }
Esempio n. 7
0
        public void ShouldAddBadSumWrongTypeAssertOutArgument()
        {
            var sut = new WorkflowInvokerTest(new BadSumWrongType { x = 1, y = 2 });
            sut.TestActivity();

            AssertHelper.Throws<WorkflowAssertFailedException>(
                () => sut.AssertOutArgument.AreEqual("sum", 3),
                "AssertOutArgument.AreEqual failed. Wrong type for OutArgument <sum>. Expected Type: <System.Int32>. Actual Type: <System.String>.");
        }
Esempio n. 8
0
        public void ShouldAddBadSumArgNameAssertOutArgument()
        {
            var sut = new WorkflowInvokerTest(new BadSumArgName { x = 1, y = 2 });
            sut.TestActivity();

            // How to handle an expected exception
            AssertHelper.Throws<WorkflowAssertFailedException>(
                () => sut.AssertOutArgument.AreEqual("sum", 3),
                "AssertOutArgument.AreEqual failed. Output does not contain an argument named <sum>.");
        }
        public void WhenOptionalAndRequiredArgIsProvidedOptionalArgShouldUseOptionalValue0()
        {
            const int Expected = 0;
            var host =
                new WorkflowInvokerTest(
                    new ActivityWithOptionalArgs { RequiredArg = "Required Value", OptionalArg = Expected });

            host.TestActivity(Constants.Timeout);
            host.AssertOutArgument.AreEqual("Result", string.Format("Required Value: {0}", Expected));
            host.Tracking.Trace();
        }
 public void VerifyCollectionActivity()
 {
     var activity = new CollectionActivities();
     var host = new WorkflowInvokerTest(activity);
     try
     {
         host.TestActivity();
     }
     finally
     {
         host.Tracking.Trace();
     }
 }
 public void ShouldNotFind2InList()
 {
     var activity = new CheckNumberExistsInCollection { CheckNumber = 2 };
     var host = new WorkflowInvokerTest(activity);
     try
     {
         host.TestActivity();
         host.AssertOutArgument.IsFalse("NumberExists");
     }
     finally
     {
         host.Tracking.Trace();
     }
 }
 public void ShouldHandleInitializationException()
 {
     var activity = new UninitializedCollection();
     var host = new WorkflowInvokerTest(activity);
     try
     {
         host.TestActivity();
         host.AssertOutArgument.IsTrue("CaughtException");
     }
     finally
     {
         host.Tracking.Trace();
     }
 }
        public void AddCustomerIfNotInList()
        {
            var collection = new Collection<Customer>();
            var customer = new Customer();
            var activity = new EnsureCustomerIsInList();
            var host = new WorkflowInvokerTest(activity);

            var inputs = new Dictionary<string, object> { { "CustomerCollection", collection }, { "Customer", customer } };

            try
            {
                host.TestActivity(inputs);
                Assert.IsTrue(collection.Contains(customer));
            }
            finally
            {
                host.Tracking.Trace();
            }
        }
        public void ShouldAddACustomerToTheCollection()
        {
            var activity = new AddCustomerToCollectionActivity();
            var host = new WorkflowInvokerTest(activity);

            try
            {
                var output = host.TestActivity();

                host.AssertOutArgument.IsNotNull("Result");

                var collection = output["Result"] as List<Customer>;
                Assert.IsNotNull(collection);
                Assert.AreEqual(1, collection.Count);
            }
            finally
            {
                host.Tracking.Trace();
            }
        }
        public void GetRecordNumberIncludedWhenOptionRecordNumber()
        {
            // Arrange
            var activity = new Sequence();
            var listTrackingParticipant = new ListTrackingParticipant();
            var host = new WorkflowInvokerTest(activity);
            host.Extensions.Add(listTrackingParticipant);
            host.TestActivity();
            var record = listTrackingParticipant.Records.First();

            try
            {
                // Act
                var actual = record.ToFormattedString(TrackingOption.RecordNumber);

                // Assert
                Assert.IsTrue(actual.StartsWith("0: "));
            }
            finally
            {
                listTrackingParticipant.Trace();
            }
        }
        public void AddToDictionaryShouldAddValueType()
        {
            const string ExpectedKey = "key";
            const int ExpectedValue = 2;
            var dictionary = new Dictionary<string, int>();
            var activity = new AddToDictionary<string, int>();
            var host = new WorkflowInvokerTest(activity);
            dynamic input = new WorkflowArguments();
            input.Dictionary = dictionary;
            input.Key = ExpectedKey;
            input.Value = ExpectedValue;
            try
            {
                host.TestActivity(input);

                Assert.AreEqual(1, dictionary.Count);
                Assert.AreEqual(ExpectedValue, dictionary[ExpectedKey]);
            }
            finally
            {
                host.Tracking.Trace();
            }
        }
Esempio n. 17
0
        public void DelayUntilTimeNowPlus1Sec()
        {
            var activity = new DelayUntilDateTime { UntilDate = DateTime.Now + TimeSpan.FromSeconds(1) };

            var host = new WorkflowInvokerTest(activity);

            try
            {
                host.TestActivity(Constants.Timeout);
            }
            finally
            {
                host.Tracking.Trace();
            }
        }
 public void ValueExistsInDictionaryReturnTrueWhenValueExists()
 {
     const string ExpectedKey = "key";
     const string ExpectedValue = "value";
     var dictionary = new Dictionary<string, string> { { ExpectedKey, ExpectedValue } };
     var activity = new ValueExistsInDictionary<string, string>();
     var host = new WorkflowInvokerTest(activity);
     dynamic input = new WorkflowArguments();
     input.Dictionary = dictionary;
     input.Value = ExpectedValue;
     try
     {
         host.TestActivity(input);
         host.AssertOutArgument.IsTrue("Result");
     }
     finally
     {
         host.Tracking.Trace();
     }
 }
 public void ValueExistsInNullDictionaryShouldThrow()
 {
     var activity = new ValueExistsInDictionary<string, string>();
     var host = new WorkflowInvokerTest(activity);
     dynamic input = new WorkflowArguments();
     input.Dictionary = null;
     input.Value = "value";
     try
     {
         AssertHelper.Throws<InvalidOperationException>(() => host.TestActivity(input));
     }
     finally
     {
         host.Tracking.Trace();
     }
 }
 public void GetFromDictionaryReturnTrueWhenGetWithGoodKey()
 {
     const string ExpectedKey = "key";
     const string ExpectedValue = "value";
     var dictionary = new Dictionary<string, string> { { ExpectedKey, ExpectedValue } };
     var activity = new GetFromDictionary<string, string>();
     var host = new WorkflowInvokerTest(activity);
     dynamic input = new WorkflowArguments();
     input.Dictionary = dictionary;
     input.Key = ExpectedKey;
     try
     {
         host.TestActivity(input);
         host.AssertOutArgument.IsTrue("Result");
         host.AssertOutArgument.AreEqual("Value", ExpectedValue);
     }
     finally
     {
         host.Tracking.Trace();
     }
 }
 public void RemoveFromNullDictionaryShouldThrow()
 {
     var activity = new RemoveFromDictionary<string, string>();
     var host = new WorkflowInvokerTest(activity);
     dynamic input = new WorkflowArguments();
     input.Dictionary = null;
     input.Key = "key";
     try
     {
         AssertHelper.Throws<InvalidOperationException>(() => host.TestActivity(input));
     }
     finally
     {
         host.Tracking.Trace();
     }
 }
 public void AddToNullDictionaryShouldThrow()
 {
     const string ExpectedKey = "key";
     const string ExpectedValue = "value";
     var activity = new AddToDictionary<string, string>();
     var host = new WorkflowInvokerTest(activity);
     dynamic input = new WorkflowArguments();
     input.Dictionary = null;
     input.Key = ExpectedKey;
     input.Value = ExpectedValue;
     try
     {
         AssertHelper.Throws<InvalidOperationException>(() => host.TestActivity(input));
     }
     finally
     {
         host.Tracking.Trace();
     }
 }
        public void ClearDictionaryShouldClear()
        {
            var dictionary = new Dictionary<string, int> { { "Key", 1 } };
            var activity = new ClearDictionary<string, int>();
            var host = new WorkflowInvokerTest(activity);
            dynamic input = new WorkflowArguments();
            input.Dictionary = dictionary;
            try
            {
                host.TestActivity(input);

                Assert.AreEqual(0, dictionary.Count);
            }
            finally
            {
                host.Tracking.Trace();
            }
        }
        public void WhatHappensIfCopiedCustomerExists()
        {
            var collection = new Collection<Customer>();
            var customer1 = new Customer();

            // Add the customer to the list
            collection.Add(customer1);

            // Create a copy of the same customer
            var customer2 = new Customer(customer1);

            var activity = new EnsureCustomerIsInList();
            var host = new WorkflowInvokerTest(activity);

            // Pass the copy to the activity
            var inputs = new Dictionary<string, object> { { "CustomerCollection", collection }, { "Customer", customer2 } };

            try
            {
                host.TestActivity(inputs);

                this.TestContext.WriteLine("Customer collection count {0}", collection.Count);
                foreach (var cust in collection)
                {
                    this.TestContext.WriteLine("Customer ID {0}", cust.Id);
                }

                // The copy will be added because the reference is not equal
                // This is probably not be what you want
                Assert.IsTrue(collection.Contains(customer1));
                Assert.IsTrue(collection.Contains(customer2));

                // Both customer and customer2 are in the collection
                Assert.AreEqual(2, collection.Count);
            }
            finally
            {
                host.Tracking.Trace();
            }
        }
Esempio n. 25
0
        public void ShouldAddGoodSumAssertOutArgument()
        {
            var sut = new WorkflowInvokerTest(new GoodSum { x = 1, y = 2 });
            sut.TestActivity();

            sut.AssertOutArgument.AreEqual("sum", 3);
        }
 /// <summary>
 /// Given
 ///   * Workflow.xaml deployed
 ///   * Activity V1 (signed) deployed
 ///   When
 ///   * ActivityLoad with ref to ActivityLibrary V1 (signed)
 ///   Then
 ///   * the workflow should return V1
 /// </summary>
 public void WorkflowXamlRefActivityV1DeployedActivityV1ShouldLoad()
 {
     var host =
         new WorkflowInvokerTest(
             StrictXamlHelper.ActivityLoad(GetWorkflowXaml(), GetListWithActivityLibraryVersion(1)));
     host.TestActivity(Constants.Timeout);
     host.AssertOutArgument.AreEqual("AssemblyVersion", new Version(1, 0, 0, 0));
 }
        public void WhenRequiredArgIsNotProvidedShouldThrowArgumentException()
        {
            var host = new WorkflowInvokerTest(new ActivityWithOptionalArgs { UseContext = true });

            // Required argument was not supplied, this should throw an exception
            AssertHelper.Throws<ArgumentException>(
                () => host.TestActivity(),
                string.Empty,
                "The activity should fail because the RequiredArg was not provided");
        }
Esempio n. 28
0
        public void DelayUntilTimeXamlNowPlus1Day1Sec()
        {
            var time = DateTime.Now.AddSeconds(2).TimeOfDay;
            var activity = new DelayUntilTimeTest { UntilTime = time };
            var host = new WorkflowInvokerTest(activity);
            var stopwatch = new Stopwatch();

            try
            {
                stopwatch.Start();
                host.TestActivity(Constants.Timeout);
                stopwatch.Stop();
            }
            finally
            {
                host.Tracking.Trace();
            }

            Assert.IsTrue(stopwatch.ElapsedMilliseconds > 900);
        }