September 30, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Unit Testing with Service Stubs or Mock Types

  • May 19, 2008
  • By Paul Kimmel
  • Send Email »
  • More Articles »

Listing 2: Defines the ServiceContract, the custom DataContext (for LINQ to SQL), and the table-mapped ORM (the Customer class).

Imports System.Data.Linq
Imports System.Data.Linq.Mapping

<ServiceContract()> _
Public Interface IService1

   <OperationContract()> _
   Function GetCustomer(ByVal CustomerID As String) As Customer

End Interface

Public Class Northwind
   Inherits DataContext

   Private Shared ReadOnly connectionString As String

   Public Sub New()
      MyBase.New(connectionString)
   End Sub

   Public ReadOnly Property Customers() As List(Of Customer)
      Get
         Return Me.GetTable(Of Customer)().ToList()
      End Get
   End Property

End Class

<DataContract()> _
<Table(Name:="Customers")> _
Public Class Customer

   Private _customerID As String
   <DataMember()> _
   <Column(IsPrimaryKey:=True)> _
   Public Property CustomerID() As String
      Get
         Return _customerID
      End Get
      Set(ByVal Value As String)
         _customerID = Value
      End Set
   End Property

   Private _companyName As String
   <DataMember()> _
   <Column()> _
   Public Property CompanyName() As String
      Get
         Return _companyName
      End Get
      Set(ByVal Value As String)
         _companyName = Value
      End Set
   End Property

   Private _contactName As String
   <DataMember()> _
   <Column()> _
   Public Property ContactName() As String
      Get
         Return _contactName
      End Get
      Set(ByVal Value As String)
         _contactName = Value
      End Set
   End Property

   Private _contactTitle As String
   <DataMember()> _
   <Column()> _
   Public Property ContactTitle() As String
      Get
         Return _contactTitle
      End Get
      Set(ByVal Value As String)
         _contactTitle = Value
      End Set
   End Property

   Private _address As String
   <DataMember()> _
   <Column()> _
   Public Property Address() As String
      Get
         Return _address
      End Get
      Set(ByVal Value As String)
         _address = Value
      End Set
   End Property

   Private _city As String
   <DataMember()> _
   <Column()> _
   Public Property City() As String
      Get
         Return _city
      End Get
      Set(ByVal Value As String)
         _city = Value
      End Set
   End Property

   Private _region As String
   <DataMember()> _
   <Column()> _
   Public Property Region() As String
      Get
         Return _region
      End Get
      Set(ByVal Value As String)
         _region = Value
      End Set
   End Property

   Private _postalCode As String
   <DataMember()> _
   <Column()> _
   Public Property PostalCode() As String
      Get
         Return _postalCode
      End Get
      Set(ByVal Value As String)
         _postalCode = Value
      End Set
   End Property

   Private _country As String
   <DataMember()> _
   <Column()> _
   Public Property Country() As String
      Get
         Return _country
      End Get
      Set(ByVal Value As String)
         _country = Value
      End Set
   EndProperty

   Private _phone As String
   <DataMember()> _
   <Column()> _
   Public Property Phone() As String
      Get
         Return _phone
      End Get
      Set(ByVal Value As String)
         _phone = Value
      End Set
   End Property

   Private _fax As String
   <DataMember()> _
   <Column()> _
   Public Property Fax() As String
      Get
         Return _fax
      End Get
      Set(ByVal Value As String)
         _fax = Value
      End Set
   End Property

End Class




Page 2 of 4



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel