コード例 #1
0
        public static StaticBusinessObjectPropertyPath Parse(string propertyPathIdentifier, IBusinessObjectClass root)
        {
            ArgumentUtility.CheckNotNullOrEmpty("propertyPathIdentifier", propertyPathIdentifier);
            ArgumentUtility.CheckNotNull("root", root);

            var properties         = new List <IBusinessObjectProperty>();
            var currentClass       = root;
            var propertyEnumerator = new StaticBusinessObjectPropertyPathPropertyEnumerator(propertyPathIdentifier);

            while (currentClass != null && propertyEnumerator.MoveNext(currentClass))
            {
                var currentProperty = propertyEnumerator.Current;
                Assertion.IsNotNull(currentProperty, "StaticPropertyPathPropertyEnumerator never returns null on successful enumeration.");
                properties.Add(currentProperty);

                var currentReferenceProperty = currentProperty as IBusinessObjectReferenceProperty;
                if (currentReferenceProperty != null)
                {
                    currentClass = currentReferenceProperty.ReferenceClass;
                }
                else
                {
                    currentClass = null;
                }
            }

            return(new StaticBusinessObjectPropertyPath(properties.ToArray(), propertyPathIdentifier));
        }
コード例 #2
0
        public void MoveNext_WithMissingProperty_ThrowsParseException()
        {
            var firstClassStub  = CreateClassStub();
            var secondClassStub = CreateClassStub();

            secondClassStub.Stub(_ => _.Identifier).Return("SecondClass");

            var firstPropertyStub = CreateReferencePropertyStub(firstClassStub, "FirstProperty", secondClassStub);

            var enumerator = new StaticBusinessObjectPropertyPathPropertyEnumerator("FirstProperty:Missing:ThirdProperty");

            Assert.That(enumerator.MoveNext(firstClassStub), Is.True);
            Assert.That(enumerator.Current, Is.SameAs(firstPropertyStub));

            Assert.That(
                () => enumerator.MoveNext(secondClassStub),
                Throws.TypeOf <ParseException>().With.Message.EqualTo("BusinessObjectClass 'SecondClass' does not contain a property named 'Missing'."));
        }
コード例 #3
0
        public void MoveNext_WithNonLastPropertyNotReferenceProperty_ThrowsParseException()
        {
            var firstClassStub  = CreateClassStub();
            var secondClassStub = CreateClassStub();

            secondClassStub.Stub(_ => _.Identifier).Return("SecondClass");

            var firstPropertyStub  = CreateReferencePropertyStub(firstClassStub, "FirstProperty", secondClassStub);
            var secondPropertyStub = CreatePropertyStub(secondClassStub, "SecondProperty");

            var enumerator = new StaticBusinessObjectPropertyPathPropertyEnumerator("FirstProperty:SecondProperty:ThirdProperty");

            Assert.That(enumerator.MoveNext(firstClassStub), Is.True);
            Assert.That(enumerator.Current, Is.SameAs(firstPropertyStub));

            Assert.That(
                () => enumerator.MoveNext(secondClassStub),
                Throws.TypeOf <ParseException>()
                .With.Message.EqualTo(
                    string.Format(
                        "Each property in a property path except the last one must be a reference property. "
                        + "Property 'SecondProperty' is of type '{0}'.",
                        secondPropertyStub.GetType().Name)));
        }
コード例 #4
0
        public void MoveNext_WithMultipleProperties()
        {
            var firstClassStub  = CreateClassStub();
            var secondClassStub = CreateClassStub();
            var thirdClassStub  = CreateClassStub();

            var firstPropertyStub  = CreateReferencePropertyStub(firstClassStub, "FirstProperty", secondClassStub);
            var secondPropertyStub = CreateReferencePropertyStub(secondClassStub, "SecondProperty", thirdClassStub);
            var thirdPropertyStub  = CreatePropertyStub(thirdClassStub, "ThirdProperty");

            var enumerator = new StaticBusinessObjectPropertyPathPropertyEnumerator("FirstProperty:SecondProperty:ThirdProperty");

            Assert.That(enumerator.MoveNext(firstClassStub), Is.True);
            Assert.That(enumerator.Current, Is.SameAs(firstPropertyStub));

            Assert.That(enumerator.MoveNext(secondClassStub), Is.True);
            Assert.That(enumerator.Current, Is.SameAs(secondPropertyStub));

            Assert.That(enumerator.MoveNext(thirdClassStub), Is.True);
            Assert.That(enumerator.Current, Is.SameAs(thirdPropertyStub));

            Assert.That(enumerator.MoveNext(MockRepository.GenerateStub <IBusinessObjectClass>()), Is.False);
            Assert.That(() => enumerator.Current, Throws.InvalidOperationException.With.Message.EqualTo("Enumeration already finished."));
        }