Unit testing using InternalsVisibleToAttribute requires compilation with / out: filename.ext?

In my last question: Best practice for testing modules? / C # InternalsVisibleTo () for VBNET 2.0 during testing? I asked about InternalsVisibleToAttribute.

I read the documentation on how to use it, and everything is fine and understandable. However, I cannot create an instance of the Groupe class from my testing project.

I want to be able to instantiate my inner class in my wrapper assembly, from my test assembly.

Any help is appreciated!

EDIT NO. 1

Here is the compile-time error that I get when I try to create an instance of my type:

Erreur 2 'Carra.Exemples.Blocs.ActiveDirectory.Groupe' n'est pas available for use with the conveyor, car il est 'Private'. C: \ Open \ Projects \ Exemples \ Src \ Carra.Exemples.Blocs.ActiveDirectory \ Carra.Exemples.Blocs.ActiveDirectory.Tests \ GroupeTests.vb 9 18 Carra.Exemples.Blocs.ActiveDirectory.Tests

(This suggests that my type is not available in this context because it is private.) But he is Friend (inner)!

EDIT No. 2

Here is the code snippet proposed for the Groupe class that implements the Public Interface IGroupe:

#Region "Importations"
Imports System.DirectoryServices
Imports System.Runtime.CompilerServices
#End Region

<Assembly: InternalsVisibleTo("Carra.Exemples.Blocs.ActiveDirectory.Tests")> 

Friend Class Groupe
    Implements IGroupe

#Region "Membres privΓ©s"
    Private _classe As String = "group"
    Private _domaine As String
    Private _membres As CustomSet(Of IUtilisateur)
    Private _groupeNatif As DirectoryEntry
#End Region

#Region "Constructeurs"
    Friend Sub New()
        _membres = New CustomSet(Of IUtilisateur)()
        _groupeNatif = New DirectoryEntry()
    End Sub

    Friend Sub New(ByVal domaine As String)
        If (String.IsNullOrEmpty(domaine)) Then Throw New ArgumentNullException()
        _domaine = domaine
        _membres = New CustomSet(Of IUtilisateur)()
        _groupeNatif = New DirectoryEntry(domaine)
    End Sub

    Friend Sub New(ByVal groupeNatif As DirectoryEntry)
        _groupeNatif = groupeNatif
        _domaine = _groupeNatif.Path
        _membres = New CustomSet(Of IUtilisateur)()
    End Sub
#End Region

And the code is trying to use it:

#Region "Importations"
Imports NUnit.Framework

Imports Carra.Exemples.Blocs.ActiveDirectory
#End Region

<TestFixture()> _
Public Class GroupeTests
    <Test()> _
    Public Sub CreerDefaut()
        Dim g As Groupe = New Groupe()
        Assert.IsNotNull(g)
        Assert.IsInstanceOf(Groupe, g)
    End Sub
End Class

EDIT No. 3

Heck! I just noticed that I did not import the assembly in my import region.

No, nothing decided = (

Thank!

+3
3

, , ? Researchain , , , "InternalsVisibleTo" VB.NET, , .NET 2.0. :

InternalsVisibleTo: .Net 2.0

:

.NET Framework 2.0 Visual Basic .

, ! =)

+3

. InternalsVisibleTo - .

, ?

EDIT: Friend/internal? - . , , .

:

  • InternalsVisibleTo ? , InternalsVisibleTo ?
  • Groupe ? .

, , , , - Friend ( InternalsVisibleTo) , .

+3

- Carra.Exemples.Blocs.ActiveDirectory.Tests?

you imported Carra.Exemples.Blocs.ActiveDirectory.Tests, but surely you should just import Carra.Exemples.Blocs.ActiveDirectory? What is the assembly that your class calls? Something fish seems to be happening.

0
source

Source: https://habr.com/ru/post/1745284/


All Articles