C# InternalsVisibleTo() attribute for VBNET 2.0 while testing?

Posted by Will Marcouiller on Stack Overflow See other posts from Stack Overflow or by Will Marcouiller
Published on 2010-05-13T13:18:14Z Indexed on 2010/05/13 13:24 UTC
Read the original article Hit count: 129

Filed under:
|
|
|
|

I'm building an Active Directory wrapper in VBNET 2.0 (can't use later .NET) in which I have the following:

  1. IUtilisateur
  2. IGroupe
  3. IUniteOrganisation

These interfaces are implemented in internal classes (Friend in VBNET), so that I want to implement a façade in order to instiate each of the interfaces with their internal classes. This will allow the architecture a better flexibility, etc.

Now, I want to test these classes (Utilisateur, Groupe, UniteOrganisation) in a different project within the same solution. However, these classes are internal. I would like to be able to instantiate them without going through my façade, but only for these tests, nothing more.

Here's a piece of code to illustrate it:

public static class DirectoryFacade {
    public static IGroupe CreerGroupe() {
        return new Groupe();
    }
}

// Then in code, I would write something alike:

public partial class MainForm : Form {
    public MainForm() {
        IGroupe g = DirectoryFacade.CreerGroupe();
        // Doing stuff with instance here...
    }
}

// My sample interface:

public interface IGroupe {
    string Domaine { get; set; }
    IList<IUtilisateur> Membres { get; }
}

internal class Groupe : IGroupe {
    private IList<IUtilisateur> _membres;

    internal Groupe() {
        _membres = new List<IUtilisateur>();
    }

    public string Domaine { get; set; }
    public IList<IUtilisateur> Membres {
        get {
            return _membres;
        }
    }
}

I heard of InternalsVisibleTo() attribute, recently. I was wondering whether it is available in VBNET 2.0/VS2005 so that I could access the assmebly's internal classes for my tests? Otherwise, how could I achieve this?

© Stack Overflow or respective owner

Related posts about internals

Related posts about vb.net