public void BeginActivity()
        {
            var es       = new TestEventStream();
            var activity = ActivityFactory.NewActivity <TestActivity>(new EventStreamMediator(es));
            EventHandler <ActivityEventArgs> handler = null;
            AutoResetEvent rst = new AutoResetEvent(false);

            try
            {
                handler = (sender, e) => {
                    Assert.AreEqual(activity.ActivityName, e.Arguments["activityName"], "activityName");
                    Assert.AreEqual(activity.ActivityId, e.Arguments["activityInstance"], "activityInstance");
                    rst.Set();
                };

                es.BeginActivityCalled += handler;

                activity.BeginActivity();

                Assert.IsTrue(rst.WaitOne(1000), "Begin Activity failed to complete");
            }
            finally
            {
                if (handler != null)
                {
                    es.BeginActivityCalled -= handler;
                }
                activity.Dispose();
            }
        }
        public void EnableContinuationGeneratedId()
        {
            var es         = new TestEventStream();
            var activityId = Guid.NewGuid().ToString();
            var activity   = ActivityFactory.NewActivity <TestActivity>(new EventStreamMediator(es), activityId);
            EventHandler <ActivityEventArgs> handler = null;
            AutoResetEvent rst = new AutoResetEvent(false);

            try
            {
                handler = (sender, e) => {
                    Assert.AreEqual(activity.ActivityName, e.Arguments["activityName"], "activityName");
                    Assert.AreEqual(activity.ActivityId, e.Arguments["activityInstance"], "activityInstance");

                    Assert.AreEqual("CONT_" + activityId, e.Arguments["continuationToken"], "continuationToken");

                    rst.Set();
                };

                es.EnableContinuationCalled += handler;

                activity.EnableContinuation();
                Assert.IsTrue(rst.WaitOne(1000), "End Activity failed to complete");
            }
            finally
            {
                if (handler != null)
                {
                    es.EnableContinuationCalled -= handler;
                }
                activity.Dispose();
            }
        }
        public void FactoryNewActivityWithId()
        {
            var activityId = Guid.NewGuid().ToString();
            var activity   = (TestActivity)ActivityFactory.NewActivity(typeof(TestActivity), new EventStreamMediator(new TestEventStream()), activityId);

            ActivityCheckCommon(activity);
            Assert.AreEqual(activityId, activity.ActivityId);
        }
        public void CommitActivity()
        {
            var es       = new TestEventStream();
            var activity = ActivityFactory.NewActivity <TestActivity>(new EventStreamMediator(es));
            EventHandler <ActivityEventArgs> handler = null;
            AutoResetEvent rst = new AutoResetEvent(false);

            try
            {
                activity.ActivityCustomDate1     = DateTime.Now;
                activity.ActivityCustomInt1      = TestHelper.Rnd.Next();
                activity.ActivityCustomString1   = Guid.NewGuid().ToString();
                activity.ActivityFieldNameChange = TestHelper.Rnd.Next();
                activity.ActivityValueType       = "foo";

                handler = (sender, e) => {
                    Assert.AreEqual(activity.ActivityName, e.Arguments["activityName"], "activityName");
                    Assert.AreEqual(activity.ActivityId, e.Arguments["activityInstance"], "activityInstance");

                    var data = ((object[])e.Arguments["data"]).BamDataToDictionary();

                    Assert.AreEqual(activity.ActivityCustomDate1, data["ActivityCustomDate1"]);
                    Assert.AreEqual(activity.ActivityCustomInt1, data["ActivityCustomInt1"]);
                    Assert.AreEqual(activity.ActivityCustomString1, data["ActivityCustomString1"]);
                    Assert.AreEqual(activity.ActivityFieldNameChange, data["Renamed Field"]);
                    Assert.AreEqual(null, data["ActivityNullableDate"]);

                    rst.Set();
                };

                es.UpdateActivityCalled += handler;

                activity.CommitActivity();
                Assert.IsTrue(rst.WaitOne(1000), "Commit Activity failed to complete");
            }
            finally
            {
                if (handler != null)
                {
                    es.UpdateActivityCalled -= handler;
                }
                activity.Dispose();
            }
        }
        public void AddCustomReference2()
        {
            var es       = new TestEventStream();
            var activity = ActivityFactory.NewActivity <TestActivity>(new EventStreamMediator(es));
            EventHandler <ActivityEventArgs> handler = null;
            AutoResetEvent rst = new AutoResetEvent(false);

            try
            {
                string referenceType = "foo", referenceName = "bar", referenceData = "blee", longReferenceData = "fnar";

                handler = (sender, e) => {
                    Assert.AreEqual(activity.ActivityName, e.Arguments["activityName"], "activityName");
                    Assert.AreEqual(activity.ActivityId, e.Arguments["activityId"], "activityInstance");

                    Assert.AreEqual(referenceType, e.Arguments["referenceType"], "referenceType");
                    Assert.AreEqual(referenceName, e.Arguments["referenceName"], "referenceName");
                    Assert.AreEqual(referenceData, e.Arguments["referenceData"], "referenceData");
                    Assert.AreEqual(longReferenceData, e.Arguments["longreferenceData"], "longreferenceData");

                    rst.Set();
                };

                es.AddReferenceCalled += handler;

                activity.AddCustomReference(referenceType, referenceName, referenceData, longReferenceData);
                Assert.IsTrue(rst.WaitOne(1000), "Add Reference failed to complete");
            }
            finally
            {
                if (handler != null)
                {
                    es.AddReferenceCalled -= handler;
                }
                activity.Dispose();
            }
        }
 public void FactoryFailInvalidActivityType()
 {
     Assert.ThrowsException <ArgumentException>(() => ActivityFactory.NewActivity(typeof(object), new EventStreamMediator(new TestEventStream())));
 }
        public void FactoryNewActivity()
        {
            var activity = (TestActivity)ActivityFactory.NewActivity(typeof(TestActivity), new EventStreamMediator(new TestEventStream()));

            ActivityCheckCommon(activity);
        }
        public void FactoryNewActivityGeneric()
        {
            var activity = ActivityFactory.NewActivity <TestActivity>(new EventStreamMediator(new TestEventStream()));

            ActivityCheckCommon(activity);
        }
示例#9
0
 public static TestActivity GetTestActivity(string activityId)
 {
     return(ActivityFactory.NewActivity <TestActivity>(new EventStreamMediator(new TestEventStream()), activityId));
 }