diff options
Diffstat (limited to 'tools/NUnit/samples/csharp')
-rw-r--r-- | tools/NUnit/samples/csharp/CSharp.sln | 37 | ||||
-rw-r--r-- | tools/NUnit/samples/csharp/failures/AssemblyInfo.cs | 58 | ||||
-rw-r--r-- | tools/NUnit/samples/csharp/failures/CSharpTest.cs | 85 | ||||
-rw-r--r-- | tools/NUnit/samples/csharp/failures/cs-failures.build | 11 | ||||
-rw-r--r-- | tools/NUnit/samples/csharp/failures/cs-failures.csproj | 20 | ||||
-rw-r--r-- | tools/NUnit/samples/csharp/money/AssemblyInfo.cs | 58 | ||||
-rw-r--r-- | tools/NUnit/samples/csharp/money/IMoney.cs | 37 | ||||
-rw-r--r-- | tools/NUnit/samples/csharp/money/Money.cs | 103 | ||||
-rw-r--r-- | tools/NUnit/samples/csharp/money/MoneyBag.cs | 174 | ||||
-rw-r--r-- | tools/NUnit/samples/csharp/money/MoneyTest.cs | 321 | ||||
-rw-r--r-- | tools/NUnit/samples/csharp/money/cs-money.build | 14 | ||||
-rw-r--r-- | tools/NUnit/samples/csharp/money/cs-money.csproj | 23 | ||||
-rw-r--r-- | tools/NUnit/samples/csharp/syntax/AssemblyInfo.cs | 58 | ||||
-rw-r--r-- | tools/NUnit/samples/csharp/syntax/AssertSyntaxTests.cs | 828 | ||||
-rw-r--r-- | tools/NUnit/samples/csharp/syntax/cs-syntax.build | 11 | ||||
-rw-r--r-- | tools/NUnit/samples/csharp/syntax/cs-syntax.csproj | 20 |
16 files changed, 0 insertions, 1858 deletions
diff --git a/tools/NUnit/samples/csharp/CSharp.sln b/tools/NUnit/samples/csharp/CSharp.sln deleted file mode 100644 index ed95f8a..0000000 --- a/tools/NUnit/samples/csharp/CSharp.sln +++ /dev/null @@ -1,37 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cs-failures", "failures\cs-failures.csproj", "{15D66EEE-A852-4A52-89C2-83E74ECF3770}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cs-money", "money\cs-money.csproj", "{11EDF872-A04D-4F75-A1BF-71168DC86AF3}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cs-syntax", "syntax\cs-syntax.csproj", "{06F46FA2-687B-4B46-A912-C1B0B4CC1B20}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release - EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {15D66EEE-A852-4A52-89C2-83E74ECF3770}.Debug.ActiveCfg = Debug|.NET - {15D66EEE-A852-4A52-89C2-83E74ECF3770}.Debug.Build.0 = Debug|.NET - {15D66EEE-A852-4A52-89C2-83E74ECF3770}.Release.ActiveCfg = Release|.NET - {15D66EEE-A852-4A52-89C2-83E74ECF3770}.Release.Build.0 = Release|.NET - {11EDF872-A04D-4F75-A1BF-71168DC86AF3}.Debug.ActiveCfg = Debug|.NET - {11EDF872-A04D-4F75-A1BF-71168DC86AF3}.Debug.Build.0 = Debug|.NET - {11EDF872-A04D-4F75-A1BF-71168DC86AF3}.Release.ActiveCfg = Release|.NET - {11EDF872-A04D-4F75-A1BF-71168DC86AF3}.Release.Build.0 = Release|.NET - {06F46FA2-687B-4B46-A912-C1B0B4CC1B20}.Debug.ActiveCfg = Debug|.NET - {06F46FA2-687B-4B46-A912-C1B0B4CC1B20}.Debug.Build.0 = Debug|.NET - {06F46FA2-687B-4B46-A912-C1B0B4CC1B20}.Release.ActiveCfg = Release|.NET - {06F46FA2-687B-4B46-A912-C1B0B4CC1B20}.Release.Build.0 = Release|.NET - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution - EndGlobalSection -EndGlobal diff --git a/tools/NUnit/samples/csharp/failures/AssemblyInfo.cs b/tools/NUnit/samples/csharp/failures/AssemblyInfo.cs deleted file mode 100644 index 67e65b0..0000000 --- a/tools/NUnit/samples/csharp/failures/AssemblyInfo.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -// -// 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. -// -[assembly: AssemblyTitle("csharp.sample.dll")] -[assembly: AssemblyDescription("C# Sample Unit Tests")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("NUnit")] -[assembly: AssemblyProduct("NUnit")] -[assembly: AssemblyCopyright("Copyright (C) 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov. \nCopyright (C) 2000-2003 Philip Craig.\nAll Rights Reserved.")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// -// 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 Revision and Build Numbers -// by using the '*' as shown below: - -[assembly: AssemblyVersion("2.2.0.0")] - -// -// In order to sign your assembly you must specify a key to use. Refer to the -// Microsoft .NET Framework documentation for more information on assembly signing. -// -// Use the attributes below to control which key is used for signing. -// -// Notes: -// (*) If no key is specified, the assembly is not signed. -// (*) KeyName refers to a key that has been installed in the Crypto Service -// Provider (CSP) on your machine. KeyFile refers to a file which contains -// a key. -// (*) If the KeyFile and the KeyName values are both specified, the -// following processing occurs: -// (1) If the KeyName can be found in the CSP, that key is used. -// (2) If the KeyName does not exist and the KeyFile does exist, the key -// in the KeyFile is installed into the CSP and used. -// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. -// When specifying the KeyFile, the location of the KeyFile should be -// relative to the project output directory which is -// %Project Directory%\obj\<configuration>. For example, if your KeyFile is -// located in the project directory, you would specify the AssemblyKeyFile -// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] -// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework -// documentation for more information on this. -// -[assembly: AssemblyDelaySign(false)] -[assembly: AssemblyKeyFile("")] -[assembly: AssemblyKeyName("")] diff --git a/tools/NUnit/samples/csharp/failures/CSharpTest.cs b/tools/NUnit/samples/csharp/failures/CSharpTest.cs deleted file mode 100644 index 0ab0fe6..0000000 --- a/tools/NUnit/samples/csharp/failures/CSharpTest.cs +++ /dev/null @@ -1,85 +0,0 @@ -// **************************************************************** -// 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/?p=license&r=2.4. -// **************************************************************** - -namespace NUnit.Samples -{ - using System; - using NUnit.Framework; - - /// <summary>Some simple Tests.</summary> - /// - [TestFixture] - public class SimpleCSharpTest - { - /// <summary> - /// - /// </summary> - protected int fValue1; - /// <summary> - /// - /// </summary> - protected int fValue2; - - /// <summary> - /// - /// </summary> - [SetUp] public void Init() - { - fValue1= 2; - fValue2= 3; - } - - /// <summary> - /// - /// </summary> - /// - [Test] public void Add() - { - double result= fValue1 + fValue2; - // forced failure result == 5 - Assert.AreEqual(6, result, "Expected Failure."); - } - - /// <summary> - /// - /// </summary> - /// - [Test] public void DivideByZero() - { - int zero= 0; - int result= 8/zero; - } - - /// <summary> - /// - /// </summary> - /// - [Test] public void Equals() - { - Assert.AreEqual(12, 12, "Integer"); - Assert.AreEqual(12L, 12L, "Long"); - Assert.AreEqual('a', 'a', "Char"); - Assert.AreEqual((object)12, (object)12, "Integer Object Cast"); - - Assert.AreEqual(12, 13, "Expected Failure (Integer)"); - Assert.AreEqual(12.0, 11.99, 0.0, "Expected Failure (Double)."); - } - - [Test] - [ExpectedException(typeof(InvalidOperationException))] - public void ExpectAnException() - { - throw new InvalidCastException(); - } - - [Test] - [Ignore("ignored test")] - public void IgnoredTest() - { - throw new Exception(); - } - } -}
\ No newline at end of file diff --git a/tools/NUnit/samples/csharp/failures/cs-failures.build b/tools/NUnit/samples/csharp/failures/cs-failures.build deleted file mode 100644 index ea71419..0000000 --- a/tools/NUnit/samples/csharp/failures/cs-failures.build +++ /dev/null @@ -1,11 +0,0 @@ -<?xml version="1.0"?> -<project name="cs-failures" default="build"> - - <include buildfile="../../samples.common"/> - - <patternset id="source-files"> - <include name="AssemblyInfo.cs" /> - <include name="CSharpTest.cs" /> - </patternset> - -</project>
\ No newline at end of file diff --git a/tools/NUnit/samples/csharp/failures/cs-failures.csproj b/tools/NUnit/samples/csharp/failures/cs-failures.csproj deleted file mode 100644 index e66e6d4..0000000 --- a/tools/NUnit/samples/csharp/failures/cs-failures.csproj +++ /dev/null @@ -1,20 +0,0 @@ -<VisualStudioProject> - <CSHARP ProjectType="Local" ProductVersion="7.10.3077" SchemaVersion="2.0" ProjectGuid="{15D66EEE-A852-4A52-89C2-83E74ECF3770}"> - <Build> - <Settings ApplicationIcon="" AssemblyKeyContainerName="" AssemblyName="cs-failures" AssemblyOriginatorKeyFile="" DefaultClientScript="JScript" DefaultHTMLPageLayout="Grid" DefaultTargetSchema="IE50" DelaySign="false" OutputType="Library" PreBuildEvent="" PostBuildEvent="" RootNamespace="csharp_sample" RunPostBuildEvent="OnBuildSuccess" StartupObject=""> - <Config Name="Debug" AllowUnsafeBlocks="false" BaseAddress="285212672" CheckForOverflowUnderflow="false" ConfigurationOverrideFile="" DefineConstants="DEBUG;TRACE" DocumentationFile="" DebugSymbols="true" FileAlignment="4096" IncrementalBuild="true" NoStdLib="false" NoWarn="" Optimize="false" OutputPath="bin\Debug\" RegisterForComInterop="false" RemoveIntegerChecks="false" TreatWarningsAsErrors="false" WarningLevel="4" /> - <Config Name="Release" AllowUnsafeBlocks="false" BaseAddress="285212672" CheckForOverflowUnderflow="false" ConfigurationOverrideFile="" DefineConstants="TRACE" DocumentationFile="" DebugSymbols="false" FileAlignment="4096" IncrementalBuild="false" NoStdLib="false" NoWarn="" Optimize="true" OutputPath="bin\Release\" RegisterForComInterop="false" RemoveIntegerChecks="false" TreatWarningsAsErrors="false" WarningLevel="4" /> - </Settings> - <References> - <Reference Name="System" AssemblyName="System" /> - <Reference Name="nunit.framework" AssemblyName="nunit.framework, Version=2.5, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" HintPath="..\..\..\bin\net-1.1\framework\nunit.framework.dll" /> - </References> - </Build> - <Files> - <Include> - <File RelPath="AssemblyInfo.cs" SubType="Code" BuildAction="Compile" /> - <File RelPath="CSharpTest.cs" SubType="Code" BuildAction="Compile" /> - </Include> - </Files> - </CSHARP> -</VisualStudioProject>
\ No newline at end of file diff --git a/tools/NUnit/samples/csharp/money/AssemblyInfo.cs b/tools/NUnit/samples/csharp/money/AssemblyInfo.cs deleted file mode 100644 index 72a1771..0000000 --- a/tools/NUnit/samples/csharp/money/AssemblyInfo.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -// -// 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. -// -[assembly: AssemblyTitle("")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// -// 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 Revision and Build Numbers -// by using the '*' as shown below: - -[assembly: AssemblyVersion("2.2.0.0")] - -// -// In order to sign your assembly you must specify a key to use. Refer to the -// Microsoft .NET Framework documentation for more information on assembly signing. -// -// Use the attributes below to control which key is used for signing. -// -// Notes: -// (*) If no key is specified, the assembly is not signed. -// (*) KeyName refers to a key that has been installed in the Crypto Service -// Provider (CSP) on your machine. KeyFile refers to a file which contains -// a key. -// (*) If the KeyFile and the KeyName values are both specified, the -// following processing occurs: -// (1) If the KeyName can be found in the CSP, that key is used. -// (2) If the KeyName does not exist and the KeyFile does exist, the key -// in the KeyFile is installed into the CSP and used. -// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. -// When specifying the KeyFile, the location of the KeyFile should be -// relative to the project output directory which is -// %Project Directory%\obj\<configuration>. For example, if your KeyFile is -// located in the project directory, you would specify the AssemblyKeyFile -// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] -// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework -// documentation for more information on this. -// -[assembly: AssemblyDelaySign(false)] -[assembly: AssemblyKeyFile("")] -[assembly: AssemblyKeyName("")] diff --git a/tools/NUnit/samples/csharp/money/IMoney.cs b/tools/NUnit/samples/csharp/money/IMoney.cs deleted file mode 100644 index 9b3fd35..0000000 --- a/tools/NUnit/samples/csharp/money/IMoney.cs +++ /dev/null @@ -1,37 +0,0 @@ -// **************************************************************** -// 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/?p=license&r=2.4. -// **************************************************************** - -namespace NUnit.Samples.Money -{ - - /// <summary>The common interface for simple Monies and MoneyBags.</summary> - interface IMoney - { - - /// <summary>Adds a money to this money.</summary> - IMoney Add(IMoney m); - - /// <summary>Adds a simple Money to this money. This is a helper method for - /// implementing double dispatch.</summary> - IMoney AddMoney(Money m); - - /// <summary>Adds a MoneyBag to this money. This is a helper method for - /// implementing double dispatch.</summary> - IMoney AddMoneyBag(MoneyBag s); - - /// <value>True if this money is zero.</value> - bool IsZero { get; } - - /// <summary>Multiplies a money by the given factor.</summary> - IMoney Multiply(int factor); - - /// <summary>Negates this money.</summary> - IMoney Negate(); - - /// <summary>Subtracts a money from this money.</summary> - IMoney Subtract(IMoney m); - } -} diff --git a/tools/NUnit/samples/csharp/money/Money.cs b/tools/NUnit/samples/csharp/money/Money.cs deleted file mode 100644 index 2e2de93..0000000 --- a/tools/NUnit/samples/csharp/money/Money.cs +++ /dev/null @@ -1,103 +0,0 @@ -// **************************************************************** -// 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/?p=license&r=2.4. -// **************************************************************** - -namespace NUnit.Samples.Money -{ - - using System; - using System.Text; - - /// <summary>A simple Money.</summary> - class Money: IMoney - { - - private int fAmount; - private String fCurrency; - - /// <summary>Constructs a money from the given amount and - /// currency.</summary> - public Money(int amount, String currency) - { - fAmount= amount; - fCurrency= currency; - } - - /// <summary>Adds a money to this money. Forwards the request to - /// the AddMoney helper.</summary> - public IMoney Add(IMoney m) - { - return m.AddMoney(this); - } - - public IMoney AddMoney(Money m) - { - if (m.Currency.Equals(Currency) ) - return new Money(Amount+m.Amount, Currency); - return new MoneyBag(this, m); - } - - public IMoney AddMoneyBag(MoneyBag s) - { - return s.AddMoney(this); - } - - public int Amount - { - get { return fAmount; } - } - - public String Currency - { - get { return fCurrency; } - } - - public override bool Equals(Object anObject) - { - if (IsZero) - if (anObject is IMoney) - return ((IMoney)anObject).IsZero; - if (anObject is Money) - { - Money aMoney= (Money)anObject; - return aMoney.Currency.Equals(Currency) - && Amount == aMoney.Amount; - } - return false; - } - - public override int GetHashCode() - { - return fCurrency.GetHashCode()+fAmount; - } - - public bool IsZero - { - get { return Amount == 0; } - } - - public IMoney Multiply(int factor) - { - return new Money(Amount*factor, Currency); - } - - public IMoney Negate() - { - return new Money(-Amount, Currency); - } - - public IMoney Subtract(IMoney m) - { - return Add(m.Negate()); - } - - public override String ToString() - { - StringBuilder buffer = new StringBuilder(); - buffer.Append("["+Amount+" "+Currency+"]"); - return buffer.ToString(); - } - } -} diff --git a/tools/NUnit/samples/csharp/money/MoneyBag.cs b/tools/NUnit/samples/csharp/money/MoneyBag.cs deleted file mode 100644 index 45b9442..0000000 --- a/tools/NUnit/samples/csharp/money/MoneyBag.cs +++ /dev/null @@ -1,174 +0,0 @@ -// **************************************************************** -// 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/?p=license&r=2.4. -// **************************************************************** - -namespace NUnit.Samples.Money -{ - - using System; - using System.Collections; - using System.Text; - - /// <summary>A MoneyBag defers exchange rate conversions.</summary> - /// <remarks>For example adding - /// 12 Swiss Francs to 14 US Dollars is represented as a bag - /// containing the two Monies 12 CHF and 14 USD. Adding another - /// 10 Swiss francs gives a bag with 22 CHF and 14 USD. Due to - /// the deferred exchange rate conversion we can later value a - /// MoneyBag with different exchange rates. - /// - /// A MoneyBag is represented as a list of Monies and provides - /// different constructors to create a MoneyBag.</remarks> - class MoneyBag: IMoney - { - private ArrayList fMonies= new ArrayList(5); - - private MoneyBag() - { - } - public MoneyBag(Money[] bag) - { - for (int i= 0; i < bag.Length; i++) - { - if (!bag[i].IsZero) - AppendMoney(bag[i]); - } - } - public MoneyBag(Money m1, Money m2) - { - AppendMoney(m1); - AppendMoney(m2); - } - public MoneyBag(Money m, MoneyBag bag) - { - AppendMoney(m); - AppendBag(bag); - } - public MoneyBag(MoneyBag m1, MoneyBag m2) - { - AppendBag(m1); - AppendBag(m2); - } - public IMoney Add(IMoney m) - { - return m.AddMoneyBag(this); - } - public IMoney AddMoney(Money m) - { - return (new MoneyBag(m, this)).Simplify(); - } - public IMoney AddMoneyBag(MoneyBag s) - { - return (new MoneyBag(s, this)).Simplify(); - } - private void AppendBag(MoneyBag aBag) - { - foreach (Money m in aBag.fMonies) - AppendMoney(m); - } - private void AppendMoney(Money aMoney) - { - IMoney old= FindMoney(aMoney.Currency); - if (old == null) - { - fMonies.Add(aMoney); - return; - } - fMonies.Remove(old); - IMoney sum= old.Add(aMoney); - if (sum.IsZero) - return; - fMonies.Add(sum); - } - private bool Contains(Money aMoney) - { - Money m= FindMoney(aMoney.Currency); - return m.Amount == aMoney.Amount; - } - public override bool Equals(Object anObject) - { - if (IsZero) - if (anObject is IMoney) - return ((IMoney)anObject).IsZero; - - if (anObject is MoneyBag) - { - MoneyBag aMoneyBag= (MoneyBag)anObject; - if (aMoneyBag.fMonies.Count != fMonies.Count) - return false; - - foreach (Money m in fMonies) - { - if (!aMoneyBag.Contains(m)) - return false; - } - return true; - } - return false; - } - private Money FindMoney(String currency) - { - foreach (Money m in fMonies) - { - if (m.Currency.Equals(currency)) - return m; - } - return null; - } - public override int GetHashCode() - { - int hash= 0; - foreach (Money m in fMonies) - { - hash^= m.GetHashCode(); - } - return hash; - } - public bool IsZero - { - get { return fMonies.Count == 0; } - } - public IMoney Multiply(int factor) - { - MoneyBag result= new MoneyBag(); - if (factor != 0) - { - foreach (Money m in fMonies) - { - result.AppendMoney((Money)m.Multiply(factor)); - } - } - return result; - } - public IMoney Negate() - { - MoneyBag result= new MoneyBag(); - foreach (Money m in fMonies) - { - result.AppendMoney((Money)m.Negate()); - } - return result; - } - private IMoney Simplify() - { - if (fMonies.Count == 1) - return (IMoney)fMonies[0]; - return this; - } - public IMoney Subtract(IMoney m) - { - return Add(m.Negate()); - } - public override String ToString() - { - StringBuilder buffer = new StringBuilder(); - buffer.Append("{"); - foreach (Money m in fMonies) - buffer.Append(m); - buffer.Append("}"); - return buffer.ToString(); - } - } -} diff --git a/tools/NUnit/samples/csharp/money/MoneyTest.cs b/tools/NUnit/samples/csharp/money/MoneyTest.cs deleted file mode 100644 index 603dcf8..0000000 --- a/tools/NUnit/samples/csharp/money/MoneyTest.cs +++ /dev/null @@ -1,321 +0,0 @@ -// **************************************************************** -// 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/?p=license&r=2.4. -// **************************************************************** - -namespace NUnit.Samples.Money -{ - using System; - using NUnit.Framework; - /// <summary> - /// - /// </summary> - /// - [TestFixture] - public class MoneyTest - { - private Money f12CHF; - private Money f14CHF; - private Money f7USD; - private Money f21USD; - - private MoneyBag fMB1; - private MoneyBag fMB2; - - /// <summary> - /// - /// </summary> - /// - [SetUp] - protected void 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); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void BagMultiply() - { - // {[12 CHF][7 USD]} *2 == {[24 CHF][14 USD]} - Money[] bag = { new Money(24, "CHF"), new Money(14, "USD") }; - MoneyBag expected= new MoneyBag(bag); - Assert.AreEqual(expected, fMB1.Multiply(2)); - Assert.AreEqual(fMB1, fMB1.Multiply(1)); - Assert.IsTrue(fMB1.Multiply(0).IsZero); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void BagNegate() - { - // {[12 CHF][7 USD]} negate == {[-12 CHF][-7 USD]} - Money[] bag= { new Money(-12, "CHF"), new Money(-7, "USD") }; - MoneyBag expected= new MoneyBag(bag); - Assert.AreEqual(expected, fMB1.Negate()); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void BagSimpleAdd() - { - // {[12 CHF][7 USD]} + [14 CHF] == {[26 CHF][7 USD]} - Money[] bag= { new Money(26, "CHF"), new Money(7, "USD") }; - MoneyBag expected= new MoneyBag(bag); - Assert.AreEqual(expected, fMB1.Add(f14CHF)); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void BagSubtract() - { - // {[12 CHF][7 USD]} - {[14 CHF][21 USD] == {[-2 CHF][-14 USD]} - Money[] bag= { new Money(-2, "CHF"), new Money(-14, "USD") }; - MoneyBag expected= new MoneyBag(bag); - Assert.AreEqual(expected, fMB1.Subtract(fMB2)); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void BagSumAdd() - { - // {[12 CHF][7 USD]} + {[14 CHF][21 USD]} == {[26 CHF][28 USD]} - Money[] bag= { new Money(26, "CHF"), new Money(28, "USD") }; - MoneyBag expected= new MoneyBag(bag); - Assert.AreEqual(expected, fMB1.Add(fMB2)); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void IsZero() - { - Assert.IsTrue(fMB1.Subtract(fMB1).IsZero); - - Money[] bag = { new Money(0, "CHF"), new Money(0, "USD") }; - Assert.IsTrue(new MoneyBag(bag).IsZero); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void MixedSimpleAdd() - { - // [12 CHF] + [7 USD] == {[12 CHF][7 USD]} - Money[] bag= { f12CHF, f7USD }; - MoneyBag expected= new MoneyBag(bag); - Assert.AreEqual(expected, f12CHF.Add(f7USD)); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void 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(null)); - - Assert.IsTrue(fMB1.Equals( fMB1 )); - MoneyBag equal= new MoneyBag(new Money(12, "CHF"), new Money(7, "USD")); - Assert.IsTrue(fMB1.Equals(equal)); - Assert.IsTrue(!fMB1.Equals(f12CHF)); - Assert.IsTrue(!f12CHF.Equals(fMB1)); - Assert.IsTrue(!fMB1.Equals(fMB2)); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void MoneyBagHash() - { - MoneyBag equal= new MoneyBag(new Money(12, "CHF"), new Money(7, "USD")); - Assert.AreEqual(fMB1.GetHashCode(), equal.GetHashCode()); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void 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(null)); - Money equalMoney= new Money(12, "CHF"); - Assert.IsTrue(f12CHF.Equals( f12CHF )); - Assert.IsTrue(f12CHF.Equals( equalMoney )); - Assert.IsFalse(f12CHF.Equals(f14CHF)); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void MoneyHash() - { - Assert.IsFalse(f12CHF.Equals(null)); - Money equal= new Money(12, "CHF"); - Assert.AreEqual(f12CHF.GetHashCode(), equal.GetHashCode()); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void Normalize() - { - Money[] bag= { new Money(26, "CHF"), new Money(28, "CHF"), new Money(6, "CHF") }; - MoneyBag moneyBag= new MoneyBag(bag); - Money[] expected = { new Money(60, "CHF") }; - // note: expected is still a MoneyBag - MoneyBag expectedBag= new MoneyBag(expected); - Assert.AreEqual(expectedBag, moneyBag); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void Normalize2() - { - // {[12 CHF][7 USD]} - [12 CHF] == [7 USD] - Money expected= new Money(7, "USD"); - Assert.AreEqual(expected, fMB1.Subtract(f12CHF)); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void Normalize3() - { - // {[12 CHF][7 USD]} - {[12 CHF][3 USD]} == [4 USD] - Money[] s1 = { new Money(12, "CHF"), new Money(3, "USD") }; - MoneyBag ms1= new MoneyBag(s1); - Money expected= new Money(4, "USD"); - Assert.AreEqual(expected, fMB1.Subtract(ms1)); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void Normalize4() - { - // [12 CHF] - {[12 CHF][3 USD]} == [-3 USD] - Money[] s1 = { new Money(12, "CHF"), new Money(3, "USD") }; - MoneyBag ms1= new MoneyBag(s1); - Money expected= new Money(-3, "USD"); - Assert.AreEqual(expected, f12CHF.Subtract(ms1)); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void Print() - { - Assert.AreEqual("[12 CHF]", f12CHF.ToString()); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void SimpleAdd() - { - // [12 CHF] + [14 CHF] == [26 CHF] - Money expected= new Money(26, "CHF"); - Assert.AreEqual(expected, f12CHF.Add(f14CHF)); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void SimpleBagAdd() - { - // [14 CHF] + {[12 CHF][7 USD]} == {[26 CHF][7 USD]} - Money[] bag= { new Money(26, "CHF"), new Money(7, "USD") }; - MoneyBag expected= new MoneyBag(bag); - Assert.AreEqual(expected, f14CHF.Add(fMB1)); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void SimpleMultiply() - { - // [14 CHF] *2 == [28 CHF] - Money expected= new Money(28, "CHF"); - Assert.AreEqual(expected, f14CHF.Multiply(2)); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void SimpleNegate() - { - // [14 CHF] negate == [-14 CHF] - Money expected= new Money(-14, "CHF"); - Assert.AreEqual(expected, f14CHF.Negate()); - } - - /// <summary> - /// - /// </summary> - /// - [Test] - public void SimpleSubtract() - { - // [14 CHF] - [12 CHF] == [2 CHF] - Money expected= new Money(2, "CHF"); - Assert.AreEqual(expected, f14CHF.Subtract(f12CHF)); - } - } -}
\ No newline at end of file diff --git a/tools/NUnit/samples/csharp/money/cs-money.build b/tools/NUnit/samples/csharp/money/cs-money.build deleted file mode 100644 index 917d973..0000000 --- a/tools/NUnit/samples/csharp/money/cs-money.build +++ /dev/null @@ -1,14 +0,0 @@ -<?xml version="1.0"?> -<project name="cs-money" default="build"> - - <include buildfile="../../samples.common" /> - - <patternset id="source-files"> - <include name="AssemblyInfo.cs" /> - <include name="IMoney.cs" /> - <include name="Money.cs" /> - <include name="MoneyBag.cs" /> - <include name="MoneyTest.cs" /> - </patternset> - -</project>
\ No newline at end of file diff --git a/tools/NUnit/samples/csharp/money/cs-money.csproj b/tools/NUnit/samples/csharp/money/cs-money.csproj deleted file mode 100644 index 1ccc7c9..0000000 --- a/tools/NUnit/samples/csharp/money/cs-money.csproj +++ /dev/null @@ -1,23 +0,0 @@ -<VisualStudioProject> - <CSHARP ProjectType="Local" ProductVersion="7.10.3077" SchemaVersion="2.0" ProjectGuid="{11EDF872-A04D-4F75-A1BF-71168DC86AF3}"> - <Build> - <Settings ApplicationIcon="" AssemblyKeyContainerName="" AssemblyName="cs-money" AssemblyOriginatorKeyFile="" DefaultClientScript="JScript" DefaultHTMLPageLayout="Grid" DefaultTargetSchema="IE50" DelaySign="false" OutputType="Library" PreBuildEvent="" PostBuildEvent="" RootNamespace="money" RunPostBuildEvent="OnBuildSuccess" StartupObject=""> - <Config Name="Debug" AllowUnsafeBlocks="false" BaseAddress="285212672" CheckForOverflowUnderflow="false" ConfigurationOverrideFile="" DefineConstants="DEBUG;TRACE" DocumentationFile="" DebugSymbols="true" FileAlignment="4096" IncrementalBuild="true" NoStdLib="false" NoWarn="" Optimize="false" OutputPath="bin\Debug\" RegisterForComInterop="false" RemoveIntegerChecks="false" TreatWarningsAsErrors="false" WarningLevel="4" /> - <Config Name="Release" AllowUnsafeBlocks="false" BaseAddress="285212672" CheckForOverflowUnderflow="false" ConfigurationOverrideFile="" DefineConstants="TRACE" DocumentationFile="" DebugSymbols="false" FileAlignment="4096" IncrementalBuild="false" NoStdLib="false" NoWarn="" Optimize="true" OutputPath="bin\Release\" RegisterForComInterop="false" RemoveIntegerChecks="false" TreatWarningsAsErrors="false" WarningLevel="4" /> - </Settings> - <References> - <Reference Name="System" AssemblyName="System" /> - <Reference Name="nunit.framework" AssemblyName="nunit.framework, Version=2.5, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" HintPath="..\..\..\bin\net-1.1\framework\nunit.framework.dll" /> - </References> - </Build> - <Files> - <Include> - <File RelPath="AssemblyInfo.cs" SubType="Code" BuildAction="Compile" /> - <File RelPath="IMoney.cs" SubType="Code" BuildAction="Compile" /> - <File RelPath="Money.cs" SubType="Code" BuildAction="Compile" /> - <File RelPath="MoneyBag.cs" SubType="Code" BuildAction="Compile" /> - <File RelPath="MoneyTest.cs" SubType="Code" BuildAction="Compile" /> - </Include> - </Files> - </CSHARP> -</VisualStudioProject>
\ No newline at end of file diff --git a/tools/NUnit/samples/csharp/syntax/AssemblyInfo.cs b/tools/NUnit/samples/csharp/syntax/AssemblyInfo.cs deleted file mode 100644 index 9f89a32..0000000 --- a/tools/NUnit/samples/csharp/syntax/AssemblyInfo.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -// -// 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. -// -[assembly: AssemblyTitle("")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// -// 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 Revision and Build Numbers -// by using the '*' as shown below: - -[assembly: AssemblyVersion("1.0.*")] - -// -// In order to sign your assembly you must specify a key to use. Refer to the -// Microsoft .NET Framework documentation for more information on assembly signing. -// -// Use the attributes below to control which key is used for signing. -// -// Notes: -// (*) If no key is specified, the assembly is not signed. -// (*) KeyName refers to a key that has been installed in the Crypto Service -// Provider (CSP) on your machine. KeyFile refers to a file which contains -// a key. -// (*) If the KeyFile and the KeyName values are both specified, the -// following processing occurs: -// (1) If the KeyName can be found in the CSP, that key is used. -// (2) If the KeyName does not exist and the KeyFile does exist, the key -// in the KeyFile is installed into the CSP and used. -// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. -// When specifying the KeyFile, the location of the KeyFile should be -// relative to the project output directory which is -// %Project Directory%\obj\<configuration>. For example, if your KeyFile is -// located in the project directory, you would specify the AssemblyKeyFile -// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] -// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework -// documentation for more information on this. -// -[assembly: AssemblyDelaySign(false)] -[assembly: AssemblyKeyFile("")] -[assembly: AssemblyKeyName("")] diff --git a/tools/NUnit/samples/csharp/syntax/AssertSyntaxTests.cs b/tools/NUnit/samples/csharp/syntax/AssertSyntaxTests.cs deleted file mode 100644 index b612580..0000000 --- a/tools/NUnit/samples/csharp/syntax/AssertSyntaxTests.cs +++ /dev/null @@ -1,828 +0,0 @@ -// **************************************************************** -// 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/?p=license&r=2.4 -// **************************************************************** - -using System; -using System.Collections; -using NUnit.Framework.Constraints; - -namespace NUnit.Framework.Tests -{ - /// <summary> - /// 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. - /// </summary> - [TestFixture] - public class AssertSyntaxTests : AssertionHelper - { - #region Simple Constraint Tests - [Test] - public void IsNull() - { - object nada = null; - - // Classic syntax - Assert.IsNull(nada); - - // Helper syntax - Assert.That(nada, Is.Null); - - // Inherited syntax - Expect(nada, Null); - } - - [Test] - public void IsNotNull() - { - // Classic syntax - Assert.IsNotNull(42); - - // Helper syntax - Assert.That(42, Is.Not.Null); - - // Inherited syntax - Expect( 42, Not.Null ); - } - - [Test] - public void IsTrue() - { - // Classic syntax - Assert.IsTrue(2+2==4); - - // Helper syntax - Assert.That(2+2==4, Is.True); - Assert.That(2+2==4); - - // Inherited syntax - Expect(2+2==4, True); - Expect(2+2==4); - } - - [Test] - public void IsFalse() - { - // Classic syntax - Assert.IsFalse(2+2==5); - - // Helper syntax - Assert.That(2+2== 5, Is.False); - - // Inherited syntax - Expect(2+2==5, False); - } - - [Test] - public void IsNaN() - { - double d = double.NaN; - float f = float.NaN; - - // Classic syntax - Assert.IsNaN(d); - Assert.IsNaN(f); - - // Helper syntax - Assert.That(d, Is.NaN); - Assert.That(f, Is.NaN); - - // Inherited syntax - Expect(d, NaN); - Expect(f, NaN); - } - - [Test] - public void EmptyStringTests() - { - // Classic syntax - Assert.IsEmpty(""); - Assert.IsNotEmpty("Hello!"); - - // Helper syntax - Assert.That("", Is.Empty); - Assert.That("Hello!", Is.Not.Empty); - - // Inherited syntax - Expect("", Empty); - Expect("Hello!", Not.Empty); - } - - [Test] - public void EmptyCollectionTests() - { - // Classic syntax - Assert.IsEmpty(new bool[0]); - Assert.IsNotEmpty(new int[] { 1, 2, 3 }); - - // Helper syntax - Assert.That(new bool[0], Is.Empty); - Assert.That(new int[] { 1, 2, 3 }, Is.Not.Empty); - - // Inherited syntax - Expect(new bool[0], Empty); - Expect(new int[] { 1, 2, 3 }, Not.Empty); - } - #endregion - - #region TypeConstraint Tests - [Test] - public void ExactTypeTests() - { - // Classic syntax workarounds - Assert.AreEqual(typeof(string), "Hello".GetType()); - Assert.AreEqual("System.String", "Hello".GetType().FullName); - Assert.AreNotEqual(typeof(int), "Hello".GetType()); - Assert.AreNotEqual("System.Int32", "Hello".GetType().FullName); - - // Helper syntax - Assert.That("Hello", Is.TypeOf(typeof(string))); - Assert.That("Hello", Is.Not.TypeOf(typeof(int))); - - // Inherited syntax - Expect( "Hello", TypeOf(typeof(string))); - Expect( "Hello", Not.TypeOf(typeof(int))); - } - - [Test] - public void InstanceOfTypeTests() - { - // Classic syntax - Assert.IsInstanceOf(typeof(string), "Hello"); - Assert.IsNotInstanceOf(typeof(string), 5); - - // Helper syntax - Assert.That("Hello", Is.InstanceOf(typeof(string))); - Assert.That(5, Is.Not.InstanceOf(typeof(string))); - - // Inherited syntax - Expect("Hello", InstanceOf(typeof(string))); - Expect(5, Not.InstanceOf(typeof(string))); - } - - [Test] - public void AssignableFromTypeTests() - { - // Classic syntax - Assert.IsAssignableFrom(typeof(string), "Hello"); - Assert.IsNotAssignableFrom(typeof(string), 5); - - // Helper syntax - Assert.That( "Hello", Is.AssignableFrom(typeof(string))); - Assert.That( 5, Is.Not.AssignableFrom(typeof(string))); - - // Inherited syntax - Expect( "Hello", AssignableFrom(typeof(string))); - Expect( 5, Not.AssignableFrom(typeof(string))); - } - #endregion - - #region StringConstraint Tests - [Test] - public void SubstringTests() - { - string phrase = "Hello World!"; - string[] array = new string[] { "abc", "bad", "dba" }; - - // Classic Syntax - StringAssert.Contains("World", phrase); - - // Helper syntax - Assert.That(phrase, Text.Contains("World")); - // Only available using new syntax - Assert.That(phrase, Text.DoesNotContain("goodbye")); - Assert.That(phrase, Text.Contains("WORLD").IgnoreCase); - Assert.That(phrase, Text.DoesNotContain("BYE").IgnoreCase); - Assert.That(array, Text.All.Contains( "b" ) ); - - // Inherited syntax - Expect(phrase, Contains("World")); - // Only available using new syntax - Expect(phrase, Not.Contains("goodbye")); - Expect(phrase, Contains("WORLD").IgnoreCase); - Expect(phrase, Not.Contains("BYE").IgnoreCase); - Expect(array, All.Contains("b")); - } - - [Test] - public void StartsWithTests() - { - string phrase = "Hello World!"; - string[] greetings = new string[] { "Hello!", "Hi!", "Hola!" }; - - // Classic syntax - StringAssert.StartsWith("Hello", phrase); - - // Helper syntax - Assert.That(phrase, Text.StartsWith("Hello")); - // Only available using new syntax - Assert.That(phrase, Text.DoesNotStartWith("Hi!")); - Assert.That(phrase, Text.StartsWith("HeLLo").IgnoreCase); - Assert.That(phrase, Text.DoesNotStartWith("HI").IgnoreCase); - Assert.That(greetings, Text.All.StartsWith("h").IgnoreCase); - - // Inherited syntax - Expect(phrase, StartsWith("Hello")); - // Only available using new syntax - Expect(phrase, Not.StartsWith("Hi!")); - Expect(phrase, StartsWith("HeLLo").IgnoreCase); - Expect(phrase, Not.StartsWith("HI").IgnoreCase); - Expect(greetings, All.StartsWith("h").IgnoreCase); - } - - [Test] - public void EndsWithTests() - { - string phrase = "Hello World!"; - string[] greetings = new string[] { "Hello!", "Hi!", "Hola!" }; - - // Classic Syntax - StringAssert.EndsWith("!", phrase); - - // Helper syntax - Assert.That(phrase, Text.EndsWith("!")); - // Only available using new syntax - Assert.That(phrase, Text.DoesNotEndWith("?")); - Assert.That(phrase, Text.EndsWith("WORLD!").IgnoreCase); - Assert.That(greetings, Text.All.EndsWith("!")); - - // Inherited syntax - Expect(phrase, EndsWith("!")); - // Only available using new syntax - Expect(phrase, Not.EndsWith("?")); - Expect(phrase, EndsWith("WORLD!").IgnoreCase); - Expect(greetings, All.EndsWith("!") ); - } - - [Test] - public void EqualIgnoringCaseTests() - { - string phrase = "Hello World!"; - - // Classic syntax - StringAssert.AreEqualIgnoringCase("hello world!",phrase); - - // Helper syntax - Assert.That(phrase, Is.EqualTo("hello world!").IgnoreCase); - //Only available using new syntax - Assert.That(phrase, Is.Not.EqualTo("goodbye world!").IgnoreCase); - Assert.That(new string[] { "Hello", "World" }, - Is.EqualTo(new object[] { "HELLO", "WORLD" }).IgnoreCase); - Assert.That(new string[] {"HELLO", "Hello", "hello" }, - Is.All.EqualTo( "hello" ).IgnoreCase); - - // Inherited syntax - Expect(phrase, EqualTo("hello world!").IgnoreCase); - //Only available using new syntax - Expect(phrase, Not.EqualTo("goodbye world!").IgnoreCase); - Expect(new string[] { "Hello", "World" }, - EqualTo(new object[] { "HELLO", "WORLD" }).IgnoreCase); - Expect(new string[] {"HELLO", "Hello", "hello" }, - All.EqualTo( "hello" ).IgnoreCase); - } - - [Test] - public void RegularExpressionTests() - { - string phrase = "Now is the time for all good men to come to the aid of their country."; - string[] quotes = 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, Text.Matches( "all good men" ) ); - Assert.That( phrase, Text.Matches( "Now.*come" ) ); - // Only available using new syntax - Assert.That(phrase, Text.DoesNotMatch("all.*men.*good")); - Assert.That(phrase, Text.Matches("ALL").IgnoreCase); - Assert.That(quotes, Text.All.Matches("never").IgnoreCase); - - // Inherited syntax - Expect( phrase, Matches( "all good men" ) ); - Expect( phrase, Matches( "Now.*come" ) ); - // Only available using new syntax - Expect(phrase, Not.Matches("all.*men.*good")); - Expect(phrase, Matches("ALL").IgnoreCase); - Expect(quotes, All.Matches("never").IgnoreCase); - } - #endregion - - #region Equality Tests - [Test] - public void EqualityTests() - { - int[] i3 = new int[] { 1, 2, 3 }; - double[] d3 = new double[] { 1.0, 2.0, 3.0 }; - int[] iunequal = new int[] { 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, Is.EqualTo(4)); - Assert.That(2 + 2 == 4); - Assert.That(i3, Is.EqualTo(d3)); - Assert.That(2 + 2, Is.Not.EqualTo(5)); - Assert.That(i3, Is.Not.EqualTo(iunequal)); - - // Inherited syntax - Expect(2 + 2, EqualTo(4)); - Expect(2 + 2 == 4); - Expect(i3, EqualTo(d3)); - Expect(2 + 2, Not.EqualTo(5)); - Expect(i3, Not.EqualTo(iunequal)); - } - - [Test] - public void EqualityTestsWithTolerance() - { - // CLassic syntax - Assert.AreEqual(5.0d, 4.99d, 0.05d); - Assert.AreEqual(5.0f, 4.99f, 0.05f); - - // Helper syntax - Assert.That(4.99d, Is.EqualTo(5.0d).Within(0.05d)); - Assert.That(4.0d, Is.Not.EqualTo(5.0d).Within(0.5d)); - Assert.That(4.99f, Is.EqualTo(5.0f).Within(0.05f)); - Assert.That(4.99m, Is.EqualTo(5.0m).Within(0.05m)); - Assert.That(3999999999u, Is.EqualTo(4000000000u).Within(5u)); - Assert.That(499, Is.EqualTo(500).Within(5)); - Assert.That(4999999999L, Is.EqualTo(5000000000L).Within(5L)); - Assert.That(5999999999ul, Is.EqualTo(6000000000ul).Within(5ul)); - - // Inherited syntax - Expect(4.99d, EqualTo(5.0d).Within(0.05d)); - Expect(4.0d, Not.EqualTo(5.0d).Within(0.5d)); - Expect(4.99f, EqualTo(5.0f).Within(0.05f)); - Expect(4.99m, EqualTo(5.0m).Within(0.05m)); - Expect(499u, EqualTo(500u).Within(5u)); - Expect(499, EqualTo(500).Within(5)); - Expect(4999999999L, EqualTo(5000000000L).Within(5L)); - Expect(5999999999ul, EqualTo(6000000000ul).Within(5ul)); - } - - [Test] - public void EqualityTestsWithTolerance_MixedFloatAndDouble() - { - // Bug Fix 1743844 - Assert.That(2.20492d, Is.EqualTo(2.2d).Within(0.01f), - "Double actual, Double expected, Single tolerance"); - Assert.That(2.20492d, Is.EqualTo(2.2f).Within(0.01d), - "Double actual, Single expected, Double tolerance" ); - Assert.That(2.20492d, Is.EqualTo(2.2f).Within(0.01f), - "Double actual, Single expected, Single tolerance" ); - Assert.That(2.20492f, Is.EqualTo(2.2f).Within(0.01d), - "Single actual, Single expected, Double tolerance"); - Assert.That(2.20492f, Is.EqualTo(2.2d).Within(0.01d), - "Single actual, Double expected, Double tolerance"); - Assert.That(2.20492f, Is.EqualTo(2.2d).Within(0.01f), - "Single actual, Double expected, Single tolerance"); - } - - [Test] - public void EqualityTestsWithTolerance_MixingTypesGenerally() - { - // Extending tolerance to all numeric types - Assert.That(202d, Is.EqualTo(200d).Within(2), - "Double actual, Double expected, int tolerance"); - Assert.That( 4.87m, Is.EqualTo(5).Within(.25), - "Decimal actual, int expected, Double tolerance" ); - Assert.That( 4.87m, Is.EqualTo(5ul).Within(1), - "Decimal actual, ulong expected, int tolerance" ); - Assert.That( 487, Is.EqualTo(500).Within(25), - "int actual, int expected, int tolerance" ); - Assert.That( 487u, Is.EqualTo(500).Within(25), - "uint actual, int expected, int tolerance" ); - Assert.That( 487L, Is.EqualTo(500).Within(25), - "long actual, int expected, int tolerance" ); - Assert.That( 487ul, Is.EqualTo(500).Within(25), - "ulong actual, int expected, int tolerance" ); - } - #endregion - - #region Comparison Tests - [Test] - public void ComparisonTests() - { - // Classic Syntax - Assert.Greater(7, 3); - Assert.GreaterOrEqual(7, 3); - Assert.GreaterOrEqual(7, 7); - - // Helper syntax - Assert.That(7, Is.GreaterThan(3)); - Assert.That(7, Is.GreaterThanOrEqualTo(3)); - Assert.That(7, Is.AtLeast(3)); - Assert.That(7, Is.GreaterThanOrEqualTo(7)); - Assert.That(7, Is.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, Is.LessThan(7)); - Assert.That(3, Is.LessThanOrEqualTo(7)); - Assert.That(3, Is.AtMost(7)); - Assert.That(3, Is.LessThanOrEqualTo(3)); - Assert.That(3, Is.AtMost(3)); - - // Inherited syntax - Expect(3, LessThan(7)); - Expect(3, LessThanOrEqualTo(7)); - Expect(3, AtMost(7)); - Expect(3, LessThanOrEqualTo(3)); - Expect(3, AtMost(3)); - } - #endregion - - #region Collection Tests - [Test] - public void AllItemsTests() - { - object[] ints = new object[] { 1, 2, 3, 4 }; - object[] doubles = new object[] { 0.99, 2.1, 3.0, 4.05 }; - object[] strings = new object[] { "abc", "bad", "cab", "bad", "dad" }; - - // Classic syntax - CollectionAssert.AllItemsAreNotNull(ints); - CollectionAssert.AllItemsAreInstancesOfType(ints, typeof(int)); - CollectionAssert.AllItemsAreInstancesOfType(strings, typeof(string)); - CollectionAssert.AllItemsAreUnique(ints); - - // Helper syntax - Assert.That(ints, Is.All.Not.Null); - Assert.That(ints, Has.None.Null); - Assert.That(ints, Is.All.InstanceOfType(typeof(int))); - Assert.That(ints, Has.All.InstanceOfType(typeof(int))); - Assert.That(strings, Is.All.InstanceOfType(typeof(string))); - Assert.That(strings, Has.All.InstanceOfType(typeof(string))); - Assert.That(ints, Is.Unique); - // Only available using new syntax - Assert.That(strings, Is.Not.Unique); - Assert.That(ints, Is.All.GreaterThan(0)); - Assert.That(ints, Has.All.GreaterThan(0)); - Assert.That(ints, Has.None.LessThanOrEqualTo(0)); - Assert.That(strings, Text.All.Contains( "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( .05 ) ); - - // Inherited syntax - Expect(ints, All.Not.Null); - Expect(ints, None.Null); - Expect(ints, All.InstanceOfType(typeof(int))); - Expect(strings, All.InstanceOfType(typeof(string))); - Expect(ints, Unique); - // Only available using new syntax - Expect(strings, Not.Unique); - Expect(ints, All.GreaterThan(0)); - Expect(ints, None.LessThanOrEqualTo(0)); - Expect(strings, All.Contains( "a" ) ); - Expect(strings, Some.StartsWith( "ba" ) ); - Expect(strings, Some.StartsWith( "BA" ).IgnoreCase ); - Expect(doubles, Some.EqualTo( 1.0 ).Within( .05 ) ); - } - - [Test] - public void SomeItemTests() - { - object[] mixed = new object[] { 1, 2, "3", null, "four", 100 }; - object[] strings = new 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.InstanceOfType(typeof(int))); - Assert.That(mixed, Has.Some.InstanceOfType(typeof(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.InstanceOfType(typeof(int))); - Expect(mixed, Some.InstanceOfType(typeof(string))); - Expect(strings, Some.StartsWith( "ba" ) ); - Expect(strings, Some.Not.StartsWith( "ba" ) ); - } - - [Test] - public void NoItemTests() - { - object[] ints = new object[] { 1, 2, 3, 4, 5 }; - object[] strings = new 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.InstanceOfType(typeof(string))); - Assert.That(ints, Has.None.GreaterThan(99)); - Assert.That(strings, Has.None.StartsWith( "qu" ) ); - - // Inherited syntax - Expect(ints, None.Null); - Expect(ints, None.InstanceOfType(typeof(string))); - Expect(ints, None.GreaterThan(99)); - Expect(strings, None.StartsWith( "qu" ) ); - } - - [Test] - public void CollectionContainsTests() - { - int[] iarray = new int[] { 1, 2, 3 }; - string[] sarray = new 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.0d ); - - // 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.0d )); - - // 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.0d )); - 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, Not.Contains("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)); - } - - [Test] - public void CollectionEquivalenceTests() - { - int[] ints1to5 = new int[] { 1, 2, 3, 4, 5 }; - int[] twothrees = new int[] { 1, 2, 3, 3, 4, 5 }; - int[] twofours = new int[] { 1, 2, 3, 4, 4, 5 }; - - // Classic syntax - CollectionAssert.AreEquivalent(new int[] { 2, 1, 4, 3, 5 }, ints1to5); - CollectionAssert.AreNotEquivalent(new int[] { 2, 2, 4, 3, 5 }, ints1to5); - CollectionAssert.AreNotEquivalent(new int[] { 2, 4, 3, 5 }, ints1to5); - CollectionAssert.AreNotEquivalent(new int[] { 2, 2, 1, 1, 4, 3, 5 }, ints1to5); - CollectionAssert.AreNotEquivalent(twothrees, twofours); - - // Helper syntax - Assert.That(new int[] { 2, 1, 4, 3, 5 }, Is.EquivalentTo(ints1to5)); - Assert.That(new int[] { 2, 2, 4, 3, 5 }, Is.Not.EquivalentTo(ints1to5)); - Assert.That(new int[] { 2, 4, 3, 5 }, Is.Not.EquivalentTo(ints1to5)); - Assert.That(new int[] { 2, 2, 1, 1, 4, 3, 5 }, Is.Not.EquivalentTo(ints1to5)); - - // Inherited syntax - Expect(new int[] { 2, 1, 4, 3, 5 }, EquivalentTo(ints1to5)); - Expect(new int[] { 2, 2, 4, 3, 5 }, Not.EquivalentTo(ints1to5)); - Expect(new int[] { 2, 4, 3, 5 }, Not.EquivalentTo(ints1to5)); - Expect(new int[] { 2, 2, 1, 1, 4, 3, 5 }, Not.EquivalentTo(ints1to5)); - } - - [Test] - public void SubsetTests() - { - int[] ints1to5 = new int[] { 1, 2, 3, 4, 5 }; - - // Classic syntax - CollectionAssert.IsSubsetOf(new int[] { 1, 3, 5 }, ints1to5); - CollectionAssert.IsSubsetOf(new int[] { 1, 2, 3, 4, 5 }, ints1to5); - CollectionAssert.IsNotSubsetOf(new int[] { 2, 4, 6 }, ints1to5); - CollectionAssert.IsNotSubsetOf(new int[] { 1, 2, 2, 2, 5 }, ints1to5); - - // Helper syntax - Assert.That(new int[] { 1, 3, 5 }, Is.SubsetOf(ints1to5)); - Assert.That(new int[] { 1, 2, 3, 4, 5 }, Is.SubsetOf(ints1to5)); - Assert.That(new int[] { 2, 4, 6 }, Is.Not.SubsetOf(ints1to5)); - - // Inherited syntax - Expect(new int[] { 1, 3, 5 }, SubsetOf(ints1to5)); - Expect(new int[] { 1, 2, 3, 4, 5 }, SubsetOf(ints1to5)); - Expect(new int[] { 2, 4, 6 }, Not.SubsetOf(ints1to5)); - } - #endregion - - #region Property Tests - [Test] - public void PropertyTests() - { - string[] array = { "abc", "bca", "xyz", "qrs" }; - string[] array2 = { "a", "ab", "abc" }; - ArrayList list = 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.Length.LessThan( 10 ) ); - 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, Is.All.Length.EqualTo( 3 ) ); - Assert.That( array, Has.All.Property("Length").EqualTo(3) ); - Assert.That( array, Is.All.Property("Length").EqualTo(3) ); - - Assert.That( array2, Has.Some.Property("Length").EqualTo(2) ); - Assert.That( array2, Has.Some.Length.EqualTo(2) ); - Assert.That( array2, Has.Some.Property("Length").GreaterThan(2) ); - - Assert.That( array2, Is.Not.Property("Length").EqualTo(4) ); - Assert.That( array2, Is.Not.Length.EqualTo( 4 ) ); - Assert.That( array2, Has.No.Property("Length").GreaterThan(3) ); - - Assert.That( List.Map( array2 ).Property("Length"), Is.EqualTo( new int[] { 1, 2, 3 } ) ); - Assert.That( List.Map( array2 ).Property("Length"), Is.EquivalentTo( new int[] { 3, 2, 1 } ) ); - Assert.That( List.Map( array2 ).Property("Length"), Is.SubsetOf( new int[] { 1, 2, 3, 4, 5 } ) ); - Assert.That( List.Map( array2 ).Property("Length"), Is.Unique ); - - Assert.That( list, Has.Count.EqualTo( 4 ) ); - - // Inherited syntax - Expect( list, Property( "Count" ) ); - Expect( list, Not.Property( "Nada" ) ); - - Expect( "Hello", Length.EqualTo( 5 ) ); - Expect( "Hello", Property("Length").EqualTo(5) ); - Expect( "Hello", Property("Length").GreaterThan(0) ); - - Expect( array, Property("Length").EqualTo(4) ); - Expect( array, Length.EqualTo(4) ); - Expect( array, Property("Length").LessThan(10)); - - Expect( array, All.Length.EqualTo( 3 ) ); - Expect( array, All.Property("Length").EqualTo(3)); - - Expect( array2, Some.Property("Length").EqualTo(2) ); - Expect( array2, Some.Length.EqualTo( 2 ) ); - Expect( array2, Some.Property("Length").GreaterThan(2)); - - Expect( array2, None.Property("Length").EqualTo(4) ); - Expect( array2, None.Length.EqualTo( 4 ) ); - Expect( array2, None.Property("Length").GreaterThan(3)); - - Expect( Map( array2 ).Property("Length"), EqualTo( new int[] { 1, 2, 3 } ) ); - Expect( Map( array2 ).Property("Length"), EquivalentTo( new int[] { 3, 2, 1 } ) ); - Expect( Map( array2 ).Property("Length"), SubsetOf( new int[] { 1, 2, 3, 4, 5 } ) ); - Expect( Map( array2 ).Property("Length"), Unique ); - - Expect( list, Count.EqualTo( 4 ) ); - - } - #endregion - - #region Not Tests - [Test] - public void NotTests() - { - // Not available using the classic syntax - - // Helper syntax - Assert.That(42, Is.Not.Null); - Assert.That(42, Is.Not.True); - Assert.That(42, Is.Not.False); - Assert.That(2.5, Is.Not.NaN); - Assert.That(2 + 2, Is.Not.EqualTo(3)); - Assert.That(2 + 2, Is.Not.Not.EqualTo(4)); - Assert.That(2 + 2, Is.Not.Not.Not.EqualTo(5)); - - // Inherited syntax - Expect(42, Not.Null); - Expect(42, Not.True); - Expect(42, Not.False); - Expect(2.5, Not.NaN); - Expect(2 + 2, Not.EqualTo(3)); - Expect(2 + 2, Not.Not.EqualTo(4)); - Expect(2 + 2, Not.Not.Not.EqualTo(5)); - } - #endregion - - #region Operator Tests - [Test] - public void NotOperator() - { - // The ! operator is only available in the new syntax - Assert.That(42, !Is.Null); - // Inherited syntax - Expect( 42, !Null ); - } - - [Test] - public void AndOperator() - { - // The & operator is only available in the new syntax - Assert.That(7, Is.GreaterThan(5) & Is.LessThan(10)); - // Inherited syntax - Expect( 7, GreaterThan(5) & LessThan(10)); - } - - [Test] - public void OrOperator() - { - // The | operator is only available in the new syntax - Assert.That(3, Is.LessThan(5) | Is.GreaterThan(10)); - Expect( 3, LessThan(5) | GreaterThan(10)); - } - - [Test] - public void ComplexTests() - { - Assert.That(7, Is.Not.Null & Is.Not.LessThan(5) & Is.Not.GreaterThan(10)); - Expect(7, Not.Null & Not.LessThan(5) & Not.GreaterThan(10)); - - Assert.That(7, !Is.Null & !Is.LessThan(5) & !Is.GreaterThan(10)); - Expect(7, !Null & !LessThan(5) & !GreaterThan(10)); - - // TODO: Remove #if when mono compiler can handle null -#if MONO - Constraint x = null; - Assert.That(7, !x & !Is.LessThan(5) & !Is.GreaterThan(10)); - Expect(7, !x & !LessThan(5) & !GreaterThan(10)); -#else - Assert.That(7, !(Constraint)null & !Is.LessThan(5) & !Is.GreaterThan(10)); - Expect(7, !(Constraint)null & !LessThan(5) & !GreaterThan(10)); -#endif - } - #endregion - - #region Invalid Code Tests - // This method contains assertions that should not compile - // You can check by uncommenting it. - //public void WillNotCompile() - //{ - // Assert.That(42, Is.Not); - // Assert.That(42, Is.All); - // Assert.That(42, Is.Null.Not); - // Assert.That(42, Is.Not.Null.GreaterThan(10)); - // Assert.That(42, Is.GreaterThan(10).LessThan(99)); - - // object[] c = new object[0]; - // Assert.That(c, Is.Null.All); - // Assert.That(c, Is.Not.All); - // Assert.That(c, Is.All.Not); - //} - #endregion - } - -} diff --git a/tools/NUnit/samples/csharp/syntax/cs-syntax.build b/tools/NUnit/samples/csharp/syntax/cs-syntax.build deleted file mode 100644 index c144588..0000000 --- a/tools/NUnit/samples/csharp/syntax/cs-syntax.build +++ /dev/null @@ -1,11 +0,0 @@ -<?xml version="1.0"?> -<project name="cs-syntax" default="build"> - - <include buildfile="../../samples.common" /> - - <patternset id="source-files"> - <include name="AssemblyInfo.cs" /> - <include name="AssertSyntaxTests.cs" /> - </patternset> - -</project>
\ No newline at end of file diff --git a/tools/NUnit/samples/csharp/syntax/cs-syntax.csproj b/tools/NUnit/samples/csharp/syntax/cs-syntax.csproj deleted file mode 100644 index b3970c7..0000000 --- a/tools/NUnit/samples/csharp/syntax/cs-syntax.csproj +++ /dev/null @@ -1,20 +0,0 @@ -<VisualStudioProject> - <CSHARP ProjectType="Local" ProductVersion="7.10.3077" SchemaVersion="2.0" ProjectGuid="{06F46FA2-687B-4B46-A912-C1B0B4CC1B20}"> - <Build> - <Settings ApplicationIcon="" AssemblyKeyContainerName="" AssemblyName="cs-syntax" AssemblyOriginatorKeyFile="" DefaultClientScript="JScript" DefaultHTMLPageLayout="Grid" DefaultTargetSchema="IE50" DelaySign="false" OutputType="Library" PreBuildEvent="" PostBuildEvent="" RootNamespace="cs_syntax" RunPostBuildEvent="OnBuildSuccess" StartupObject=""> - <Config Name="Debug" AllowUnsafeBlocks="false" BaseAddress="285212672" CheckForOverflowUnderflow="false" ConfigurationOverrideFile="" DefineConstants="DEBUG;TRACE" DocumentationFile="" DebugSymbols="true" FileAlignment="4096" IncrementalBuild="false" NoStdLib="false" NoWarn="" Optimize="false" OutputPath="bin\Debug\" RegisterForComInterop="false" RemoveIntegerChecks="false" TreatWarningsAsErrors="false" WarningLevel="4" /> - <Config Name="Release" AllowUnsafeBlocks="false" BaseAddress="285212672" CheckForOverflowUnderflow="false" ConfigurationOverrideFile="" DefineConstants="TRACE" DocumentationFile="" DebugSymbols="false" FileAlignment="4096" IncrementalBuild="false" NoStdLib="false" NoWarn="" Optimize="true" OutputPath="bin\Release\" RegisterForComInterop="false" RemoveIntegerChecks="false" TreatWarningsAsErrors="false" WarningLevel="4" /> - </Settings> - <References> - <Reference Name="System" AssemblyName="System" /> - <Reference Name="nunit.framework" AssemblyName="nunit.framework, Version=2.5, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" HintPath="..\..\..\bin\net-1.1\framework\nunit.framework.dll" /> - </References> - </Build> - <Files> - <Include> - <File RelPath="AssemblyInfo.cs" SubType="Code" BuildAction="Compile" /> - <File RelPath="AssertSyntaxTests.cs" SubType="Code" BuildAction="Compile" /> - </Include> - </Files> - </CSHARP> -</VisualStudioProject>
\ No newline at end of file |