public void CanGetKeyFromValueAccess()
        {
            PropertyInfo propertyInfo = typeof(BaseTestDomainObject).GetProperty("Property3");
            ValueAccess  valueAccess  = new PropertyValueAccess(propertyInfo);

            Assert.AreEqual("Property3", valueAccess.Key);
        }
        public IState Next(Token token)
        {
            if (token.TokenType == TokenType.CloseTemplate)
            {
                _builder.AddOutputValue(new PropertyValueAccess
                {
                    Name = _identifier
                });
                return(new CloseTemplateState(_builder));
            }

            if (token.TokenType == TokenType.Dot)
            {
                var valueAccess = new PropertyValueAccess
                {
                    Name = _identifier
                };

                return(new IdentifierDotState(valueAccess, _builder));
            }

            if (token.TokenType == TokenType.LeftParenthesis)
            {
                return(new IdentifierLeftParenthesisState(_identifier, _builder));
            }

            throw new ParsingException(this, token);
        }
Пример #3
0
        public void GetValue_return_value_if_Next_not_null()
        {
            var obj = new
            {
                Language = new
                {
                    Name = "C++"
                }
            };

            var model = new Model(obj);

            var valueAccess = new PropertyValueAccess
            {
                Name = "Language",
                Next = new PropertyValueAccess
                {
                    Name = "Name",
                    Next = null
                }
            };

            object value = model.GetValue(valueAccess);

            Assert.AreEqual("C++", value);
        }
        public void Append_Next_same_appended_element()
        {
            var beginValueAccess = new PropertyValueAccess();

            var endValueAccess = new PropertyValueAccess();

            beginValueAccess.Append(endValueAccess);

            Assert.AreSame(endValueAccess, beginValueAccess.Next);
        }
Пример #5
0
        public IState Next(Token token)
        {
            if (token.TokenType == TokenType.Identifier)
            {
                var endValueAccess = new PropertyValueAccess {
                    Name = token.Content
                };
                _valueAccess.Append(endValueAccess);
                return(new IdentifierDotIdentifierState(_valueAccess, _builder));
            }

            throw new ParsingException(this, token);
        }
        public IState Next(Token token)
        {
            if (token.TokenType == TokenType.Identifier)
            {
                var valueAccess = new PropertyValueAccess {
                    Name = token.Content
                };
                _conditionTemplateElement.ValueAccess = valueAccess;
                return(new BeginIfIdentifierState(valueAccess, _builder));
            }

            throw new ParsingException(this, token);
        }
Пример #7
0
        public void CanValidateThroughPropertyAccess()
        {
            DerivedTestDomainObject targetToValidate = new DerivedTestDomainObject();
            PropertyValueAccess     valueAccess      = new PropertyValueAccess(typeof(DerivedTestDomainObject).GetProperty("Property2"));
            MockValidator <object>  valueValidator   = new MockValidator <object>(false);
            Validator validator = new ValueAccessValidator(valueAccess, valueValidator);

            ValidationResults validationResults = validator.Validate(targetToValidate);

            Assert.IsTrue(validationResults.IsValid);
            Assert.AreEqual(1, valueValidator.ValidatedTargets.Count);
            Assert.AreSame(targetToValidate.Property2, valueValidator.ValidatedTargets[0]);
        }
        public void RetrievalOfValueForInstanceOfNonRelatedTypeReturnsFailure()
        {
            PropertyInfo propertyInfo = typeof(BaseTestDomainObject).GetProperty("Property1");
            ValueAccess  valueAccess  = new PropertyValueAccess(propertyInfo);

            object value;
            string valueAccessRetrievalFailure;
            bool   status = valueAccess.GetValue("a string", out value, out valueAccessRetrievalFailure);

            Assert.IsFalse(status);
            Assert.IsNull(value);
            Assert.IsTrue(TemplateStringTester.IsMatch(Resources.ErrorValueAccessInvalidType, valueAccessRetrievalFailure));
        }
        public void RetrievalOfValueForInstanceOfDerivedTypeThroughNewAliasedPropertyReturnsValueFromNewProperty()
        {
            PropertyInfo         propertyInfo = typeof(DerivedTestDomainObject).GetProperty("Property3");
            ValueAccess          valueAccess  = new PropertyValueAccess(propertyInfo);
            BaseTestDomainObject domainObject = new DerivedTestDomainObject();

            object value;
            string valueAccessRetrievalFailure;
            bool   status = valueAccess.GetValue(domainObject, out value, out valueAccessRetrievalFailure);

            Assert.IsTrue(status);
            Assert.AreEqual(DerivedTestDomainObject.Derived3Value, value);
        }
        public void CanGetValueFromOverridenPropertyForInstanceOfDerivedClass()
        {
            PropertyInfo         propertyInfo = typeof(BaseTestDomainObject).GetProperty("Property2");
            ValueAccess          valueAccess  = new PropertyValueAccess(propertyInfo);
            BaseTestDomainObject domainObject = new DerivedTestDomainObject();

            object value;
            string valueAccessRetrievalFailure;
            bool   status = valueAccess.GetValue(domainObject, out value, out valueAccessRetrievalFailure);

            Assert.IsTrue(status);
            Assert.AreEqual(DerivedTestDomainObject.Derived2Value, value);
        }
Пример #11
0
        public void AddOutputValueElement_GetResult_templateModel_contains_PropertyTemplateElement()
        {
            var property = new PropertyValueAccess {
                Name = "Count"
            };

            _builder.AddOutputValue(property);

            TemplateModel templateModel = _builder.GetResult();

            TemplateElement[] elements = templateModel.Elements.ToArray();
            Assert.AreEqual(1, elements.Length);
            var element = (OutputValueTemplateElement)elements[0];

            Assert.AreEqual("Count", element.ValueAccess.Name);
        }
Пример #12
0
        public void GetValue_return_value()
        {
            var obj = new
            {
                Count = 10
            };

            var model = new Model(obj);

            var valueAccess = new PropertyValueAccess {
                Name = "Count"
            };

            object value = model.GetValue(valueAccess);

            Assert.AreEqual(10, value);
        }