Example #1
0
        public void StringBuilderExtensions_Activate_WithColorWithHashTag_Should_ContainActivationLineWithColor()
        {
            // Assign
            var stringBuilder = new StringBuilder();

            // Act
            stringBuilder.Activate("actor", "#Blue");

            // Assert
            stringBuilder.ToString().Should().Be("activate actor #Blue\n");
        }
Example #2
0
        public void StringBuilderExtensions_Activate_Should_ContainActivateLine()
        {
            // Assign
            var stringBuilder = new StringBuilder();

            // Act
            stringBuilder.Activate("actor");

            // Assert
            stringBuilder.ToString().Should().Be("activate actor\n");
        }
Example #3
0
        public void StringBuilderExtensions_Activate_WithColorAndBorderColor_Should_ContainActivationLineWithColors()
        {
            // Assign
            var stringBuilder = new StringBuilder();

            // Act
            stringBuilder.Activate("actor", "Blue", NamedColor.APPLICATION);

            // Assert
            stringBuilder.ToString().Should().Be("activate actor #Blue #APPLICATION\n");
        }
Example #4
0
        public void StringBuilderExtensions_Activate_WithOnlyBorderColor_Should_ContainActivationLineWithNoColors()
        {
            // Assign
            var stringBuilder = new StringBuilder();

            // Act
            stringBuilder.Activate("actor", borderColor: "Blue");

            // Assert
            stringBuilder.ToString().Should().Be("activate actor\n");
        }
Example #5
0
        public void StringBuilderExtensions_Activate_WhitespaceName_Should_ThrowArgumentException()
        {
            // Assign
            var stringBuilder = new StringBuilder();

            // Act
            Action action = () => stringBuilder.Activate(" ");

            // Assert
            action.Should().Throw <ArgumentException>()
            .WithMessage("A non-empty value should be provided*")
            .And.ParamName.Should().Be("name");
        }
Example #6
0
        /// <summary>
        /// Renders an arrow between two participants.
        /// </summary>
        /// <remarks>
        /// Takes scope (if/alt/group/etc.) into account for correctly close activation lines.
        /// </remarks>
        private static void RenderArrow(StringBuilder stringBuilder, Arrow arrow, IReadOnlyList <InteractionFragment> scope, Interactions tree, List <string> activations)
        {
            var target = (arrow.Source != "W" && arrow.Target == "A") ? "Q" : arrow.Target;

            stringBuilder.Arrow(arrow.Source, $"-{arrow.Color}>", target, label: arrow.Name);

            if (!activations.Contains(arrow.Source))
            {
                // Scope was activated in current scope

                if (arrow.Target != "]" && arrow.Source != "A" && arrow.Source != "W" && !arrow.Source.StartsWith("x ", StringComparison.Ordinal) && scope.Descendants <Arrow>().Last(a => a.Source == arrow.Source) == arrow && arrow.Source != arrow.Target)
                {
                    // This is the last arrow from this source
                    stringBuilder.Deactivate(arrow.Source);

                    activations.Remove(arrow.Source);
                }
            }

            if (!activations.Contains(arrow.Target))
            {
                // Scope was not activated by the parent scope

                if ((arrow.Target != "A" || arrow.Source == "W") && arrow.Target != "Q" && arrow.Target != "W" && !arrow.Target.StartsWith("x ", StringComparison.Ordinal) && arrow.Source != arrow.Target && scope.OfType <Arrow>().First(a => a.Target == arrow.Target) == arrow)
                {
                    var previousArrows = arrow.Ancestors().SelectMany(a => a.StatementsBeforeSelf()).OfType <Arrow>().ToList();
                    if (!previousArrows.Any(a => a.Target == arrow.Target) && !ExternalTargets.Contains(arrow.Target))
                    {
                        // There was no earlier activation in the current scope
                        stringBuilder.Activate(arrow.Target);

                        activations.Add(arrow.Target);
                    }
                }
            }
        }