Created
March 23, 2015 22:11
-
-
Save DominicFinn/b1103016ee5732841e1a to your computer and use it in GitHub Desktop.
VB.NET ShortCircuit Example
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 | |
Imports System.Runtime.CompilerServices | |
Module StringExtensions | |
<Extension()> | |
Public Function IsLongerThan10Characters(ByVal value As String) As Boolean | |
Return value IsNot Nothing AndAlso value.Length > 10 | |
End Function | |
End Module | |
<TestClass()> | |
Public Class GivenANullString | |
Dim _result As Boolean | |
<TestInitialize()> | |
Public Sub Setup() | |
Dim value As String = Nothing | |
Me._result = value.IsLongerThan10Characters() | |
End Sub | |
<TestMethod()> | |
Public Sub AndAlsoShouldShortCircuit() | |
Assert.IsFalse(Me._result) | |
End Sub | |
End Class | |
<TestClass()> | |
Public Class GivenAString | |
Dim _result As Boolean | |
<TestInitialize()> | |
Public Sub Setup() | |
Dim value As String = "Good Day Sir" | |
Me._result = value.IsLongerThan10Characters() | |
End Sub | |
<TestMethod()> | |
Public Sub AndAlsoShouldShortCircuit() | |
Assert.IsTrue(Me._result) | |
End Sub | |
End Class | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment