Exemplo n.º 1
0
        public void substories_should_be_in_right_order()
        {
            List <string> _loggedStoryNames = new List <string>();

            var handlerRules = new Ruleset <IStory, IStoryHandler>();

            handlerRules.Rules.Add(new PredicateRule
                                   (
                                       _ => _.IsRoot(),
                                       _ => new ActionHandler("unittest", (story) => RegisterStoryName(story, _loggedStoryNames))
                                   )
                                   );
            Storytelling.Factory = new BasicStoryFactory(handlerRules);
            using (Storytelling.StartNew("parent"))
            {
                using (Storytelling.StartNew("child1")) { }
                using (Storytelling.StartNew("child2"))
                {
                    using (Storytelling.StartNew("child2/child1")) { }
                    using (Storytelling.StartNew("child2/child2")) { }
                }
                using (Storytelling.StartNew("child3")) { }
            }

            CollectionAssert.AreEqual(new List <string>
            {
                "parent",
                "child1",
                "child2",
                "child2/child1",
                "child2/child2",
                "child3",
            }, _loggedStoryNames);
        }
Exemplo n.º 2
0
        public void story_data_is_observed_during_invocation()
        {
            var data = new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("bool_value", true),
                new KeyValuePair <string, object>("int_value", 123),
                new KeyValuePair <string, object>("string_value", "test!"),
            };

            var handlerRules = new Ruleset <IStory, IStoryHandler>()
            {
                Rules =
                {
                    new PredicateRule(
                        _ => true,                                                        // always run for story
                        _ => new ActionHandler(
                            "data_verification_handler",
                            (story) => Assert.AreEqual(0, story.Data.Count()),            // make sure OnStart() is invoked with zero data items.
                            (story) => Assert.IsTrue(data.SequenceEqual(story.Data)))     // make sure OnStop() is invoked with 3 data items.
                        ),
                },
            };

            Storytelling.StartNew("testStory", () =>
            {
                foreach (var kvp in data)
                {
                    Storytelling.Data[kvp.Key] = kvp.Value;
                }
            });
        }
Exemplo n.º 3
0
        public void story_handler_is_not_invoked_when_rule_condition_is_not_met()
        {
            var invokedBefore = false;
            var invokedAfter  = false;

            var handlerRules = new Ruleset <IStory, IStoryHandler>()
            {
                Rules =
                {
                    new PredicateRule(story =>
                    {
                        var userId = (string)story.Data["userId"];
                        return(userId != null && userId == "user13");
                    },
                                      _ => new ActionHandler("invocation_handler", s => invokedBefore = true, s => invokedAfter = true)),
                }
            };

            Storytelling.Factory = new BasicStoryFactory(handlerRules);

            Storytelling.StartNew("testStory", () =>
            {
                Storytelling.Data["userId"] = "user21";

                Assert.IsFalse(invokedBefore);
                Assert.IsFalse(invokedAfter);
            });
        }
Exemplo n.º 4
0
        public void story_name_is_not_chained_to_null_parent()
        {
            var handlerRules = new Ruleset <IStory, IStoryHandler>();

            Storytelling.StartNew("testStory", () =>
            {
                Assert.AreEqual("testStory", Storytelling.Current.Name);
            });
        }
Exemplo n.º 5
0
        public void story_exception_thrown_is_propagated()
        {
            var handlerRules = new Ruleset <IStory, IStoryHandler>();

            Storytelling.StartNew("testStory", () =>
            {
                throw new InvalidOperationException("oh oh");
            });
        }
Exemplo n.º 6
0
        public void story_name_is_chained_to_parent()
        {
            var handlerRules = new Ruleset <IStory, IStoryHandler>();

            Storytelling.StartNew("base", () =>
            {
                Storytelling.StartNew("child", () =>
                {
                    Assert.AreEqual("base/child", Storytelling.Current.Name);
                });
            });
        }
Exemplo n.º 7
0
        public void story_log_is_observed_during_invocation()
        {
            var log = new List <KeyValuePair <LogSeverity, string> >
            {
                new KeyValuePair <LogSeverity, string>(LogSeverity.Info, "test_info"),
                new KeyValuePair <LogSeverity, string>(LogSeverity.Warning, "test_warning"),
                new KeyValuePair <LogSeverity, string>(LogSeverity.Error, "test_error"),
            };

            var handlerRules = new Ruleset <IStory, IStoryHandler>()
            {
                Rules =
                {
                    new PredicateRule(
                        _ => true,                                                              // always run for story
                        _ => new ActionHandler(
                            "data_verification_handler",
                            (story) => Assert.AreEqual(0, story.Log.Count()),                   // make sure OnStart() is invoked with zero log items.
                            (story) => Assert.IsTrue(story.Log.All(
                                                         entry => log.Exists(
                                                             l => l.Key == entry.Severity &&
                                                             l.Value == entry.Text))))
                        ),
                },
            };

            Storytelling.Factory = new BasicStoryFactory(handlerRules);

            Storytelling.StartNew("testStory", () =>
            {
                foreach (var kvp in log)
                {
                    Storytelling.Current.Log.Add(kvp.Key, kvp.Value);
                }
            });
        }