Example #1
0
        public void TestNextComponent(string pathString, int numberOfCalls, bool expectedResult)
        {
            // Arrange
              var path = Path.Create(pathString);
              var sut = new PathWalker(path);
              bool result = false;

              // Act
              for(int i = 0; i < numberOfCalls; i++)
              {
            result = sut.NextComponent();
              }

              // Assert
              Assert.AreEqual(expectedResult, result);
        }
Example #2
0
        public void TestCurrentComponent(string pathString, int component, int expectedPartCount)
        {
            // Arrange
              var path = Path.Create(pathString);
              var sut = new PathWalker(path);
              int result = 0;

              // Act
              for(int i = 0; i < component; i++)
              {
            sut.NextComponent();
            result = sut.CurrentComponent.Parts.Count;
              }

              // Assert
              Assert.AreEqual(expectedPartCount, result);
        }
Example #3
0
        public void TestCurrentPart(string pathString, int component, int part, string expectedValue)
        {
            // Arrange
              var path = Path.Create(pathString);
              var sut = new PathWalker(path);

              for(int i = 0; i < component; i++)
              {
            sut.NextComponent();
              }

              // Act
              for(int i = 0; i < part; i++)
              {
            sut.NextPart();
              }

              // Assert
              Assert.NotNull(sut.CurrentPart, "Result nullability");
              Assert.AreEqual(expectedValue, sut.CurrentPart.Value, "Result value");
        }
        /// <summary>
        /// Walks and evaluates a TALES path.
        /// </summary>
        /// <returns>The evaluated value of the path.</returns>
        /// <param name="walker">A TALES path walker, containing a path.</param>
        /// <param name="context">The rendering context for the expression being evaluated.</param>
        /// <param name="model">The ZPT model, providing the context for evaluation.</param>
        private object WalkPath(PathWalker walker, IRenderingContext context, ITalesModel model)
        {
            object output = null;
              bool success = false;

              while(walker.NextComponent() && !success)
              {
            success = this.WalkComponent(walker, context, model, out output);
              }

              if(!success)
              {
            throw new TraversalException(Resources.ExceptionMessages.CouldNotWalkAnyPaths);
              }

              return output;
        }
Example #5
0
        public void TestReset()
        {
            // Arrange
              var path = Path.Create("foo/bar|wibble/wobble");
              var sut = new PathWalker(path);

              sut.NextComponent();
              sut.NextComponent();
              sut.NextPart();
              sut.NextPart();

              // Act
              sut.Reset();

              // Assert
              Assert.IsTrue(sut.NextComponent(),              "NextComponent result");
              Assert.IsTrue(sut.NextPart(),                   "NextPart result");
              Assert.AreEqual("foo",  sut.CurrentPart.Value,  "CurrentPart");
        }