public void TestTryParseAndConvertTemplate(string template, string expectedConvertedTemplate, ICollection <string> expectedKeysArray)
        {
            var actualTemplate = string.Empty;
            ICollection <string> actualKeysArray = null;

            StringFormatHelpers.TryParseAndConvertTemplate(template, out actualTemplate, out actualKeysArray);

            actualTemplate.Should().Be(expectedConvertedTemplate);
            actualKeysArray.Should().Equal(expectedKeysArray);
        }
        public void TestExtractObjectFromPropertyPathSimple()
        {
            var testObj = new
            {
                foo    = "bar",
                nested = new
                {
                    foo = "bar"
                }
            };

            StringFormatHelpers.ExtractObjectFromPropertyPath("foo", testObj).Should().Be(testObj.foo);
            StringFormatHelpers.ExtractObjectFromPropertyPath("nested.foo", testObj).Should().Be(testObj.nested.foo);

            Action negative = () => StringFormatHelpers.ExtractObjectFromPropertyPath("bar", testObj);

            negative.ShouldThrow <InvalidOperationException>();
        }
        public void TestExtractObjectFromPropertyPathCircular()
        {
            var a = new A()
            {
                Value = 1
            };
            var b = new B()
            {
                Value = 2, A = a
            };

            a.B = b;

            StringFormatHelpers.ExtractObjectFromPropertyPath("Value", a).Should().Be(a.Value);
            StringFormatHelpers.ExtractObjectFromPropertyPath("Value", b).Should().Be(b.Value);

            StringFormatHelpers.ExtractObjectFromPropertyPath("B.Value", a).Should().Be(a.B.Value);
            StringFormatHelpers.ExtractObjectFromPropertyPath("A.Value", b).Should().Be(b.A.Value);

            StringFormatHelpers.ExtractObjectFromPropertyPath("A.B.A.B.A.Value", b).Should().Be(a.Value);
        }
 public void TestExtractIndexFromFormat(string template, string expectedIndex)
 {
     StringFormatHelpers.ExtractIndexFromFormat(template).Should().Be(expectedIndex);
 }