/// <summary>
        /// Creates a new <see cref="AppendCommandBuilder"/>.
        /// </summary>
        public AppendCommandBuilder(TaconiteResult result)
        {
            if (result == null)
            throw new ArgumentNullException("result");

              Result = result;
        }
        /// <summary>
        /// Creates a new <see cref="ReplaceContentsOfCommandBuilder"/>.
        /// </summary>
        public ReplaceContentsOfCommandBuilder(TaconiteResult result)
        {
            if (result == null)
            throw new ArgumentNullException("result");

              Result = result;
        }
        public SetAttributeCommandBuilder(TaconiteResult result, object attributes)
        {
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }

            Result = result;

            var properties = TypeDescriptor.GetProperties(attributes);

            if (properties.Count == 0)
            {
                throw new ArgumentException("Object has no properties");
            }

            foreach (PropertyDescriptor property in properties)
            {
                var attributeName = property.Name.Replace('_', '-');

                if (_attributes.ContainsKey(attributeName))
                {
                    throw new ArgumentException("Object contains duplicate attributes having name '{0}'", property.Name);
                }

                _attributes[attributeName] = Convert.ToString(property.GetValue(attributes));
            }
        }
Exemple #4
0
        public void ExecuteResult_TwoCommands_WritesCorrectTaconiteDocumentToResponse()
        {
            var      controllerContext = Substitute.For <ControllerContext>();
            XElement taconiteDocument  = null;

            controllerContext.HttpContext.Response.Received()
            .When(x => x.Write(Arg.Any <XElement>()))
            .Do(x => taconiteDocument = x.Arg <XElement>());
            var taconiteResult   = new TaconiteResult();
            var command0         = Substitute.For <TaconiteCommand>();
            var command0XElement = new XElement("command0");

            command0.CreateCommandXElement(Arg.Any <ActionResultExecutor>()).Returns(command0XElement);
            taconiteResult.AddCommand(command0);
            var command1         = Substitute.For <TaconiteCommand>();
            var command1XElement = new XElement("command1");

            command1.CreateCommandXElement(Arg.Any <ActionResultExecutor>()).Returns(command1XElement);
            taconiteResult.AddCommand(command1);

            taconiteResult.ExecuteResult(controllerContext);

            controllerContext.HttpContext.Response.Received().ContentType = "text/xml";
            controllerContext.HttpContext.Response.Received().Write(Arg.Any <XElement>());
            taconiteDocument.Name.Should().Be((XName)"taconite");
            taconiteDocument.Elements().Should().HaveCount(2)
            .And.ContainInOrder(command0XElement, command1XElement);
        }
Exemple #5
0
        public void AddCommand_NullCommand_ThrowsArgumentNullException()
        {
            var taconiteResult = new TaconiteResult();

            Action action = () => taconiteResult.AddCommand(null);

            action.ShouldThrow <ArgumentNullException>();
        }
Exemple #6
0
        public void ExecuteResult_NullControllerContext_ThrowsArgumentNullException()
        {
            var taconiteResult = new TaconiteResult();

            Action action = () => taconiteResult.ExecuteResult(null);

            action.ShouldThrow <ArgumentNullException>();
        }
        public AddClassCommandBuilder(TaconiteResult result, params string[] classNames)
        {
            if (result == null)
            throw new ArgumentNullException("result");

              Result = result;
              _classNames = classNames;
        }
Exemple #8
0
        /// <summary>
        /// Creates a new <see cref="ReplaceContentsOfCommandBuilder"/>.
        /// </summary>
        public ReplaceContentsOfCommandBuilder(TaconiteResult result)
        {
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            Result = result;
        }
Exemple #9
0
        /// <summary>
        /// Creates a new <see cref="PrependCommandBuilder"/>.
        /// </summary>
        public PrependCommandBuilder(TaconiteResult result)
        {
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            Result = result;
        }
Exemple #10
0
        public void AddCommand_AddsCommand()
        {
            var command        = Substitute.For <TaconiteCommand>();
            var taconiteResult = new TaconiteResult();

            taconiteResult.AddCommand(command);

            taconiteResult.Commands.Should().HaveCount(1)
            .And.Contain(command);
        }
        public AddClassCommandBuilder(TaconiteResult result, params string[] classNames)
        {
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            Result      = result;
            _classNames = classNames;
        }
        public RemoveAttributeCommandBuilder(TaconiteResult result, params string[] attributes)
        {
            if (result == null)
            throw new ArgumentNullException("result");
              if (attributes == null)
            throw new ArgumentNullException("attributes");

              Result = result;
              _attributes = attributes;
        }
        public SetAttributeCommandBuilder(TaconiteResult result, string name, object value)
        {
            if (result == null)
            throw new ArgumentNullException("result");
              if (String.IsNullOrEmpty(name))
            throw new ArgumentNullException("name");
              if (value == null)
            throw new ArgumentNullException("value");

              Result = result;
              _attributes[name] = Convert.ToString(value);
        }
Exemple #14
0
        public void ExecuteResult_PassesActionResultExecutorToEachCommandWithCorrectContext()
        {
            var controllerContext = Substitute.For <ControllerContext>();
            var taconiteResult    = new TaconiteResult();
            var command           = Substitute.For <TaconiteCommand>();
            var commandXElement   = new XElement("command");

            command.CreateCommandXElement(Arg.Any <ActionResultExecutor>()).Returns(commandXElement);
            taconiteResult.AddCommand(command);

            taconiteResult.ExecuteResult(controllerContext);

            command.Received().CreateCommandXElement(Arg.Is <ActionResultExecutor>(x => x.ControllerContext == controllerContext));
        }
Exemple #15
0
        public RemoveAttributeCommandBuilder(TaconiteResult result, params string[] attributes)
        {
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }

            Result      = result;
            _attributes = attributes;
        }
Exemple #16
0
        public void ExecuteResult_ZeroCommands_WritesCorrectTaconiteDocumentToResponse()
        {
            var      controllerContext = Substitute.For <ControllerContext>();
            XElement taconiteDocument  = null;

            controllerContext.HttpContext.Response.Received()
            .When(x => x.Write(Arg.Any <XElement>()))
            .Do(x => taconiteDocument = x.Arg <XElement>());
            var taconiteResult = new TaconiteResult();

            taconiteResult.ExecuteResult(controllerContext);

            controllerContext.HttpContext.Response.Received().ContentType = "text/xml";
            controllerContext.HttpContext.Response.Received().Write(Arg.Any <XElement>());
            taconiteDocument.Name.Should().Be((XName)"taconite");
            taconiteDocument.HasElements.Should().BeFalse();
        }
        public SetAttributeCommandBuilder(TaconiteResult result, string name, object value)
        {
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            Result            = result;
            _attributes[name] = Convert.ToString(value);
        }
        public SetAttributeCommandBuilder(TaconiteResult result, object attributes)
        {
            if (result == null)
            throw new ArgumentNullException("result");
              if (attributes == null)
            throw new ArgumentNullException("attributes");

              Result = result;

              var properties = TypeDescriptor.GetProperties(attributes);
              if (properties.Count == 0)
            throw new ArgumentException("Object has no properties");

              foreach (PropertyDescriptor property in properties)
              {
            var attributeName = property.Name.Replace('_', '-');

            if (_attributes.ContainsKey(attributeName))
              throw new ArgumentException("Object contains duplicate attributes having name '{0}'", property.Name);

            _attributes[attributeName] = Convert.ToString(property.GetValue(attributes));
              }
        }
 /// <summary>
 /// Creates a new <see cref="ExecutePluginCommandBuilder"/>.
 /// </summary>
 public ExecutePluginCommandBuilder(ITaconite taconite)
 {
     Result = taconite as TaconiteResult ?? new TaconiteResult();
 }