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)); }
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)); }
public void SetValue_ValueIsNotAppropriateType_ThrowsArgumentException() { var context = VgXmlPropertyContext.CreateContext(_stringElementProperty); var targetedContext = context.WithTarget(_testObj); Assert.That(() => targetedContext.SetValue(new { value = "NotStringValue" }), Throws.ArgumentException); }
public void IsCollection_PropertyIsCollection_ReturnTrue() { var property = typeof(TestClass).GetProperty(nameof(TestClass.CollectionElement)); var context = VgXmlPropertyContext.CreateContext(property); Assert.That(context.IsCollection(), Is.True); }
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); }
public void IsCollection_PropertyIsNotCollection_ReturnFalse() { var property = typeof(TestClass).GetProperty(nameof(TestClass.StaticRegexStringElement)); var context = VgXmlPropertyContext.CreateContext(property); Assert.That(context.IsCollection(), Is.False); }
public void GetContentFactory_ReturnsInstanceOfContentFactory() { var property = typeof(TestClass).GetProperty(nameof(TestClass.StaticRegexStringElement)); var context = VgXmlPropertyContext.CreateContext(property); Assert.That(context.GetContentFactory(), Is.Not.Null); }
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)); }
public bool NameMatches_NoNameDefined_ExpectsNameSameAsPropertyName(string name) { var property = typeof(TestClass).GetProperty(nameof(TestClass.StringAttribute)); var context = VgXmlPropertyContext.CreateContext(property); return(context.NameMatches(name)); }
public void AddToCollection_PropertyIsNotACollection_ThrowsInvalidOperationException() { var context = VgXmlPropertyContext.CreateContext(_stringElementProperty); var targetedContext = context.WithTarget(_testObj); Assert.That(() => targetedContext.AddToCollection("object"), Throws.InvalidOperationException); }
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); }
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)); }
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); }
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)); }
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))); }
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); }
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)); }
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); }
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))); }
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)); }
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)); }
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)); }
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>()); }
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)); }
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)); }