public void EntityType_ReturnsEntityTypeDeclaredInPropertyDecoration(string propertyName, VgXmlEntityType expectedEntityType)
        {
            var property = typeof(TestClass).GetProperty(propertyName);
            var context  = VgXmlPropertyContext.CreateContext(property);

            Assert.That(context.EntityType, Is.EqualTo(expectedEntityType));
        }
Esempio n. 2
0
        public bool NameMatches_RegexName(string name)
        {
            var property = typeof(TestClass).GetProperty(nameof(TestClass.RegexStringElement));
            var context  = VgXmlPropertyContext.CreateContext(property);

            return(context.NameMatches(name));
        }
        public void Property_EqualsInputProperty()
        {
            var property = typeof(TestClass).GetProperty(nameof(TestClass.StaticRegexStringElement));
            var context  = VgXmlPropertyContext.CreateContext(property);

            Assert.That(context.Property, Is.EqualTo(property));
        }
Esempio n. 4
0
        public void SetValue_ValueIsNotAppropriateType_ThrowsArgumentException()
        {
            var context         = VgXmlPropertyContext.CreateContext(_stringElementProperty);
            var targetedContext = context.WithTarget(_testObj);

            Assert.That(() => targetedContext.SetValue(new { value = "NotStringValue" }), Throws.ArgumentException);
        }
Esempio n. 5
0
        public void IsCollection_PropertyIsCollection_ReturnTrue()
        {
            var property = typeof(TestClass).GetProperty(nameof(TestClass.CollectionElement));
            var context  = VgXmlPropertyContext.CreateContext(property);

            Assert.That(context.IsCollection(), Is.True);
        }
Esempio n. 6
0
        public void GetBestMatchingNameFor_RegexNameOption_PropertyNameDoesNotMatchPattern_ThrowsInvalidOperationsException()
        {
            var property = typeof(TestClass).GetProperty(nameof(TestClass.RegexStringElement));
            var context  = VgXmlPropertyContext.CreateContext(property);

            Assert.That(() => context.GetBestMatchingNameFor("string"), Throws.InvalidOperationException);
        }
Esempio n. 7
0
        public void IsCollection_PropertyIsNotCollection_ReturnFalse()
        {
            var property = typeof(TestClass).GetProperty(nameof(TestClass.StaticRegexStringElement));
            var context  = VgXmlPropertyContext.CreateContext(property);

            Assert.That(context.IsCollection(), Is.False);
        }
Esempio n. 8
0
        public void GetContentFactory_ReturnsInstanceOfContentFactory()
        {
            var property = typeof(TestClass).GetProperty(nameof(TestClass.StaticRegexStringElement));
            var context  = VgXmlPropertyContext.CreateContext(property);

            Assert.That(context.GetContentFactory(), Is.Not.Null);
        }
Esempio n. 9
0
        public void WithTarget_NotOfPropertyType_ThrowsArgumentException()
        {
            var property = typeof(TestClass).GetProperty(nameof(TestClass.StaticRegexStringElement));
            var context  = VgXmlPropertyContext.CreateContext(property);

            Assert.That(() => context.WithTarget("NotTestClassType"), Throws.ArgumentException);
        }
        public void PropertyType_ReturnsPropertyInfoPropertyType()
        {
            var property = typeof(TestClass).GetProperty(nameof(TestClass.StaticRegexStringElement));
            var context  = VgXmlPropertyContext.CreateContext(property);

            Assert.That(context.PropertyType, Is.EqualTo(property.PropertyType));
        }
Esempio n. 11
0
        public bool NameMatches_NoNameDefined_ExpectsNameSameAsPropertyName(string name)
        {
            var property = typeof(TestClass).GetProperty(nameof(TestClass.StringAttribute));
            var context  = VgXmlPropertyContext.CreateContext(property);

            return(context.NameMatches(name));
        }
Esempio n. 12
0
        public void AddToCollection_PropertyIsNotACollection_ThrowsInvalidOperationException()
        {
            var context         = VgXmlPropertyContext.CreateContext(_stringElementProperty);
            var targetedContext = context.WithTarget(_testObj);

            Assert.That(() => targetedContext.AddToCollection("object"), Throws.InvalidOperationException);
        }
Esempio n. 13
0
        public void WithTarget_OfPropertyType_ReturnsIVgXmlTargetedPropertyContext()
        {
            var property         = typeof(TestClass).GetProperty(nameof(TestClass.StaticRegexStringElement));
            var context          = VgXmlPropertyContext.CreateContext(property);
            var targettedContext = context.WithTarget(new TestClass());

            Assert.That(targettedContext, Is.Not.Null);
        }
Esempio n. 14
0
        public void GenerateName_StaticName_ReturnsFirstFoundStaticName()
        {
            var property = typeof(TestClass).GetProperty(nameof(TestClass.StaticStringElement));
            var context  = VgXmlPropertyContext.CreateContext(property);

            var result = context.GenerateName(null);

            Assert.That(result, Is.EqualTo(TestClass.StringElementName_Static));
        }
Esempio n. 15
0
        public void GetBestMatchingNameFor_IsNameContainer_NameOptionsDefined_ContainerValueDoesNotMatch_GetBestMatchingNameFor_RegexNameOption_PropertyNameDoesNotMatchPattern_ThrowsInvalidOperationsException()
        {
            var property = typeof(TestClass).GetProperty(nameof(TestClass.StaticRegexNameContainerElement));
            var context  = VgXmlPropertyContext.CreateContext(property);

            _testObj.StaticRegexNameContainerElement.TagName = "NonMatchingName";

            Assert.That(() => context.GetBestMatchingNameFor(_testObj.StaticRegexNameContainerElement), Throws.InvalidOperationException);
        }
Esempio n. 16
0
        public void GetBestMatchingNameFor_StaticNameOption_ReturnsFirstStaticName()
        {
            var property = typeof(TestClass).GetProperty(nameof(TestClass.StaticStringElement));
            var context  = VgXmlPropertyContext.CreateContext(property);

            var result = context.GetBestMatchingNameFor("string");

            Assert.That(result, Is.EqualTo(TestClass.StringElementName_Static));
        }
Esempio n. 17
0
        public void GenerateName_NoName_ReturnsPropertyName()
        {
            var property = typeof(TestClass).GetProperty(nameof(TestClass.StringAttribute));
            var context  = VgXmlPropertyContext.CreateContext(property);

            var result = context.GenerateName(null);

            Assert.That(result, Is.EqualTo(nameof(TestClass.StringAttribute)));
        }
Esempio n. 18
0
        public void GetOptions_NoNamesDefined_ReturnsEmpty()
        {
            var property = typeof(TestClass).GetProperty(nameof(TestClass.StringRawElement));
            var context  = VgXmlPropertyContext.CreateContext(property);

            var options = context.GetOptions().ToList();

            Assert.That(options, Is.Empty);
        }
Esempio n. 19
0
        public void GenerateName_RegexName_DoesNotReturnFirstFoundRegexName()
        {
            var property = typeof(TestClass).GetProperty(nameof(TestClass.RegexStringElement));
            var context  = VgXmlPropertyContext.CreateContext(property);

            var result = context.GenerateName(null);

            Assert.That(result, Is.Not.EqualTo(TestClass.StringElementName_Regex));
        }
Esempio n. 20
0
        public void AddToCollection_CollectionIsNull_InstantiateCollectionOnTarget()
        {
            var context         = VgXmlPropertyContext.CreateContext(_stringCollectionElementProperty);
            var targetedContext = context.WithTarget(_testObj);

            targetedContext.AddToCollection("string");

            Assert.That(_testObj.StringCollectionElement, Is.Not.Null);
        }
Esempio n. 21
0
        public void GetBestMatchingNameFor_NoNameOptions_ReturnsPropertyName()
        {
            var property = typeof(TestClass).GetProperty(nameof(TestClass.StringAttribute));
            var context  = VgXmlPropertyContext.CreateContext(property);

            var result = context.GetBestMatchingNameFor("string");

            Assert.That(result, Is.EqualTo(nameof(TestClass.StringAttribute)));
        }
Esempio n. 22
0
        public void GetValue_ReturnsTargetsValue()
        {
            var context         = VgXmlPropertyContext.CreateContext(_stringElementProperty);
            var targetedContext = context.WithTarget(_testObj);

            _testObj.StringElement = "StringValue";
            var result = targetedContext.GetValue();

            Assert.That(result, Is.EqualTo(_testObj.StringElement));
        }
Esempio n. 23
0
        public void SetValue_ValueIsAppropriateType_ValueIsSet()
        {
            var context         = VgXmlPropertyContext.CreateContext(_stringElementProperty);
            var targetedContext = context.WithTarget(_testObj);
            var newStringValue  = "NewStringValue";

            targetedContext.SetValue(newStringValue);

            Assert.That(_testObj.StringElement, Is.EqualTo(newStringValue));
        }
Esempio n. 24
0
        public void GetBestMatchingNameFor_IsNameContainer_NameOptionsDefined_ContainerValueIsValid_ReturnsContainerValue(string nameContainerValue)
        {
            var property = typeof(TestClass).GetProperty(nameof(TestClass.StaticRegexNameContainerElement));
            var context  = VgXmlPropertyContext.CreateContext(property);

            _testObj.StaticRegexNameContainerElement.TagName = nameContainerValue;

            var result = context.GetBestMatchingNameFor(_testObj.StaticRegexNameContainerElement);

            Assert.That(result, Is.EqualTo(nameContainerValue));
        }
Esempio n. 25
0
        public void GetOptionsT_ReturnsTypesDeclaredInGenericArgument()
        {
            var property = typeof(TestClass).GetProperty(nameof(TestClass.StaticRegexStringElement));
            var context  = VgXmlPropertyContext.CreateContext(property);

            //out of the 2 options posted on StringElement; only the StaticName is a generator
            var options = context.GetOptions <IVgXmlNameGenerator>().ToList();

            Assert.That(options, Has.Count.EqualTo(1));
            Assert.That(options, Has.One.InstanceOf <IVgXmlNameGenerator>());
        }
Esempio n. 26
0
        public void GetOptions_ManyOptions_ReturnsDefinedOptions()
        {
            var property = typeof(TestClass).GetProperty(nameof(TestClass.StaticRegexStringElement));
            var context  = VgXmlPropertyContext.CreateContext(property);

            var options = context.GetOptions().ToList();

            Assert.That(options, Has.Count.EqualTo(2));
            Assert.That(options, Has.One.InstanceOf(typeof(VgXmlStaticNameAttribute)).With.
                        Property(nameof(VgXmlStaticNameAttribute.Name)).EqualTo(TestClass.StringElementName_Static));

            Assert.That(options, Has.One.InstanceOf(typeof(VgXmlRegexNameAttribute)).With.
                        Property(nameof(VgXmlRegexNameAttribute.Pattern)).EqualTo(TestClass.StringElementName_Regex));
        }
Esempio n. 27
0
        public void AddToCollection_ValueIsAddedToCollection()
        {
            var context         = VgXmlPropertyContext.CreateContext(_stringCollectionElementProperty);
            var targetedContext = context.WithTarget(_testObj);

            _testObj.StringCollectionElement = new List <string>();
            var value1 = "stringValue1";
            var value2 = "stringValue1";
            var value3 = "stringValue1";

            targetedContext.AddToCollection(value1);
            targetedContext.AddToCollection(value2);
            targetedContext.AddToCollection(value3);

            Assert.That(_testObj.StringCollectionElement, Has.Count.EqualTo(3));
            Assert.That(_testObj.StringCollectionElement, Has.Member(value1));
            Assert.That(_testObj.StringCollectionElement, Has.Member(value2));
            Assert.That(_testObj.StringCollectionElement, Has.Member(value3));
        }