我有一个 VS2012 Visual Basic.NET 应用程序,我想为这个应用程序创建一些单元测试。
在我的应用程序中,我有一个包含以下结构的模块:
<Serializable()> Public Structure MediaItem
Dim longMediaID As Long
Dim MediaObject As WMPLib.IWMPMedia
Dim FileInfoObject As FileInfo
Dim stringGenre As String
Dim stringMediaDuration As String
Dim doubleMediaLength As Double
End Structure
如何“导入”上述 MediaItem 结构,以便可以使用此结构进行一些单元测试?目前,TestClass 不能“看到”这个结构。
更新
这个结构是我自己定制的。它实际上不在一个类中,它在一个模块中。
更新 2
这是模块代码:
Imports System.IO
Namespace modCanMediaStructures
Module modCanMediaStructures
<Serializable()> Public Structure MediaItem
Dim longMediaID As Long
Dim MediaObject As WMPLib.IWMPMedia
Dim FileInfoObject As FileInfo
Dim stringGenre As String
Dim stringMediaDuration As String
Dim doubleMediaLength As Double
End Structure
<Serializable()> Public Structure MediaPlayList
Dim stringMediaPlayListName As String
Dim stringMediaPlayListDescription As String
Dim stringMediaPlayListComments As String
Dim mediaItemList As List(Of MediaItem)
Dim stringPlayListDuration As String
Dim doublePlayListDuration As Double
Dim booleanShuffle As Boolean
Dim booleanLoop As Boolean
End Structure
Public Structure genreItem
Dim stringGenreName As String
Dim longGenreCount As Long
Dim doubleGenreDuration As Double
End Structure
<Serializable()> Public Structure ScheduleItem
Dim stringItemName As String
Dim stringItemPlaylist As String
Dim stringItemDuration As String
Dim stringItemComments As String
Dim doubleItemDuration As Double
Dim booleanStartDateIsDerivedFromEndOfOtherScheduleItem As Boolean
Dim stringScheduleItemThatStartDateIsDerivedFrom As String
Dim dateItemStartDateTime As Date
Dim dateItemEndDateTime As Date
Dim booleanEndDateIsDerivedFromPlayListDuration As Boolean
End Structure
End Module
End Namespace
在我的主要形式中,我声明了一个变量,如下所示:
Dim testMediaItem As modCanMediaStructures.MediaItem
导入以下语句后:
Imports modCanMediaStructures
这行得通。但是,当我在 UnitTest 测试中执行相同的语句时,会出现以下错误:
未定义类型“modCanMediaStructures.MediaItem”
这是我的代码:
Imports System.Text
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports CanMediaPlayer
Imports modCanMediaStructures
<TestClass()> Public Class MediaListTests
<TestMethod()> Public Sub TestaddMediaItemToList()
Dim myStructure As New modCanMediaStructures.MediaItem
End Sub
End Class
我相信这是因为 UnitTest 项目实际上无法“看到”其他解决方案文件中的代码。
我可以帮忙吗?