Initial commit of VB samples from NUnit project

This commit is contained in:
Charlie Poole 2012-11-01 12:23:54 -07:00
Родитель bd9d519628
Коммит 5e09824ff2
14 изменённых файлов: 1613 добавлений и 1 удалений

8
.gitignore поставляемый
Просмотреть файл

@ -5,7 +5,13 @@ obj/
#User Specific Files
*.user
*.suo
*.pidb
*.userprefs
#Resource Caches
_ReSharper.*
*.sln.cache
*.sln.cache
#Editor backup files
*~

32
money/AssemblyInfo.vb Executable file
Просмотреть файл

@ -0,0 +1,32 @@
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices
' General Information about an assembly is controlled through the following
' set of attributes. Change these attribute values to modify the information
' associated with an assembly.
' Review the values of the assembly attributes
<Assembly: AssemblyTitle("")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("")>
<Assembly: AssemblyCopyright("")>
<Assembly: AssemblyTrademark("")>
<Assembly: CLSCompliant(True)>
'The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid("F21BB3B6-0C5E-4AE5-ABC7-4D25FC3F98DB")>
' Version information for an assembly consists of the following four values:
'
' Major Version
' Minor Version
' Build Number
' Revision
'
' You can specify all the values or you can default the Build and Revision Numbers
' by using the '*' as shown below:
<Assembly: AssemblyVersion("1.0.*")>

37
money/IMoney.vb Executable file
Просмотреть файл

@ -0,0 +1,37 @@
' ****************************************************************
' This is free software licensed under the NUnit license. You
' may obtain a copy of the license as well as information regarding
' copyright ownership at http://nunit.org
' ****************************************************************
Namespace NUnit.Samples
'The common interface for simple Monies and MoneyBags.
Public Interface IMoney
'Adds a money to this money
Function Add(ByVal m As IMoney) As IMoney
'Adds a simple Money to this money. This is a helper method for
'implementing double dispatch.
Function AddMoney(ByVal m As Money) As IMoney
'Adds a MoneyBag to this money. This is a helper method for
'implementing double dispatch.
Function AddMoneyBag(ByVal s As MoneyBag) As IMoney
'True if this money is zero.
ReadOnly Property IsZero() As Boolean
'Multiplies a money by the given factor.
Function Multiply(ByVal factor As Int32) As IMoney
'Negates this money.
Function Negate() As IMoney
'Subtracts a money from this money.
Function Subtract(ByVal m As IMoney) As IMoney
End Interface
End Namespace

109
money/Money.vb Executable file
Просмотреть файл

@ -0,0 +1,109 @@
' ****************************************************************
' This is free software licensed under the NUnit license. You
' may obtain a copy of the license as well as information regarding
' copyright ownership at http://nunit.org
' ****************************************************************
Option Explicit On
Namespace NUnit.Samples
' A Simple Money.
Public Class Money
Implements IMoney
Private fAmount As Int32
Private fCurrency As String
' Constructs a money from a given amount and currency.
Public Sub New(ByVal amount As Int32, ByVal currency As String)
Me.fAmount = amount
Me.fCurrency = currency
End Sub
' Adds a money to this money. Forwards the request
' to the AddMoney helper.
Public Overloads Function Add(ByVal m As IMoney) As IMoney Implements IMoney.Add
Return m.AddMoney(Me)
End Function
Public Overloads Function AddMoney(ByVal m As Money) As IMoney Implements IMoney.AddMoney
If m.Currency.Equals(Currency) Then
Return New Money(Amount + m.Amount, Currency)
End If
Return New MoneyBag(Me, m)
End Function
Public Function AddMoneyBag(ByVal s As MoneyBag) As IMoney Implements IMoney.AddMoneyBag
Return s.AddMoney(Me)
End Function
Public ReadOnly Property Amount() As Integer
Get
Return fAmount
End Get
End Property
Public ReadOnly Property Currency() As String
Get
Return fCurrency
End Get
End Property
Public Overloads Overrides Function Equals(ByVal anObject As Object) As Boolean
If IsZero And TypeOf anObject Is IMoney Then
Dim aMoney As IMoney = anObject
Return aMoney.IsZero
End If
If TypeOf anObject Is Money Then
Dim aMoney As Money = anObject
If (IsZero) Then
Return aMoney.IsZero
End If
Return Currency.Equals(aMoney.Currency) And Amount.Equals(aMoney.Amount)
End If
Return False
End Function
Public Overrides Function GetHashCode() As Int32
Return fCurrency.GetHashCode() + fAmount
End Function
Public ReadOnly Property IsZero() As Boolean Implements IMoney.IsZero
Get
Return Amount.Equals(0)
End Get
End Property
Public Function Multiply(ByVal factor As Integer) As IMoney Implements IMoney.Multiply
Return New Money(Amount * factor, Currency)
End Function
Public Function Negate() As IMoney Implements IMoney.Negate
Return New Money(-Amount, Currency)
End Function
Public Function Subtract(ByVal m As IMoney) As IMoney Implements IMoney.Subtract
Return Add(m.Negate())
End Function
Public Overrides Function ToString() As String
Return String.Format("[{0} {1}]", Amount, Currency)
End Function
End Class
End Namespace

164
money/MoneyBag.vb Executable file
Просмотреть файл

@ -0,0 +1,164 @@
' ****************************************************************
' This is free software licensed under the NUnit license. You
' may obtain a copy of the license as well as information regarding
' copyright ownership at http://nunit.org
' ****************************************************************
Option Explicit On
Namespace NUnit.Samples
Public Class MoneyBag
Implements IMoney
Private fmonies As ArrayList = New ArrayList(5)
Private Sub New()
End Sub
Public Sub New(ByVal bag As Money())
For Each m As Money In bag
If Not m.IsZero Then
AppendMoney(m)
End If
Next
End Sub
Public Sub New(ByVal m1 As Money, ByVal m2 As Money)
AppendMoney(m1)
AppendMoney(m2)
End Sub
Public Sub New(ByVal m As Money, ByVal bag As MoneyBag)
AppendMoney(m)
AppendBag(bag)
End Sub
Public Sub New(ByVal m1 As MoneyBag, ByVal m2 As MoneyBag)
AppendBag(m1)
AppendBag(m2)
End Sub
Public Function Add(ByVal m As IMoney) As IMoney Implements IMoney.Add
Return m.AddMoneyBag(Me)
End Function
Public Function AddMoney(ByVal m As Money) As IMoney Implements IMoney.AddMoney
Return New MoneyBag(m, Me).Simplify
End Function
Public Function AddMoneyBag(ByVal s As MoneyBag) As IMoney Implements IMoney.AddMoneyBag
Return New MoneyBag(s, Me).Simplify()
End Function
Private Sub AppendBag(ByVal aBag As MoneyBag)
For Each m As Money In aBag.fmonies
AppendMoney(m)
Next
End Sub
Private Sub AppendMoney(ByVal aMoney As Money)
Dim old As Money = FindMoney(aMoney.Currency)
If old Is Nothing Then
fmonies.Add(aMoney)
Return
End If
fmonies.Remove(old)
Dim sum As IMoney = old.Add(aMoney)
If (sum.IsZero) Then
Return
End If
fmonies.Add(sum)
End Sub
Private Function Contains(ByVal aMoney As Money) As Boolean
Dim m As Money = FindMoney(aMoney.Currency)
Return m.Amount.Equals(aMoney.Amount)
End Function
Public Overloads Overrides Function Equals(ByVal anObject As Object) As Boolean
If IsZero Then
If TypeOf anObject Is IMoney Then
Dim aMoney As IMoney = anObject
Return aMoney.IsZero
End If
End If
If TypeOf anObject Is MoneyBag Then
Dim aMoneyBag As MoneyBag = anObject
If Not aMoneyBag.fmonies.Count.Equals(fmonies.Count) Then
Return False
End If
For Each m As Money In fmonies
If Not aMoneyBag.Contains(m) Then
Return False
End If
Return True
Next
End If
Return False
End Function
Private Function FindMoney(ByVal currency As String) As Money
For Each m As Money In fmonies
If m.Currency.Equals(currency) Then
Return m
End If
Next
Return Nothing
End Function
Public Overrides Function GetHashCode() As Int32
Dim hash As Int32 = 0
For Each m As Money In fmonies
hash += m.GetHashCode()
Next
Return hash
End Function
Public ReadOnly Property IsZero() As Boolean Implements IMoney.IsZero
Get
Return fmonies.Count.Equals(0)
End Get
End Property
Public Function Multiply(ByVal factor As Integer) As IMoney Implements IMoney.Multiply
Dim result As New MoneyBag
If Not factor.Equals(0) Then
For Each m As Money In fmonies
result.AppendMoney(m.Multiply(factor))
Next
End If
Return result
End Function
Public Function Negate() As IMoney Implements IMoney.Negate
Dim result As New MoneyBag
For Each m As Money In fmonies
result.AppendMoney(m.Negate())
Next
Return result
End Function
Private Function Simplify() As IMoney
If fmonies.Count.Equals(1) Then
Return fmonies(0)
End If
Return Me
End Function
Public Function Subtract(ByVal m As IMoney) As IMoney Implements IMoney.Subtract
Return Add(m.Negate())
End Function
End Class
End Namespace

216
money/MoneyTest.vb Executable file
Просмотреть файл

@ -0,0 +1,216 @@
' ****************************************************************
' This is free software licensed under the NUnit license. You
' may obtain a copy of the license as well as information regarding
' copyright ownership at http://nunit.org
' ****************************************************************
Option Explicit On
Imports System
Imports NUnit.Framework
Namespace NUnit.Samples
<TestFixture()> _
Public Class MoneyTest
Private f12CHF As Money
Private f14CHF As Money
Private f7USD As Money
Private f21USD As Money
Private fMB1 As MoneyBag
Private fMB2 As MoneyBag
<SetUp()> _
Protected Sub SetUp()
f12CHF = New Money(12, "CHF")
f14CHF = New Money(14, "CHF")
f7USD = New Money(7, "USD")
f21USD = New Money(21, "USD")
fMB1 = New MoneyBag(f12CHF, f7USD)
fMB2 = New MoneyBag(f14CHF, f21USD)
End Sub
<Test()> _
Public Sub BagMultiply()
' {[12 CHF][7 USD]} *2 == {[24 CHF][14 USD]}
Dim bag() As Money = New Money() {New Money(24, "CHF"), New Money(14, "USD")}
Dim expected As New MoneyBag(bag)
Assert.AreEqual(expected, fMB1.Multiply(2))
Assert.AreEqual(fMB1, fMB1.Multiply(1))
Assert.IsTrue(fMB1.Multiply(0).IsZero)
End Sub
<Test()> _
Public Sub BagNegate()
' {[12 CHF][7 USD]} negate == {[-12 CHF][-7 USD]}
Dim bag() As Money = New Money() {New Money(-12, "CHF"), New Money(-7, "USD")}
Dim expected As New MoneyBag(bag)
Assert.AreEqual(expected, fMB1.Negate())
End Sub
<Test()> _
Public Sub BagSimpleAdd()
' {[12 CHF][7 USD]} + [14 CHF] == {[26 CHF][7 USD]}
Dim bag() As Money = New Money() {New Money(26, "CHF"), New Money(7, "USD")}
Dim expected As New MoneyBag(bag)
Assert.AreEqual(expected, fMB1.Add(f14CHF))
End Sub
<Test()> _
Public Sub BagSubtract()
' {[12 CHF][7 USD]} - {[14 CHF][21 USD] == {[-2 CHF][-14 USD]}
Dim bag() As Money = New Money() {New Money(-2, "CHF"), New Money(-14, "USD")}
Dim expected As New MoneyBag(bag)
Assert.AreEqual(expected, fMB1.Subtract(fMB2))
End Sub
<Test()> _
Public Sub BagSumAdd()
' {[12 CHF][7 USD]} + {[14 CHF][21 USD]} == {[26 CHF][28 USD]}
Dim bag() As Money = New Money() {New Money(26, "CHF"), New Money(28, "USD")}
Dim expected As New MoneyBag(bag)
Assert.AreEqual(expected, fMB1.Add(fMB2))
End Sub
<Test()> _
Public Sub IsZero()
Assert.IsTrue(fMB1.Subtract(fMB1).IsZero)
Dim bag() As Money = New Money() {New Money(0, "CHF"), New Money(0, "USD")}
Assert.IsTrue(New MoneyBag(bag).IsZero)
End Sub
<Test()> _
Public Sub MixedSimpleAdd()
' [12 CHF] + [7 USD] == {[12 CHF][7 USD]}
Dim bag() As Money = New Money() {f12CHF, f7USD}
Dim expected As New MoneyBag(bag)
Assert.AreEqual(expected, f12CHF.Add(f7USD))
End Sub
<Test()> _
Public Sub MoneyBagEquals()
' NOTE: Normally we use Assert.AreEqual to test whether two
' objects are equal. But here we are testing the MoneyBag.Equals()
' method itself, so using AreEqual would not serve the purpose.
Assert.IsFalse(fMB1.Equals(Nothing))
Assert.IsTrue(fMB1.Equals(fMB1))
Dim equal As MoneyBag = New MoneyBag(New Money(12, "CHF"), New Money(7, "USD"))
Assert.IsTrue(fMB1.Equals(equal))
Assert.IsFalse(fMB1.Equals(f12CHF))
Assert.IsFalse(f12CHF.Equals(fMB1))
Assert.IsFalse(fMB1.Equals(fMB2))
End Sub
<Test()> _
Public Sub MoneyBagHash()
Dim equal As MoneyBag = New MoneyBag(New Money(12, "CHF"), New Money(7, "USD"))
Assert.AreEqual(fMB1.GetHashCode(), equal.GetHashCode())
End Sub
<Test()> _
Public Sub MoneyEquals()
' NOTE: Normally we use Assert.AreEqual to test whether two
' objects are equal. But here we are testing the MoneyBag.Equals()
' method itself, so using AreEqual would not serve the purpose.
Assert.IsFalse(f12CHF.Equals(Nothing))
Dim equalMoney As Money = New Money(12, "CHF")
Assert.IsTrue(f12CHF.Equals(f12CHF))
Assert.IsTrue(f12CHF.Equals(equalMoney))
Assert.IsFalse(f12CHF.Equals(f14CHF))
End Sub
<Test()> _
Public Sub MoneyHash()
Assert.IsFalse(f12CHF.Equals(Nothing))
Dim equal As Money = New Money(12, "CHF")
Assert.AreEqual(f12CHF.GetHashCode(), equal.GetHashCode())
End Sub
<Test()> _
Public Sub Normalize()
Dim bag() As Money = New Money() {New Money(26, "CHF"), New Money(28, "CHF"), New Money(6, "CHF")}
Dim moneyBag As New MoneyBag(bag)
Dim expected() As Money = New Money() {New Money(60, "CHF")}
' // note: expected is still a MoneyBag
Dim expectedBag As New MoneyBag(expected)
Assert.AreEqual(expectedBag, moneyBag)
End Sub
<Test()> _
Public Sub Normalize2()
' {[12 CHF][7 USD]} - [12 CHF] == [7 USD]
Dim expected As Money = New Money(7, "USD")
Assert.AreEqual(expected, fMB1.Subtract(f12CHF))
End Sub
<Test()> _
Public Sub Normalize3()
' {[12 CHF][7 USD]} - {[12 CHF][3 USD]} == [4 USD]
Dim s1() As Money = New Money() {New Money(12, "CHF"), New Money(3, "USD")}
Dim ms1 As New MoneyBag(s1)
Dim expected As New Money(4, "USD")
Assert.AreEqual(expected, fMB1.Subtract(ms1))
End Sub
<Test()> _
Public Sub Normalize4()
' [12 CHF] - {[12 CHF][3 USD]} == [-3 USD]
Dim s1() As Money = New Money() {New Money(12, "CHF"), New Money(3, "USD")}
Dim ms1 As New MoneyBag(s1)
Dim expected As New Money(-3, "USD")
Assert.AreEqual(expected, f12CHF.Subtract(ms1))
End Sub
<Test()> _
Public Sub Print()
Assert.AreEqual("[12 CHF]", f12CHF.ToString())
End Sub
<Test()> _
Public Sub SimpleAdd()
' [12 CHF] + [14 CHF] == [26 CHF]
Dim expected As Money = New Money(26, "CHF")
Assert.AreEqual(expected, f12CHF.Add(f14CHF))
End Sub
<Test()> _
Public Sub SimpleNegate()
' [14 CHF] negate == [-14 CHF]
Dim expected As New Money(-14, "CHF")
Assert.AreEqual(expected, f14CHF.Negate())
End Sub
<Test()> _
Public Sub SimpleSubtract()
' [14 CHF] - [12 CHF] == [2 CHF]
Dim expected As New Money(2, "CHF")
Assert.AreEqual(expected, f14CHF.Subtract(f12CHF))
End Sub
<Test()> _
Public Sub SimpleMultiply()
' [14 CHF] *2 == [28 CHF]
Dim expected As New Money(28, "CHF")
Assert.AreEqual(expected, f14CHF.Multiply(2))
End Sub
End Class
End Namespace

14
money/vb-money.build Executable file
Просмотреть файл

@ -0,0 +1,14 @@
<?xml version="1.0"?>
<project name="vb-money" default="build">
<include buildfile="../../samples.common" />
<patternset id="source-files">
<include name="AssemblyInfo.vb" />
<include name="IMoney.vb" />
<include name="Money.vb" />
<include name="MoneyBag.vb" />
<include name="MoneyTest.vb" />
</patternset>
</project>

20
money/vb-money.sln Normal file
Просмотреть файл

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "vb-money", "vb-money.vbproj", "{95394B96-A794-48EA-9879-0E4EC79C5724}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{95394B96-A794-48EA-9879-0E4EC79C5724}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95394B96-A794-48EA-9879-0E4EC79C5724}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95394B96-A794-48EA-9879-0E4EC79C5724}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95394B96-A794-48EA-9879-0E4EC79C5724}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = vb-money.vbproj
EndGlobalSection
EndGlobal

124
money/vb-money.vbproj Normal file
Просмотреть файл

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectType>Local</ProjectType>
<ProductVersion>7.10.3077</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{95394B96-A794-48EA-9879-0E4EC79C5724}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<AssemblyKeyContainerName />
<AssemblyName>vb-money</AssemblyName>
<AssemblyOriginatorKeyMode>None</AssemblyOriginatorKeyMode>
<DefaultClientScript>JScript</DefaultClientScript>
<DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
<DefaultTargetSchema>IE50</DefaultTargetSchema>
<DelaySign>false</DelaySign>
<OutputType>Library</OutputType>
<RootNamespace>Money</RootNamespace>
<FileUpgradeFlags>
</FileUpgradeFlags>
<MyType>Windows</MyType>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>0.0</OldToolsVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>bin\</OutputPath>
<DocumentationFile>vb-money.xml</DocumentationFile>
<BaseAddress>285212672</BaseAddress>
<ConfigurationOverrideFile />
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<DebugSymbols>true</DebugSymbols>
<RegisterForComInterop>false</RegisterForComInterop>
<NoWarn>42016,42017,42018,42019,42032,42353,42354,42355</NoWarn>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<AdditionalParameters />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>bin\</OutputPath>
<DocumentationFile>vb-money.xml</DocumentationFile>
<BaseAddress>285212672</BaseAddress>
<ConfigurationOverrideFile />
<DefineDebug>false</DefineDebug>
<DefineTrace>true</DefineTrace>
<Optimize>true</Optimize>
<RegisterForComInterop>false</RegisterForComInterop>
<NoWarn>42016,42017,42018,42019,42032,42353,42354,42355</NoWarn>
<DebugType>none</DebugType>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<AdditionalParameters />
</PropertyGroup>
<ItemGroup>
<Reference Include="System">
<Name>System</Name>
</Reference>
<Reference Include="nunit.framework">
<HintPath>..\..\..\nunit-2.6\work\bin\Debug\framework\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Import Include="Microsoft.VisualBasic" />
<Import Include="System" />
<Import Include="System.Collections" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.vb">
<SubType>Code</SubType>
</Compile>
<Compile Include="IMoney.vb">
<SubType>Code</SubType>
</Compile>
<Compile Include="Money.vb">
<SubType>Code</SubType>
</Compile>
<Compile Include="MoneyBag.vb">
<SubType>Code</SubType>
</Compile>
<Compile Include="MoneyTest.vb">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Folder Include="My Project\" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
<PropertyGroup>
<PreBuildEvent />
<PostBuildEvent />
</PropertyGroup>
</Project>

32
syntax/AssemblyInfo.vb Executable file
Просмотреть файл

@ -0,0 +1,32 @@
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices
' General Information about an assembly is controlled through the following
' set of attributes. Change these attribute values to modify the information
' associated with an assembly.
' Review the values of the assembly attributes
<Assembly: AssemblyTitle("")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("")>
<Assembly: AssemblyCopyright("")>
<Assembly: AssemblyTrademark("")>
<Assembly: CLSCompliant(True)>
'The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid("966C964A-3C92-4834-AC3A-9A47BA0A728B")>
' Version information for an assembly consists of the following four values:
'
' Major Version
' Minor Version
' Build Number
' Revision
'
' You can specify all the values or you can default the Build and Revision Numbers
' by using the '*' as shown below:
<Assembly: AssemblyVersion("1.0.*")>

703
syntax/AssertSyntaxTests.vb Executable file
Просмотреть файл

@ -0,0 +1,703 @@
' ****************************************************************
' Copyright 2007, Charlie Poole
' This is free software licensed under the NUnit license. You may
' obtain a copy of the license at http://nunit.org
' ****************************************************************
Option Explicit On
Imports System
Imports NUnit.Framework
Imports NUnit.Framework.Constraints
Namespace NUnit.Samples
' This test fixture attempts to exercise all the syntactic
' variations of Assert without getting into failures, errors
' or corner cases. Thus, some of the tests may be duplicated
' in other fixtures.
'
' Each test performs the same operations using the classic
' syntax (if available) and the new syntax in both the
' helper-based and inherited forms.
'
' This Fixture will eventually be duplicated in other
' supported languages.
<TestFixture()> _
Public Class AssertSyntaxTests
Inherits AssertionHelper
#Region "Simple Constraint Tests"
<Test()> _
Public Sub IsNull()
Dim nada As Object = Nothing
' Classic syntax
Assert.IsNull(nada)
' Helper syntax
Assert.That(nada, Iz.Null)
' Inherited syntax
Expect(nada, Null)
End Sub
<Test()> _
Public Sub IsNotNull()
' Classic syntax
Assert.IsNotNull(42)
' Helper syntax
Assert.That(42, Iz.Not.Null)
' Inherited syntax
Expect(42, Iz.Not.Null)
End Sub
<Test()> _
Public Sub IsTrue()
' Classic syntax
Assert.IsTrue(2 + 2 = 4)
' Helper syntax
Assert.That(2 + 2 = 4, Iz.True)
Assert.That(2 + 2 = 4)
' Inherited syntax
Expect(2 + 2 = 4, Iz.True)
Expect(2 + 2 = 4)
End Sub
<Test()> _
Public Sub IsFalse()
' Classic syntax
Assert.IsFalse(2 + 2 = 5)
' Helper syntax
Assert.That(2 + 2 = 5, Iz.False)
' Inherited syntax
Expect(2 + 2 = 5, Iz.False)
End Sub
<Test()> _
Public Sub IsNaN()
Dim d As Double = Double.NaN
Dim f As Single = Single.NaN
' Classic syntax
Assert.IsNaN(d)
Assert.IsNaN(f)
' Helper syntax
Assert.That(d, Iz.NaN)
Assert.That(f, Iz.NaN)
' Inherited syntax
Expect(d, NaN)
Expect(f, NaN)
End Sub
<Test()> _
Public Sub EmptyStringTests()
' Classic syntax
Assert.IsEmpty("")
Assert.IsNotEmpty("Hello!")
' Helper syntax
Assert.That("", Iz.Empty)
Assert.That("Hello!", Iz.Not.Empty)
' Inherited syntax
Expect("", Empty)
Expect("Hello!", Iz.Not.Empty)
End Sub
<Test()> _
Public Sub EmptyCollectionTests()
Dim boolArray As Boolean() = New Boolean() {}
Dim nonEmpty As Integer() = New Integer() {1, 2, 3}
' Classic syntax
Assert.IsEmpty(boolArray)
Assert.IsNotEmpty(nonEmpty)
' Helper syntax
Assert.That(boolArray, Iz.Empty)
Assert.That(nonEmpty, Iz.Not.Empty)
' Inherited syntax
Expect(boolArray, Iz.Empty)
Expect(nonEmpty, Iz.Not.Empty)
End Sub
#End Region
#Region "TypeConstraint Tests"
<Test()> _
Public Sub ExactTypeTests()
' Classic syntax workarounds
Assert.AreEqual(GetType(String), "Hello".GetType())
Assert.AreEqual("System.String", "Hello".GetType().FullName)
Assert.AreNotEqual(GetType(Integer), "Hello".GetType())
Assert.AreNotEqual("System.Int32", "Hello".GetType().FullName)
' Helper syntax
Assert.That("Hello", Iz.TypeOf(GetType(String)))
Assert.That("Hello", Iz.Not.TypeOf(GetType(Integer)))
' Inherited syntax
Expect("Hello", Iz.TypeOf(GetType(String)))
Expect("Hello", Iz.Not.TypeOf(GetType(Integer)))
End Sub
<Test()> _
Public Sub InstanceOfTests()
' Classic syntax
Assert.IsInstanceOf(GetType(String), "Hello")
Assert.IsNotInstanceOf(GetType(String), 5)
' Helper syntax
Assert.That("Hello", Iz.InstanceOf(GetType(String)))
Assert.That(5, Iz.Not.InstanceOf(GetType(String)))
' Inherited syntax
Expect("Hello", InstanceOf(GetType(String)))
Expect(5, Iz.Not.InstanceOf(GetType(String)))
End Sub
<Test()> _
Public Sub AssignableFromTypeTests()
' Classic syntax
Assert.IsAssignableFrom(GetType(String), "Hello")
Assert.IsNotAssignableFrom(GetType(String), 5)
' Helper syntax
Assert.That("Hello", Iz.AssignableFrom(GetType(String)))
Assert.That(5, Iz.Not.AssignableFrom(GetType(String)))
' Inherited syntax
Expect("Hello", AssignableFrom(GetType(String)))
Expect(5, Iz.Not.AssignableFrom(GetType(String)))
End Sub
#End Region
#Region "StringConstraintTests"
<Test()> _
Public Sub SubstringTests()
Dim phrase As String = "Hello World!"
Dim array As String() = New String() {"abc", "bad", "dba"}
' Classic Syntax
StringAssert.Contains("World", phrase)
' Helper syntax
Assert.That(phrase, Iz.StringContaining("World"))
' Only available using new syntax
Assert.That(phrase, Iz.Not.StringContaining("goodbye"))
Assert.That(phrase, Iz.StringContaining("WORLD").IgnoreCase)
Assert.That(phrase, Iz.Not.StringContaining("BYE").IgnoreCase)
Assert.That(array, Iz.All.StringContaining("b"))
' Inherited syntax
Expect(phrase, Contains("World"))
' Only available using new syntax
Expect(phrase, Iz.Not.Contains("goodbye"))
Expect(phrase, Contains("WORLD").IgnoreCase)
Expect(phrase, Iz.Not.Contains("BYE").IgnoreCase)
Expect(array, All.Contains("b"))
End Sub
<Test()> _
Public Sub StartsWithTests()
Dim phrase As String = "Hello World!"
Dim greetings As String() = New String() {"Hello!", "Hi!", "Hola!"}
' Classic syntax
StringAssert.StartsWith("Hello", phrase)
' Helper syntax
Assert.That(phrase, Iz.StringStarting("Hello"))
' Only available using new syntax
Assert.That(phrase, Iz.Not.StringStarting("Hi!"))
Assert.That(phrase, Iz.StringStarting("HeLLo").IgnoreCase)
Assert.That(phrase, Iz.Not.StringStarting("HI").IgnoreCase)
Assert.That(greetings, Iz.All.StringStarting("h").IgnoreCase)
' Inherited syntax
Expect(phrase, StartsWith("Hello"))
' Only available using new syntax
Expect(phrase, Iz.Not.StringStarting("Hi!"))
Expect(phrase, StartsWith("HeLLo").IgnoreCase)
Expect(phrase, Iz.Not.StringStarting("HI").IgnoreCase)
Expect(greetings, All.StartsWith("h").IgnoreCase)
End Sub
<Test()> _
Public Sub EndsWithTests()
Dim phrase As String = "Hello World!"
Dim greetings As String() = New String() {"Hello!", "Hi!", "Hola!"}
' Classic Syntax
StringAssert.EndsWith("!", phrase)
' Helper syntax
Assert.That(phrase, Iz.StringEnding("!"))
' Only available using new syntax
Assert.That(phrase, Iz.Not.StringEnding("?"))
Assert.That(phrase, Iz.StringEnding("WORLD!").IgnoreCase)
Assert.That(greetings, Iz.All.StringEnding("!"))
' Inherited syntax
Expect(phrase, EndsWith("!"))
' Only available using new syntax
Expect(phrase, Iz.Not.StringEnding("?"))
Expect(phrase, EndsWith("WORLD!").IgnoreCase)
Expect(greetings, All.EndsWith("!"))
End Sub
<Test()> _
Public Sub EqualIgnoringCaseTests()
Dim phrase As String = "Hello World!"
Dim array1 As String() = New String() {"Hello", "World"}
Dim array2 As String() = New String() {"HELLO", "WORLD"}
Dim array3 As String() = New String() {"HELLO", "Hello", "hello"}
' Classic syntax
StringAssert.AreEqualIgnoringCase("hello world!", phrase)
' Helper syntax
Assert.That(phrase, Iz.EqualTo("hello world!").IgnoreCase)
'Only available using new syntax
Assert.That(phrase, Iz.Not.EqualTo("goodbye world!").IgnoreCase)
Assert.That(array1, Iz.EqualTo(array2).IgnoreCase)
Assert.That(array3, Iz.All.EqualTo("hello").IgnoreCase)
' Inherited syntax
Expect(phrase, EqualTo("hello world!").IgnoreCase)
'Only available using new syntax
Expect(phrase, Iz.Not.EqualTo("goodbye world!").IgnoreCase)
Expect(array1, EqualTo(array2).IgnoreCase)
Expect(array3, All.EqualTo("hello").IgnoreCase)
End Sub
<Test()> _
Public Sub RegularExpressionTests()
Dim phrase As String = "Now is the time for all good men to come to the aid of their country."
Dim quotes As String() = New String() {"Never say never", "It's never too late", "Nevermore!"}
' Classic syntax
StringAssert.IsMatch("all good men", phrase)
StringAssert.IsMatch("Now.*come", phrase)
' Helper syntax
Assert.That(phrase, Iz.StringMatching("all good men"))
Assert.That(phrase, Iz.StringMatching("Now.*come"))
' Only available using new syntax
Assert.That(phrase, Iz.Not.StringMatching("all.*men.*good"))
Assert.That(quotes, Iz.All.StringMatching("never").IgnoreCase)
' Inherited syntax
Expect(phrase, Matches("all good men"))
Expect(phrase, Matches("Now.*come"))
' Only available using new syntax
Expect(phrase, Iz.Not.StringMatching("all.*men.*good"))
Expect(phrase, Matches("ALL").IgnoreCase)
Expect(quotes, All.Matches("never").IgnoreCase)
End Sub
#End Region
#Region "Equality Tests"
<Test()> _
Public Sub EqualityTests()
Dim i3 As Integer() = {1, 2, 3}
Dim d3 As Double() = {1.0, 2.0, 3.0}
Dim iunequal As Integer() = {1, 3, 2}
' Classic Syntax
Assert.AreEqual(4, 2 + 2)
Assert.AreEqual(i3, d3)
Assert.AreNotEqual(5, 2 + 2)
Assert.AreNotEqual(i3, iunequal)
' Helper syntax
Assert.That(2 + 2, Iz.EqualTo(4))
Assert.That(2 + 2 = 4)
Assert.That(i3, Iz.EqualTo(d3))
Assert.That(2 + 2, Iz.Not.EqualTo(5))
Assert.That(i3, Iz.Not.EqualTo(iunequal))
' Inherited syntax
Expect(2 + 2, EqualTo(4))
Expect(2 + 2 = 4)
Expect(i3, EqualTo(d3))
Expect(2 + 2, Iz.Not.EqualTo(5))
Expect(i3, Iz.Not.EqualTo(iunequal))
End Sub
<Test()> _
Public Sub EqualityTestsWithTolerance()
' CLassic syntax
Assert.AreEqual(5.0R, 4.99R, 0.05R)
Assert.AreEqual(5.0F, 4.99F, 0.05F)
' Helper syntax
Assert.That(4.99R, Iz.EqualTo(5.0R).Within(0.05R))
Assert.That(4D, Iz.Not.EqualTo(5D).Within(0.5D))
Assert.That(4.99F, Iz.EqualTo(5.0F).Within(0.05F))
Assert.That(4.99D, Iz.EqualTo(5D).Within(0.05D))
Assert.That(499, Iz.EqualTo(500).Within(5))
Assert.That(4999999999L, Iz.EqualTo(5000000000L).Within(5L))
' Inherited syntax
Expect(4.99R, EqualTo(5.0R).Within(0.05R))
Expect(4D, Iz.Not.EqualTo(5D).Within(0.5D))
Expect(4.99F, EqualTo(5.0F).Within(0.05F))
Expect(4.99D, EqualTo(5D).Within(0.05D))
Expect(499, EqualTo(500).Within(5))
Expect(4999999999L, EqualTo(5000000000L).Within(5L))
End Sub
<Test()> _
Public Sub EqualityTestsWithTolerance_MixedFloatAndDouble()
' Bug Fix 1743844
Assert.That(2.20492R, Iz.EqualTo(2.2R).Within(0.01F), _
"Double actual, Double expected, Single tolerance")
Assert.That(2.20492R, Iz.EqualTo(2.2F).Within(0.01R), _
"Double actual, Single expected, Double tolerance")
Assert.That(2.20492R, Iz.EqualTo(2.2F).Within(0.01F), _
"Double actual, Single expected, Single tolerance")
Assert.That(2.20492F, Iz.EqualTo(2.2F).Within(0.01R), _
"Single actual, Single expected, Double tolerance")
Assert.That(2.20492F, Iz.EqualTo(2.2R).Within(0.01R), _
"Single actual, Double expected, Double tolerance")
Assert.That(2.20492F, Iz.EqualTo(2.2R).Within(0.01F), _
"Single actual, Double expected, Single tolerance")
End Sub
<Test()> _
Public Sub EqualityTestsWithTolerance_MixingTypesGenerally()
' Extending tolerance to all numeric types
Assert.That(202.0R, Iz.EqualTo(200.0R).Within(2), _
"Double actual, Double expected, int tolerance")
Assert.That(4.87D, Iz.EqualTo(5).Within(0.25R), _
"Decimal actual, int expected, Double tolerance")
Assert.That(4.87D, Iz.EqualTo(5L).Within(1), _
"Decimal actual, long expected, int tolerance")
Assert.That(487, Iz.EqualTo(500).Within(25), _
"int actual, int expected, int tolerance")
Assert.That(487L, Iz.EqualTo(500).Within(25), _
"long actual, int expected, int tolerance")
End Sub
#End Region
#Region "Comparison Tests"
<Test()> _
Public Sub ComparisonTests()
' Classic Syntax
Assert.Greater(7, 3)
Assert.GreaterOrEqual(7, 3)
Assert.GreaterOrEqual(7, 7)
' Helper syntax
Assert.That(7, Iz.GreaterThan(3))
Assert.That(7, Iz.GreaterThanOrEqualTo(3))
Assert.That(7, Iz.AtLeast(3))
Assert.That(7, Iz.GreaterThanOrEqualTo(7))
Assert.That(7, Iz.AtLeast(7))
' Inherited syntax
Expect(7, GreaterThan(3))
Expect(7, GreaterThanOrEqualTo(3))
Expect(7, AtLeast(3))
Expect(7, GreaterThanOrEqualTo(7))
Expect(7, AtLeast(7))
' Classic syntax
Assert.Less(3, 7)
Assert.LessOrEqual(3, 7)
Assert.LessOrEqual(3, 3)
' Helper syntax
Assert.That(3, Iz.LessThan(7))
Assert.That(3, Iz.LessThanOrEqualTo(7))
Assert.That(3, Iz.AtMost(7))
Assert.That(3, Iz.LessThanOrEqualTo(3))
Assert.That(3, Iz.AtMost(3))
' Inherited syntax
Expect(3, LessThan(7))
Expect(3, LessThanOrEqualTo(7))
Expect(3, AtMost(7))
Expect(3, LessThanOrEqualTo(3))
Expect(3, AtMost(3))
End Sub
#End Region
#Region "Collection Tests"
<Test()> _
Public Sub AllItemsTests()
Dim ints As Object() = {1, 2, 3, 4}
Dim doubles As Object() = {0.99, 2.1, 3.0, 4.05}
Dim strings As Object() = {"abc", "bad", "cab", "bad", "dad"}
' Classic syntax
CollectionAssert.AllItemsAreNotNull(ints)
CollectionAssert.AllItemsAreInstancesOfType(ints, GetType(Integer))
CollectionAssert.AllItemsAreInstancesOfType(strings, GetType(String))
CollectionAssert.AllItemsAreUnique(ints)
' Helper syntax
Assert.That(ints, Iz.All.Not.Null)
Assert.That(ints, Has.None.Null)
Assert.That(ints, Iz.All.InstanceOf(GetType(Integer)))
Assert.That(ints, Has.All.InstanceOf(GetType(Integer)))
Assert.That(strings, Iz.All.InstanceOf(GetType(String)))
Assert.That(strings, Has.All.InstanceOf(GetType(String)))
Assert.That(ints, Iz.Unique)
' Only available using new syntax
Assert.That(strings, Iz.Not.Unique)
Assert.That(ints, Iz.All.GreaterThan(0))
Assert.That(ints, Has.All.GreaterThan(0))
Assert.That(ints, Has.None.LessThanOrEqualTo(0))
Assert.That(strings, Iz.All.StringContaining("a"))
Assert.That(strings, Has.All.Contains("a"))
Assert.That(strings, Has.Some.StartsWith("ba"))
Assert.That(strings, Has.Some.Property("Length").EqualTo(3))
Assert.That(strings, Has.Some.StartsWith("BA").IgnoreCase)
Assert.That(doubles, Has.Some.EqualTo(1.0).Within(0.05))
' Inherited syntax
Expect(ints, All.Not.Null)
Expect(ints, None.Null)
Expect(ints, All.InstanceOf(GetType(Integer)))
Expect(strings, All.InstanceOf(GetType(String)))
Expect(ints, Unique)
' Only available using new syntax
Expect(strings, Iz.Not.Unique)
Expect(ints, All.GreaterThan(0))
Expect(strings, All.Contains("a"))
Expect(strings, Some.StartsWith("ba"))
Expect(strings, Some.StartsWith("BA").IgnoreCase)
Expect(doubles, Some.EqualTo(1.0).Within(0.05))
End Sub
<Test()> _
Public Sub SomeItemsTests()
Dim mixed As Object() = {1, 2, "3", Nothing, "four", 100}
Dim strings As Object() = {"abc", "bad", "cab", "bad", "dad"}
' Not available using the classic syntax
' Helper syntax
Assert.That(mixed, Has.Some.Null)
Assert.That(mixed, Has.Some.InstanceOf(GetType(Integer)))
Assert.That(mixed, Has.Some.InstanceOf(GetType(String)))
Assert.That(strings, Has.Some.StartsWith("ba"))
Assert.That(strings, Has.Some.Not.StartsWith("ba"))
' Inherited syntax
Expect(mixed, Some.Null)
Expect(mixed, Some.InstanceOf(GetType(Integer)))
Expect(mixed, Some.InstanceOf(GetType(String)))
Expect(strings, Some.StartsWith("ba"))
Expect(strings, Some.Not.StartsWith("ba"))
End Sub
<Test()> _
Public Sub NoItemsTests()
Dim ints As Object() = {1, 2, 3, 4, 5}
Dim strings As Object() = {"abc", "bad", "cab", "bad", "dad"}
' Not available using the classic syntax
' Helper syntax
Assert.That(ints, Has.None.Null)
Assert.That(ints, Has.None.InstanceOf(GetType(String)))
Assert.That(ints, Has.None.GreaterThan(99))
Assert.That(strings, Has.None.StartsWith("qu"))
' Inherited syntax
Expect(ints, None.Null)
Expect(ints, None.InstanceOf(GetType(String)))
Expect(ints, None.GreaterThan(99))
Expect(strings, None.StartsWith("qu"))
End Sub
<Test()> _
Public Sub CollectionContainsTests()
Dim iarray As Integer() = {1, 2, 3}
Dim sarray As String() = {"a", "b", "c"}
' Classic syntax
Assert.Contains(3, iarray)
Assert.Contains("b", sarray)
CollectionAssert.Contains(iarray, 3)
CollectionAssert.Contains(sarray, "b")
CollectionAssert.DoesNotContain(sarray, "x")
' Showing that Contains uses NUnit equality
CollectionAssert.Contains(iarray, 1.0R)
' Helper syntax
Assert.That(iarray, Has.Member(3))
Assert.That(sarray, Has.Member("b"))
Assert.That(sarray, Has.No.Member("x"))
' Showing that Contains uses NUnit equality
Assert.That(iarray, Has.Member(1.0R))
' Only available using the new syntax
' Note that EqualTo and SameAs do NOT give
' identical results to Contains because
' Contains uses Object.Equals()
Assert.That(iarray, Has.Some.EqualTo(3))
Assert.That(iarray, Has.Member(3))
Assert.That(sarray, Has.Some.EqualTo("b"))
Assert.That(sarray, Has.None.EqualTo("x"))
Assert.That(iarray, Has.None.SameAs(1.0R))
Assert.That(iarray, Has.All.LessThan(10))
Assert.That(sarray, Has.All.Length.EqualTo(1))
Assert.That(sarray, Has.None.Property("Length").GreaterThan(3))
' Inherited syntax
Expect(iarray, Contains(3))
Expect(sarray, Contains("b"))
Expect(sarray, Has.No.Member("x"))
' Only available using new syntax
' Note that EqualTo and SameAs do NOT give
' identical results to Contains because
' Contains uses Object.Equals()
Expect(iarray, Some.EqualTo(3))
Expect(sarray, Some.EqualTo("b"))
Expect(sarray, None.EqualTo("x"))
Expect(iarray, All.LessThan(10))
Expect(sarray, All.Length.EqualTo(1))
Expect(sarray, None.Property("Length").GreaterThan(3))
End Sub
<Test()> _
Public Sub CollectionEquivalenceTests()
Dim ints1to5 As Integer() = {1, 2, 3, 4, 5}
Dim twothrees As Integer() = {1, 2, 3, 3, 4, 5}
Dim twofours As Integer() = {1, 2, 3, 4, 4, 5}
' Classic syntax
CollectionAssert.AreEquivalent(New Integer() {2, 1, 4, 3, 5}, ints1to5)
CollectionAssert.AreNotEquivalent(New Integer() {2, 2, 4, 3, 5}, ints1to5)
CollectionAssert.AreNotEquivalent(New Integer() {2, 4, 3, 5}, ints1to5)
CollectionAssert.AreNotEquivalent(New Integer() {2, 2, 1, 1, 4, 3, 5}, ints1to5)
CollectionAssert.AreNotEquivalent(twothrees, twofours)
' Helper syntax
Assert.That(New Integer() {2, 1, 4, 3, 5}, Iz.EquivalentTo(ints1to5))
Assert.That(New Integer() {2, 2, 4, 3, 5}, Iz.Not.EquivalentTo(ints1to5))
Assert.That(New Integer() {2, 4, 3, 5}, Iz.Not.EquivalentTo(ints1to5))
Assert.That(New Integer() {2, 2, 1, 1, 4, 3, 5}, Iz.Not.EquivalentTo(ints1to5))
Assert.That(twothrees, Iz.Not.EquivalentTo(twofours))
' Inherited syntax
Expect(New Integer() {2, 1, 4, 3, 5}, EquivalentTo(ints1to5))
End Sub
<Test()> _
Public Sub SubsetTests()
Dim ints1to5 As Integer() = {1, 2, 3, 4, 5}
' Classic syntax
CollectionAssert.IsSubsetOf(New Integer() {1, 3, 5}, ints1to5)
CollectionAssert.IsSubsetOf(New Integer() {1, 2, 3, 4, 5}, ints1to5)
CollectionAssert.IsNotSubsetOf(New Integer() {2, 4, 6}, ints1to5)
CollectionAssert.IsNotSubsetOf(New Integer() {1, 2, 2, 2, 5}, ints1to5)
' Helper syntax
Assert.That(New Integer() {1, 3, 5}, Iz.SubsetOf(ints1to5))
Assert.That(New Integer() {1, 2, 3, 4, 5}, Iz.SubsetOf(ints1to5))
Assert.That(New Integer() {2, 4, 6}, Iz.Not.SubsetOf(ints1to5))
' Inherited syntax
Expect(New Integer() {1, 3, 5}, SubsetOf(ints1to5))
Expect(New Integer() {1, 2, 3, 4, 5}, SubsetOf(ints1to5))
Expect(New Integer() {2, 4, 6}, Iz.Not.SubsetOf(ints1to5))
End Sub
#End Region
#Region "Property Tests"
<Test()> _
Public Sub PropertyTests()
Dim array As String() = {"abc", "bca", "xyz", "qrs"}
Dim array2 As String() = {"a", "ab", "abc"}
Dim list As New ArrayList(array)
' Not available using the classic syntax
' Helper syntax
' Assert.That(list, Has.Property("Count"))
' Assert.That(list, Has.No.Property("Length"))
Assert.That("Hello", Has.Length.EqualTo(5))
Assert.That("Hello", Has.Property("Length").EqualTo(5))
Assert.That("Hello", Has.Property("Length").GreaterThan(3))
Assert.That(array, Has.Property("Length").EqualTo(4))
Assert.That(array, Has.Length.EqualTo(4))
Assert.That(array, Has.Property("Length").LessThan(10))
Assert.That(array, Has.All.Property("Length").EqualTo(3))
Assert.That(array, Has.All.Length.EqualTo(3))
Assert.That(array, Iz.All.Length.EqualTo(3))
Assert.That(array, Has.All.Property("Length").EqualTo(3))
Assert.That(array, Iz.All.Property("Length").EqualTo(3))
Assert.That(array2, Iz.Not.Property("Length").EqualTo(4))
Assert.That(array2, Iz.Not.Length.EqualTo(4))
Assert.That(array2, Has.No.Property("Length").GreaterThan(3))
' Inherited syntax
' Expect(list, Has.Property("Count"))
' Expect(list, Has.No.Property("Nada"))
Expect(array, All.Property("Length").EqualTo(3))
Expect(array, All.Length.EqualTo(3))
End Sub
#End Region
#Region "Not Tests"
<Test()> _
Public Sub NotTests()
' Not available using the classic syntax
' Helper syntax
Assert.That(42, Iz.Not.Null)
Assert.That(42, Iz.Not.True)
Assert.That(42, Iz.Not.False)
Assert.That(2.5, Iz.Not.NaN)
Assert.That(2 + 2, Iz.Not.EqualTo(3))
Assert.That(2 + 2, Iz.Not.Not.EqualTo(4))
Assert.That(2 + 2, Iz.Not.Not.Not.EqualTo(5))
' Inherited syntax
Expect(42, Iz.Not.Null)
Expect(42, Iz.Not.True)
Expect(42, Iz.Not.False)
Expect(2.5, Iz.Not.NaN)
Expect(2 + 2, Iz.Not.EqualTo(3))
Expect(2 + 2, Iz.Not.Not.EqualTo(4))
Expect(2 + 2, Iz.Not.Not.Not.EqualTo(5))
End Sub
#End Region
End Class
End Namespace

11
syntax/vb-syntax.build Executable file
Просмотреть файл

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<project name="vb-syntax" default="build">
<include buildfile="../../samples.common" />
<patternset id="source-files">
<include name="AssemblyInfo.vb" />
<include name="AssertSyntaxTests.vb" />
</patternset>
</project>

20
syntax/vb-syntax.sln Normal file
Просмотреть файл

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "vb-syntax", "vb-syntax.vbproj", "{6BEF566A-2691-4EE8-91AF-0390CCCDDAF1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6BEF566A-2691-4EE8-91AF-0390CCCDDAF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6BEF566A-2691-4EE8-91AF-0390CCCDDAF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6BEF566A-2691-4EE8-91AF-0390CCCDDAF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BEF566A-2691-4EE8-91AF-0390CCCDDAF1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = vb-syntax.vbproj
EndGlobalSection
EndGlobal

124
syntax/vb-syntax.vbproj Normal file
Просмотреть файл

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectType>Local</ProjectType>
<ProductVersion>7.10.3077</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6BEF566A-2691-4EE8-91AF-0390CCCDDAF1}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<AssemblyKeyContainerName />
<AssemblyName>vb-syntax</AssemblyName>
<AssemblyOriginatorKeyMode>None</AssemblyOriginatorKeyMode>
<DefaultClientScript>JScript</DefaultClientScript>
<DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
<DefaultTargetSchema>IE50</DefaultTargetSchema>
<DelaySign>false</DelaySign>
<OutputType>Library</OutputType>
<RootNamespace>NUnit.Samples</RootNamespace>
<StartupObject>NUnit.Samples.%28None%29</StartupObject>
<FileUpgradeFlags>
</FileUpgradeFlags>
<MyType>Windows</MyType>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>0.0</OldToolsVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>bin\</OutputPath>
<DocumentationFile>vb-syntax.xml</DocumentationFile>
<BaseAddress>285212672</BaseAddress>
<ConfigurationOverrideFile />
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<DebugSymbols>true</DebugSymbols>
<RegisterForComInterop>false</RegisterForComInterop>
<NoWarn>42016,42017,42018,42019,42032,42353,42354,42355</NoWarn>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<AdditionalParameters />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>bin\</OutputPath>
<DocumentationFile>vb-syntax.xml</DocumentationFile>
<BaseAddress>285212672</BaseAddress>
<ConfigurationOverrideFile />
<DefineDebug>false</DefineDebug>
<DefineTrace>true</DefineTrace>
<Optimize>true</Optimize>
<RegisterForComInterop>false</RegisterForComInterop>
<NoWarn>42016,42017,42018,42019,42032,42353,42354,42355</NoWarn>
<DebugType>none</DebugType>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<AdditionalParameters />
</PropertyGroup>
<ItemGroup>
<Reference Include="System">
<Name>System</Name>
</Reference>
<Reference Include="System.Data">
<Name>System.Data</Name>
</Reference>
<Reference Include="System.Xml">
<Name>System.XML</Name>
</Reference>
<Reference Include="nunit.framework">
<HintPath>..\..\..\nunit-2.6\work\bin\Debug\framework\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Import Include="Microsoft.VisualBasic" />
<Import Include="System" />
<Import Include="System.Collections" />
<Import Include="System.Data" />
<Import Include="System.Diagnostics" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.vb">
<SubType>Code</SubType>
</Compile>
<Compile Include="AssertSyntaxTests.vb">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Folder Include="My Project\" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
<PropertyGroup>
<PreBuildEvent />
<PostBuildEvent />
</PropertyGroup>
</Project>