mardi 12 janvier 2016

Unit Test Methods Custom Config Section Reading using Config Classes

I'm trying to read a section of config files using custom config classes(inheriting them) in .net.

Now I have the following properties in FeatureCollection class

public class FeatureCollection : ConfigurationElementCollection
{
    internal const string PropertyName = "Feature";

    public override ConfigurationElementCollectionType CollectionType
    {
        get { return ConfigurationElementCollectionType.BasicMapAlternate; }
    }

    protected override string ElementName
    {
        get { return PropertyName; }
    }

    protected override bool IsElementName(string elementName)
    {
        return elementName.Equals(PropertyName, StringComparison.InvariantCultureIgnoreCase);
    }

    public override bool IsReadOnly()
    {
        return false;
    }

    protected override ConfigurationElement CreateNewElement()
    {
        return new Feature();
    }

    protected override object GetElementKey(ConfigurationElement element)
    {
        return ((Feature)(element)).Id;
    }

    public Feature this[int idx]
    {
        get { return (Feature)BaseGet(idx); }
    }
}

Below is the Feature Section in the app.config file.

<FeatureSection>
<Features>
  <Feature Id="CreateCatalogHeader" US="false"  EMEA="true" Order="1"></Feature>
  <Feature Id="CatalogCreation" US="false"  EMEA="true" Order="2"></Feature>
  <Feature Id="CatalogItemDetails" US="false"  EMEA="true" Order="3"></Feature>
  <Feature Id="ProcessDeltaCatalog" US="false"  EMEA="true" Order="4"></Feature>
  <Feature Id="SaveAutoCatalogDetails" US="false"  EMEA="true" Order="5"></Feature>
</Features>

please help me in writing the unit test method for the return type Feature property in FeatureCollection

Aucun commentaire:

Enregistrer un commentaire