Unit Testing Best Practice? / C# InternalsVisibleTo() attribute for VBNET 2.0 while testing?

女生的网名这么多〃 提交于 2019-12-23 12:32:07

问题


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?

EDIT Is this a good testing practice to proceed like I do?


回答1:


Yes, the InternalsVisibleTo attribute is available in vb.net and works on Friend types.



来源:https://stackoverflow.com/questions/2827051/unit-testing-best-practice-c-sharp-internalsvisibleto-attribute-for-vbnet-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!