예제 #1
0
        public void ApplyFunctionResultShouldThrowValidationExceptionWhenNullContext()
        {
            var sender = new object();

            var functionResult = new FunctionResult()
            {
            };

            var functionsManager = new FunctionsManager("component", "statemachine");

            functionsManager.AddTask(new object(), new object(), new object(), new object(), sender, "function");

            while (true)
            {
                var postedTask = functionsManager.GetTask();
                if (postedTask != null)
                {
                    break;
                }
                Thread.Sleep(TimeSpan.FromSeconds(1));
            }

            var exception = Assert.Throws <ValidationException>(() => functionsManager.ApplyFunctionResult(functionResult,
                                                                                                           new object(),
                                                                                                           new object(),
                                                                                                           null,
                                                                                                           sender));

            Assert.IsTrue(exception.Message.Contains("Context"),
                          "Exception message should show where is the problem");
        }
예제 #2
0
        public void ObjectsHaveNoPropertyToDeserializeSoIgnoringThemInsteadOfThrowing()
        {
            var functionResult = new FunctionResult()
            {
                PublicMember   = new JObject(),
                InternalMember = new JObject()
            };

            var sender           = new object();
            var context          = new object();
            var publicMember     = new object();
            var internalMember   = new object();
            var functionsManager = new FunctionsManager("component", "statemachine");

            functionsManager.AddTask(new object(),
                                     publicMember,
                                     internalMember,
                                     context,
                                     sender);

            Assert.DoesNotThrow(() =>
            {
                functionsManager.ApplyFunctionResult(functionResult,
                                                     publicMember,
                                                     internalMember,
                                                     context,
                                                     sender);
            });
        }
예제 #3
0
        public void ApplyPostedResultShouldWorkWithJObjects()
        {
            var publicMemberBefore = new PublicMember()
            {
                State = "before"
            };

            var publicMemberAfter = new JObject();

            publicMemberAfter.Add("State", new JValue("after"));

            var functionResult = new FunctionResult()
            {
                PublicMember = publicMemberAfter,
            };

            var sender           = new object();
            var context          = new object();
            var internalMember   = new object();
            var functionsManager = new FunctionsManager("component", "statemachine");

            functionsManager.AddTask(new object(),
                                     publicMemberBefore,
                                     internalMember,
                                     context,
                                     sender);

            functionsManager.ApplyFunctionResult(functionResult,
                                                 publicMemberBefore,
                                                 new object(),
                                                 context,
                                                 sender);

            Assert.AreEqual("after", publicMemberBefore.State);
        }
예제 #4
0
        public void ApplyFunctionResultShouldThrowValidationExceptionWhenDeserializationFails()
        {
            var sender             = new object();
            var publicMemberBefore = new PublicMember()
            {
                State = "before"
            };

            var publicMemberAfter = new JObject();

            publicMemberAfter.Add("State", new JValue("after"));

            var functionResult = new FunctionResult()
            {
                PublicMember = "Hello",
            };

            var functionsManager = new FunctionsManager("component", "statemachine");

            functionsManager.AddTask(new object(), new object(), new object(), new object(), sender, "function");

            while (true)
            {
                var postedTask = functionsManager.GetTask();
                if (postedTask != null)
                {
                    break;
                }
                Thread.Sleep(TimeSpan.FromSeconds(1));
            }

            var exception = Assert.Throws <ValidationException>(() => functionsManager.ApplyFunctionResult(functionResult,
                                                                                                           publicMemberBefore,
                                                                                                           new object(),
                                                                                                           new object(),
                                                                                                           sender));

            Assert.IsTrue(exception.Message.Contains("Hello"),
                          "Exception message should show where is the problem");
        }
예제 #5
0
        public void ApplyFunctionResultShouldThrowInvalidSenderValidationException()
        {
            var sender         = new object();
            var functionResult = new FunctionResult()
            {
                Senders = new List <SenderResult>()
                {
                    new SenderResult
                    {
                        SenderName      = "UnknownSender",
                        SenderParameter = "{ \"Value\": \"undo\" }",
                        UseContext      = false
                    },
                },
            };

            var functionsManager = new FunctionsManager("component", "statemachine");

            functionsManager.AddTask(new object(), new object(), new object(), new object(), sender, "function");

            while (true)
            {
                var postedTask = functionsManager.GetTask();
                if (postedTask != null)
                {
                    break;
                }
                Thread.Sleep(TimeSpan.FromSeconds(1));
            }

            var exception = Assert.Throws <ValidationException>(() => functionsManager.ApplyFunctionResult(functionResult,
                                                                                                           new object(),
                                                                                                           new object(),
                                                                                                           new object(),
                                                                                                           sender));

            Assert.IsTrue(exception.Message.Contains("UnknownSender"),
                          "Exception message should show where is the problem");
        }