Created
March 23, 2015 23:26
-
-
Save DominicFinn/d75a9fba12f2fa83219d to your computer and use it in GitHub Desktop.
Testing the concept of anonymous types in Visual Basic .NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System.Text | |
Imports Microsoft.VisualStudio.TestTools.UnitTesting | |
Public Class Dog | |
Public Property Id As Integer | |
Public Property Name As String | |
Public Property Age As Integer | |
End Class | |
<TestClass()> | |
Public Class GivenAListOfDogs | |
Private _dogs As IList(Of Dog) | |
<TestInitialize()> | |
Public Sub Setup() | |
Me._dogs = New List(Of Dog) | |
Me._dogs.Add(New Dog() With {.Id = 1, .Name = "Bob", .Age = 12}) | |
Me._dogs.Add(New Dog() With {.Id = 2, .Name = "Bill", .Age = 2}) | |
Me._dogs.Add(New Dog() With {.Id = 3, .Name = "Brady", .Age = 5}) | |
End Sub | |
<TestMethod()> | |
Public Sub TheyCanBeSelectedIntoACollectionOfAnonymousObjects() | |
Dim dogs = _dogs.Select(Function(d) New With {.Name = d.Name}) | |
Dim bob = dogs.First() | |
Assert.AreEqual(bob.Name, "Bob") | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment