根据.Net中的应用程序设置使用测试数据或实时数据?

时间:2011-03-28 15:28:03

标签: .net testing

我已经看到有人设置了两个应用程序设置;一个包含测试数据连接字符串,另一个包含实时数据连接字符串。它们使用相同的dbml,无论它们指向哪个实际数据库,然后无论何时设置数据上下文,它们只需指定它们想要使用的设置。 我想实现这一点,但想知道是否有任何好的博客文章或教程显示如何正确地执行此操作,或者是否有更“开箱即用”的替代方案。

2 个答案:

答案 0 :(得分:2)

Config transformations基于构建类型?

答案 1 :(得分:1)

以下是我使用的内容:

Friend Sub connect(ByVal isDebuggerAttached As Boolean)
    Dim server As String
    Dim dbName As String

    If isDebuggerAttached Then
       server = "DHSDEV10069\DSD"
    Else
       server = "dhs10073sql"
    End If

    dbName = "DSDWorkPlanTracking"

    _connect = "Data Source=" & server & ";Database=" & dbName & ";Integrated Security=true"
    _connect = _connect & ";Application Name = " & My.Application.Info.AssemblyName
End Sub

并在调用类中:

    Try
        Model.instance.connect(System.Diagnostics.Debugger.IsAttached)
    Catch ex As Exception
        MsgBox("Sorry, couldn't connect to database " & ex.Message)
    End Try

另外,对于帮助/关于:

Private Sub mnuHelpAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHelpAbout.Click
    Dim msg As String
    Dim appName As String

    If My.Application.Info.Title <> "" Then
        appName = My.Application.Info.Title
    Else
        appName = System.IO.Path.GetFileNameWithoutExtension(My.Application.Info.AssemblyName)
    End If
    msg = appName & vbCrLf & vbCrLf
    msg = msg & "Version: " & Application.ProductVersion & vbCrLf & vbCrLf  ' the file version displayed in .exe properties.  Assembly version is for internal builds and doesn't need to change for one developer.
    msg = msg & "User: " & My.User.Name & vbCrLf & vbCrLf
    msg = msg & "Connection: " & Model.instance.connection & vbCrLf & vbCrLf
    MsgBox(msg, MsgBoxStyle.OkOnly, appName)
End Sub