public void TestHighway() { Itinero.Osm.Vehicles.Vehicle.RegisterVehicles(); var tags = new AttributeCollection(); var profileTags = new AttributeCollection(); var metaTags = new AttributeCollection(); Assert.IsFalse(tags.Normalize(profileTags, metaTags, Itinero.Osm.Vehicles.Vehicle.GetAllRegistered())); tags.AddOrReplace(new Attribute("highway", "residential")); Assert.IsTrue(tags.Normalize(profileTags, metaTags, Itinero.Osm.Vehicles.Vehicle.GetAllRegistered())); Assert.IsTrue(profileTags.Contains("highway", "residential")); profileTags.Clear(); tags.Clear(); tags.AddOrReplace(new Attribute("highway", "footway")); Assert.IsTrue(tags.Normalize(profileTags, metaTags, Itinero.Osm.Vehicles.Vehicle.GetAllRegistered())); Assert.IsTrue(profileTags.Contains("highway", "footway")); profileTags.Clear(); tags.Clear(); tags.AddOrReplace(new Attribute("highway", "motorway")); Assert.IsTrue(tags.Normalize(profileTags, metaTags, Itinero.Osm.Vehicles.Vehicle.GetAllRegistered())); Assert.IsTrue(profileTags.Contains("highway", "motorway")); profileTags.Clear(); tags.Clear(); }
public void Contains_Attributes_ReturnsExpected() { Attribute[] attributes = GetAttributes().Take(5).ToArray(); var attributeCollection = new AttributeCollection(attributes); Assert.True(attributeCollection.Contains(attributes)); Assert.True(attributeCollection.Contains(new Attribute[0])); Assert.True(attributeCollection.Contains((Attribute[])null)); Assert.False(attributeCollection.Contains(new Attribute[] { new ReadOnlyAttribute(true) })); }
public void Contains_InvokeAttributeWithAttributes_ReturnsExpected() { var attribute1 = new BrowsableAttribute(true); var attribute2 = new ReadOnlyAttribute(true); var collection = new AttributeCollection(attribute1, attribute2); Assert.True(collection.Contains(attribute1)); Assert.False(collection.Contains(new BrowsableAttribute(false))); Assert.True(collection.Contains(attribute2)); Assert.False(collection.Contains(new EditorBrowsableAttribute())); Assert.False(collection.Contains((Attribute)null)); }
public void TestLoadFromOneConnection() { var transitDb = new TransitDb(); var feed = DummyGTFSFeedBuilder.OneConnection( TimeOfDay.FromTotalSeconds(0), TimeOfDay.FromTotalSeconds(3600)); transitDb.LoadFrom(feed); Assert.AreEqual(1, transitDb.TripsCount); var tripEnumerator = transitDb.GetTripsEnumerator(); Assert.IsTrue(tripEnumerator.MoveTo(0)); Assert.AreEqual(0, tripEnumerator.Id); Assert.AreEqual(0, tripEnumerator.ScheduleId); var tripMeta = new AttributeCollection(transitDb.TripAttributes.Get(tripEnumerator.MetaId)); Assert.IsTrue(tripMeta.Contains("id", "0")); Assert.IsTrue(tripMeta.Contains("route_id", "0")); Assert.IsTrue(tripMeta.Contains("service_id", "0")); var agencyMeta = new AttributeCollection(transitDb.AgencyAttributes.Get(tripEnumerator.AgencyId)); Assert.IsTrue(agencyMeta.Contains("id", "0")); Assert.AreEqual(2, transitDb.StopsCount); var stopEnumerator = transitDb.GetStopsEnumerator(); Assert.IsTrue(stopEnumerator.MoveTo(0)); Assert.AreEqual(0, stopEnumerator.Id); Assert.AreEqual(0, stopEnumerator.Latitude); Assert.AreEqual(0, stopEnumerator.Longitude); var stopMeta = new AttributeCollection(transitDb.StopAttributes.Get(stopEnumerator.MetaId)); Assert.IsTrue(stopMeta.Contains("id", "0")); Assert.IsTrue(stopEnumerator.MoveTo(1)); Assert.AreEqual(1, stopEnumerator.Id); Assert.AreEqual(1, stopEnumerator.Latitude); Assert.AreEqual(1, stopEnumerator.Longitude); stopMeta = new AttributeCollection(transitDb.StopAttributes.Get(stopEnumerator.MetaId)); Assert.IsTrue(stopMeta.Contains("id", "1")); Assert.AreEqual(1, transitDb.ConnectionsCount); transitDb.SortConnections(DefaultSorting.DepartureTime, null); var connectionEnumerator = transitDb.GetConnectionsEnumerator(DefaultSorting.DepartureTime); Assert.IsTrue(connectionEnumerator.MoveTo(0)); Assert.AreEqual(0, connectionEnumerator.Id); Assert.AreEqual(0, connectionEnumerator.DepartureStop); Assert.AreEqual(0, connectionEnumerator.DepartureTime); Assert.AreEqual(1, connectionEnumerator.ArrivalStop); Assert.AreEqual(3600, connectionEnumerator.ArrivalTime); Assert.AreEqual(0, connectionEnumerator.TripId); }
public void TestBicycleRestrictions() { Itinero.Osm.Vehicles.Vehicle.RegisterVehicles(); var vehicles = new Itinero.Osm.Vehicles.Vehicle[] { Itinero.Osm.Vehicles.Vehicle.Bicycle }; var tags = new AttributeCollection(); var profileTags = new AttributeCollection(); var metaTags = new AttributeCollection(); tags.AddOrReplace(new Attribute("highway", "residential")); tags.AddOrReplace(new Attribute("bicycle", "yes")); Assert.IsTrue(tags.Normalize(profileTags, metaTags, vehicles)); Assert.IsTrue(profileTags.Contains("highway", "residential")); Assert.IsFalse(profileTags.Contains("bicycle", "yes")); profileTags.Clear(); tags.Clear(); tags.AddOrReplace(new Attribute("highway", "residential")); tags.AddOrReplace(new Attribute("bicycle", "no")); Assert.IsTrue(tags.Normalize(profileTags, metaTags, vehicles)); Assert.IsTrue(profileTags.Contains("highway", "residential")); Assert.IsTrue(profileTags.Contains("bicycle", "no")); profileTags.Clear(); tags.Clear(); tags.AddOrReplace(new Attribute("highway", "residential")); tags.AddOrReplace(new Attribute("bicycle", "mistake")); Assert.IsTrue(tags.Normalize(profileTags, metaTags, vehicles)); Assert.IsTrue(profileTags.Contains("highway", "residential")); Assert.IsFalse(profileTags.Contains("bicycle", "mistake")); profileTags.Clear(); tags.Clear(); tags.AddOrReplace(new Attribute("highway", "footway")); tags.AddOrReplace(new Attribute("bicycle", "no")); Assert.IsTrue(tags.Normalize(profileTags, metaTags, vehicles)); Assert.IsTrue(profileTags.Contains("highway", "footway")); Assert.IsFalse(profileTags.Contains("bicycle", "no")); profileTags.Clear(); tags.Clear(); vehicles = new Itinero.Osm.Vehicles.Vehicle[] { Itinero.Osm.Vehicles.Vehicle.Car }; tags.AddOrReplace("highway", "residential"); tags.AddOrReplace("bicycle", "no"); Assert.IsTrue(tags.Normalize(profileTags, metaTags, vehicles)); Assert.IsTrue(profileTags.Contains("highway", "residential")); Assert.IsFalse(profileTags.Contains("bicycle", "no")); profileTags.Clear(); tags.Clear(); }
public static T GetAliasedValue <T>(this AttributeCollection properties, string aliasedEntityName, string attributeName) { const string aliasedTemplate = "{0}.{1}"; if (string.IsNullOrEmpty(aliasedEntityName)) { throw new ArgumentNullException(nameof(aliasedEntityName)); } if (string.IsNullOrEmpty(attributeName)) { throw new ArgumentNullException(nameof(attributeName)); } var aliasedAttrName = string.Format(aliasedTemplate, aliasedEntityName, attributeName); if (!properties.Contains(aliasedAttrName)) { return(default(T)); } var value = properties[aliasedAttrName]; //Если значение аттрибута нулевое или не типа AliasedValue - дефолтное значение if (!(value is AliasedValue)) { return(default(T)); } var aliasedValue = ((AliasedValue)value).Value; return((T)aliasedValue); }
public void TestRamp() { Itinero.Osm.Vehicles.Vehicle.RegisterVehicles(); var tags = new AttributeCollection(); var profileTags = new AttributeCollection(); var metaTags = new AttributeCollection(); tags.AddOrReplace("highway", "steps"); tags.AddOrReplace("ramp", "yes"); Assert.IsTrue(tags.Normalize(profileTags, metaTags, Itinero.Osm.Vehicles.Vehicle.GetAllRegistered())); Assert.IsTrue(profileTags.Contains("highway", "steps")); Assert.IsTrue(profileTags.Contains("ramp", "yes")); profileTags.Clear(); tags.Clear(); }
private void CheckAndAddProperty(PSPropertyInfo propertyInfo, Attribute[] attributes, ref PropertyDescriptorCollection returnValue) { using (typeDescriptor.TraceScope("Checking property \"{0}\".", propertyInfo.Name)) { // WriteOnly properties are not returned in TypeDescriptor.GetProperties, so we do the same. if (!propertyInfo.IsGettable) { typeDescriptor.WriteLine("Property \"{0}\" is write-only so it has been skipped.", propertyInfo.Name); return; } AttributeCollection propertyAttributes = null; Type propertyType = typeof(object); if (attributes != null && attributes.Length != 0) { PSProperty property = propertyInfo as PSProperty; if (property != null) { DotNetAdapter.PropertyCacheEntry propertyEntry = property.adapterData as DotNetAdapter.PropertyCacheEntry; if (propertyEntry == null) { typeDescriptor.WriteLine("Skipping attribute check for property \"{0}\" because it is an adapted property (not a .NET property).", property.Name); } else if (property.isDeserialized) { // At the moment we are not serializing attributes, so we can skip // the attribute check if the property is deserialized. typeDescriptor.WriteLine("Skipping attribute check for property \"{0}\" because it has been deserialized.", property.Name); } else { propertyType = propertyEntry.propertyType; propertyAttributes = propertyEntry.Attributes; foreach (Attribute attribute in attributes) { if (!propertyAttributes.Contains(attribute)) { typeDescriptor.WriteLine("Property \"{0}\" does not contain attribute \"{1}\" so it has been skipped.", property.Name, attribute); return; } } } } } if (propertyAttributes == null) { propertyAttributes = new AttributeCollection(); } typeDescriptor.WriteLine("Adding property \"{0}\".", propertyInfo.Name); PSObjectPropertyDescriptor propertyDescriptor = new PSObjectPropertyDescriptor(propertyInfo.Name, propertyType, !propertyInfo.IsSettable, propertyAttributes); propertyDescriptor.SettingValueException += this.SettingValueException; propertyDescriptor.GettingValueException += this.GettingValueException; returnValue.Add(propertyDescriptor); } }
internal static object GetComparableAttribute(AttributeCollection attributes, string attributeName) { if (!attributes.Contains(attributeName)) { return(null); } var attribute = attributes[attributeName]; if (attribute == null) { return(null); } if (attribute is Money money) { return(money.Value); } if (attribute is EntityReference eRef) { return(eRef.Name); } if (attribute is OptionSetValue osv) { return(osv.Value); } return(attribute); }
public void ContainsShouldReturnFalse() { Element parent = new Element(); parent.SetName("prefix", "localname"); AttributeCollection target = new AttributeCollection(parent); Assert.IsFalse(target.Contains("test", true)); }
public void ContainsTest(int count) { var attributes = GetAttributes().Take(count).ToArray(); var attributeCollection = new AttributeCollection(attributes); foreach (Attribute attribute in attributes) { Assert.True(attributeCollection.Contains(attribute)); } }
public void Contains_AttributeExists_ReturnsExpected(int count) { Attribute[] attributes = GetAttributes().Take(count).ToArray(); var attributeCollection = new AttributeCollection(attributes); foreach (Attribute attribute in attributes) { Assert.True(attributeCollection.Contains(attribute)); } }
public void ContainsShouldReturnTrueNonCaseSensative() { Element parent = new Element(); parent.SetName("prefix", "localname"); AttributeCollection target = new AttributeCollection(parent); target.Add(new Attribute(null, "Test", "Value")); Assert.IsTrue(target.Contains("test", true)); }
public static void SetMoneyValue(this AttributeCollection properties, string name, decimal value) { if (properties.Contains(name)) { properties[name] = new Money(value); } else { properties.Add(name, new Money(value)); } }
public static int GetPicklistValue(this AttributeCollection properties, string name, int defaultValue) { if (!properties.Contains(name)) { return(defaultValue); } OptionSetValue property = properties[name] as OptionSetValue; return(property?.Value ?? defaultValue); }
public static void SetPicklistValue(this AttributeCollection properties, string name, int value) { if (properties.Contains(name)) { properties[name] = new OptionSetValue(value); } else { properties.Add(name, new OptionSetValue(value)); } }
public static void SetStringValue(this AttributeCollection properties, string name, string value) { if (properties.Contains(name)) { properties[name] = value; } else { properties.Add(name, value); } }
public static string GetStringValue(this AttributeCollection properties, string name) { if (!properties.Contains(name)) { return(null); } object property = properties[name]; return(property?.ToString()); }
public static void SetLookupValue(this AttributeCollection properties, string name, string type, Guid value) { if (properties.Contains(name)) { properties[name] = new EntityReference(type, value); } else { properties.Add(name, new EntityReference(type, value)); } }
public static int GetNumberValue(this AttributeCollection properties, string name) { if (!properties.Contains(name)) { return(0); } object property = properties[name]; return(property != null?Convert.ToInt32(property) : 0); }
public static bool GetBooleanValue(this AttributeCollection properties, string name) { if (!properties.Contains(name)) { return(false); } object property = properties[name]; return(property != null && Convert.ToBoolean(property)); }
public static decimal GetDecimalValue(this AttributeCollection properties, string name) { if (!properties.Contains(name)) { return(0); } object property = properties[name]; return(property != null?Convert.ToDecimal(property) : 0); }
public void AddAttribute() { var component = new DescriptorTestComponent(); var addedAttribute = new DescriptorTestAttribute("expected string"); TypeDescriptor.AddAttributes(component.GetType(), addedAttribute); AttributeCollection attributes = TypeDescriptor.GetAttributes(component); Assert.True(attributes.Contains(addedAttribute)); }
public static void SetNullValue(this AttributeCollection properties, string name) { if (properties.Contains(name)) { properties[name] = null; } else { properties.Add(name, null); } }
public static void SetLookupValue(this AttributeCollection properties, string name, EntityReference reference) { if (properties.Contains(name)) { properties[name] = reference; } else { properties.Add(name, reference); } }
private void CheckAndAddProperty(PSPropertyInfo propertyInfo, Attribute[] attributes, ref PropertyDescriptorCollection returnValue) { using (typeDescriptor.TraceScope("Checking property \"{0}\".", new object[] { propertyInfo.Name })) { if (!propertyInfo.IsGettable) { typeDescriptor.WriteLine("Property \"{0}\" is write-only so it has been skipped.", new object[] { propertyInfo.Name }); } else { AttributeCollection propertyAttributes = null; Type propertyType = typeof(object); if ((attributes != null) && (attributes.Length != 0)) { PSProperty property = propertyInfo as PSProperty; if (property != null) { DotNetAdapter.PropertyCacheEntry adapterData = property.adapterData as DotNetAdapter.PropertyCacheEntry; if (adapterData == null) { typeDescriptor.WriteLine("Skipping attribute check for property \"{0}\" because it is an adapted property (not a .NET property).", new object[] { property.Name }); } else if (property.isDeserialized) { typeDescriptor.WriteLine("Skipping attribute check for property \"{0}\" because it has been deserialized.", new object[] { property.Name }); } else { propertyType = adapterData.propertyType; propertyAttributes = adapterData.Attributes; foreach (Attribute attribute in attributes) { if (!propertyAttributes.Contains(attribute)) { typeDescriptor.WriteLine("Property \"{0}\" does not contain attribute \"{1}\" so it has been skipped.", new object[] { property.Name, attribute }); return; } } } } } if (propertyAttributes == null) { propertyAttributes = new AttributeCollection(new Attribute[0]); } typeDescriptor.WriteLine("Adding property \"{0}\".", new object[] { propertyInfo.Name }); PSObjectPropertyDescriptor descriptor = new PSObjectPropertyDescriptor(propertyInfo.Name, propertyType, !propertyInfo.IsSettable, propertyAttributes); descriptor.SettingValueException += this.SettingValueException; descriptor.GettingValueException += this.GettingValueException; returnValue.Add(descriptor); } } }
public static decimal GetMoneyValue(this AttributeCollection properties, string name) { if (!properties.Contains(name)) { return(0); } object property = properties[name]; Money num = property as Money; return(num != null?Convert.ToDecimal(num.Value) : 0); }
private void UpdateConverterAttribute(Type optionType) { TypeConverterAttribute converter = new TypeConverterAttribute(typeof(OptionsDefaultConverter)); CategoryAttribute category = new CategoryAttribute(optionType.ToString()); Attribute[] attributes = new Attribute[] { null, null }; AttributeCollection oldAttributes = TypeDescriptor.GetAttributes(optionType); if (!oldAttributes.Contains(converter)) { attributes[0] = converter; } if (!oldAttributes.Contains(category)) { attributes[1] = category; } if (attributes[0] != null) { TypeDescriptor.AddAttributes(optionType, attributes); } }
public static object GetValue(this AttributeCollection properties, string name) { if (!properties.Contains(name)) { return(null); } object crmValue = properties[name]; if (crmValue == null) { return(null); } Type fieldType = crmValue.GetType(); Type[] endTypes = { typeof(DateTime), typeof(int), typeof(double) }; EntityReference reference = crmValue as EntityReference; if (reference != null) { return(reference.Id); } if (fieldType == typeof(OptionSetValue)) { OptionSetValue field = (OptionSetValue)crmValue; return(field.Value); } if (fieldType == typeof(Money)) { Money field = (Money)crmValue; return(field.Value); } if (endTypes.Contains(fieldType)) { return(crmValue); } if (fieldType == typeof(AliasedValue)) { return(((AliasedValue)crmValue).Value); } return(crmValue); }
public static DateTime GetDateTimeValue(this AttributeCollection properties, string name) { if (!properties.Contains(name)) { return(DateTime.MinValue); } object property = properties[name]; if (property != null) { return(Convert.ToDateTime(property)); } return(DateTime.MinValue); }