diff options
Diffstat (limited to 'src/test/Cmpp298.Assignment3.Test')
10 files changed, 616 insertions, 0 deletions
diff --git a/src/test/Cmpp298.Assignment3.Test/App.config b/src/test/Cmpp298.Assignment3.Test/App.config new file mode 100644 index 0000000..370bfe9 --- /dev/null +++ b/src/test/Cmpp298.Assignment3.Test/App.config @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <connectionStrings>
+ <add name="PayablesConnection" connectionString="data source=(local);Integrated Security=SSPI;Initial Catalog=Payables;" providerName="System.Data.SqlClient" />
+ </connectionStrings>
+</configuration>
\ No newline at end of file diff --git a/src/test/Cmpp298.Assignment3.Test/Cmpp298.Assignment3.Test.csproj b/src/test/Cmpp298.Assignment3.Test/Cmpp298.Assignment3.Test.csproj new file mode 100644 index 0000000..fab4c06 --- /dev/null +++ b/src/test/Cmpp298.Assignment3.Test/Cmpp298.Assignment3.Test.csproj @@ -0,0 +1,82 @@ +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.50727</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{C9135CE2-7960-4E21-ACE8-2769BEF35C01}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Cmpp298.Assignment3.Test</RootNamespace>
+ <AssemblyName>Cmpp298.Assignment3.Test</AssemblyName>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="MbUnit.Framework, Version=1.0.2700.29885, Culture=neutral, PublicKeyToken=5e72ecd30bc408d5">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\..\tools\MbUnit\MbUnit.Framework.dll</HintPath>
+ </Reference>
+ <Reference Include="Rhino.Mocks, Version=3.1.0.584, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\..\tools\rhinomocks\Rhino.Mocks.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Dto\SaveInvoiceDtoTest.cs" />
+ <Compile Include="Presentation\DeleteInvoicePresenterTest.cs" />
+ <Compile Include="Presentation\EditInvoicePresenterTest.cs" />
+ <Compile Include="Task\InvoiceTaskTest.cs" />
+ <Compile Include="Presentation\NewInvoicePresenterTest.cs" />
+ <Compile Include="Presentation\InvoicesMainPresenterTest.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Task\VendorTaskTest.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\app\Cmpp298.Assignment3.DataAccess\Cmpp298.Assignment3.DataAccess.csproj">
+ <Project>{48B09B0E-F2D5-463D-9FAB-C1781CA46D4D}</Project>
+ <Name>Cmpp298.Assignment3.DataAccess</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\..\app\Cmpp298.Assignment3.Desktop.Presentation\Cmpp298.Assignment3.Desktop.Presentation.csproj">
+ <Project>{62EA2002-B0ED-4E9C-945E-B77552A0669C}</Project>
+ <Name>Cmpp298.Assignment3.Desktop.Presentation</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\..\app\Cmpp298.Assignment3.Dto\Cmpp298.Assignment3.Dto.csproj">
+ <Project>{29260A8E-3F7B-4D9B-BBE3-81210F4B9E5B}</Project>
+ <Name>Cmpp298.Assignment3.Dto</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\..\app\Cmpp298.Assignment3.Task\Cmpp298.Assignment3.Task.csproj">
+ <Project>{A747CA6E-EEA1-42E0-BA90-69317F8BF45D}</Project>
+ <Name>Cmpp298.Assignment3.Task</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config" />
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
\ No newline at end of file diff --git a/src/test/Cmpp298.Assignment3.Test/Dto/SaveInvoiceDtoTest.cs b/src/test/Cmpp298.Assignment3.Test/Dto/SaveInvoiceDtoTest.cs new file mode 100644 index 0000000..f01025b --- /dev/null +++ b/src/test/Cmpp298.Assignment3.Test/Dto/SaveInvoiceDtoTest.cs @@ -0,0 +1,33 @@ +using Cmpp298.Assignment3.Dto;
+using MbUnit.Framework;
+
+namespace Cmpp298.Assignment3.Test.Dto {
+ [TestFixture]
+ public class SaveInvoiceDtoTest {
+ [Test]
+ public void Should_Be_Equal( ) {
+ SaveInvoiceDto dto1 = new SaveInvoiceDto( "1", "QP58872", "1/5/2007 12:00:00 AM", "116.5400", "116.5400", "0.0000",
+ "3/4/2007 12:00:00 AM",
+ "2/22/2007 12:00:00 AM", "4" );
+
+ SaveInvoiceDto dto2 = new SaveInvoiceDto( "1", "QP58872", "1/5/2007 12:00:00 AM", "116.5400", "116.5400", "0.0000",
+ "3/4/2007 12:00:00 AM",
+ "2/22/2007 12:00:00 AM", "4" );
+
+ Assert.IsTrue( dto1.Equals( dto2 ), "Both dtos Should be equal" );
+ }
+
+ [Test]
+ public void Should_Not_Be_Equal( ) {
+ SaveInvoiceDto dto1 = new SaveInvoiceDto( "1", "QP58872", "1/5/2007 12:00:00 AM", "116.5400", "116.5400", "0.0000",
+ "3/4/2007 12:00:00 AM",
+ "2/22/2007 12:00:00 AM", "4" );
+
+ SaveInvoiceDto dto2 = new SaveInvoiceDto( "2", "QP58872", "1/5/2007 12:00:00 AM", "116.5400", "116.5400", "0.0000",
+ "3/4/2007 12:00:00 AM",
+ "2/22/2007 12:00:00 AM", "4" );
+
+ Assert.IsTrue( !dto1.Equals( dto2 ), "Both dtos Should not be equal" );
+ }
+ }
+}
\ No newline at end of file diff --git a/src/test/Cmpp298.Assignment3.Test/Presentation/DeleteInvoicePresenterTest.cs b/src/test/Cmpp298.Assignment3.Test/Presentation/DeleteInvoicePresenterTest.cs new file mode 100644 index 0000000..f0ce644 --- /dev/null +++ b/src/test/Cmpp298.Assignment3.Test/Presentation/DeleteInvoicePresenterTest.cs @@ -0,0 +1,59 @@ +using Cmpp298.Assignment3.Dto;
+using Cmpp298.Assignment3.Presentation;
+using Cmpp298.Assignment3.Task;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Cmpp298.Assignment3.Test.Presentation {
+ [TestFixture]
+ public class DeleteInvoicePresenterTest {
+ private MockRepository _mockery;
+ private IDeleteInvoiceView _view;
+ private IInvoiceTask _invoiceTask;
+
+ [SetUp]
+ public void SetUp( ) {
+ _mockery = new MockRepository( );
+ _view = _mockery.Stub< IDeleteInvoiceView >( );
+ _invoiceTask = _mockery.Stub< IInvoiceTask >( );
+ }
+
+ [Test]
+ public void Should_Load_Invoice_Details_On_Load( ) {
+ string invoiceId = "1";
+ using ( _mockery.Record( ) ) {
+ Expect.Call( _invoiceTask.GetInvoiceBy( invoiceId ) ).Return(
+ new DisplayInvoiceDto( invoiceId, "IBM", "12", "date", "total", "12.12", "12.12", "10 days", "due date",
+ "payment date" ) );
+
+ _view.VendorName = "IBM";
+ _view.InvoiceNumber = "12";
+ _view.InvoiceDate = "date";
+ _view.InvoiceTotal = "total";
+ _view.PaymentTotal = "12.12";
+ _view.CreditTotal = "12.12";
+ _view.DueDate = "due date";
+ _view.PaymentDate = "payment date";
+ _view.Terms = "10 days";
+ }
+ using ( _mockery.Playback( ) ) {
+ CreateSut( invoiceId ).Initialize( );
+ }
+ }
+
+ [Test]
+ public void Should_Delete_Invoice_On_Delete_Click( ) {
+ const string invoiceId = "1";
+ using ( _mockery.Record( ) ) {
+ _invoiceTask.DeleteInvoice( invoiceId );
+ }
+ using ( _mockery.Playback( ) ) {
+ CreateSut( invoiceId ).DeleteInvoice( );
+ }
+ }
+
+ private DeleteInvoicePresenter CreateSut( string invoiceId ) {
+ return new DeleteInvoicePresenter( invoiceId, _view, _invoiceTask );
+ }
+ }
+}
\ No newline at end of file diff --git a/src/test/Cmpp298.Assignment3.Test/Presentation/EditInvoicePresenterTest.cs b/src/test/Cmpp298.Assignment3.Test/Presentation/EditInvoicePresenterTest.cs new file mode 100644 index 0000000..3f88a33 --- /dev/null +++ b/src/test/Cmpp298.Assignment3.Test/Presentation/EditInvoicePresenterTest.cs @@ -0,0 +1,85 @@ +using System.Collections.Generic;
+using Cmpp298.Assignment3.Dto;
+using Cmpp298.Assignment3.Presentation;
+using Cmpp298.Assignment3.Task;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Cmpp298.Assignment3.Test.Presentation {
+ [TestFixture]
+ public class EditInvoicePresenterTest {
+ private MockRepository _mockery;
+ private IEditInvoiceView _view;
+ private IInvoiceTask _task;
+ private ITermTask _termTask;
+ private IDropDownListAdapter _termsDropDown;
+
+ [SetUp]
+ public void Setup( ) {
+ _mockery = new MockRepository( );
+ _view = _mockery.CreateMock< IEditInvoiceView >( );
+ _task = _mockery.CreateMock< IInvoiceTask >( );
+ _termTask = _mockery.CreateMock< ITermTask >( );
+ _termsDropDown = _mockery.CreateMock< IDropDownListAdapter >( );
+
+ SetupResult.For( _view.TermsDropDown ).Return( _termsDropDown );
+ }
+
+ [Test]
+ public void Should_Load_Invoice_Details_On_Load( ) {
+ const string invoiceId = "1";
+ IList< IDropDownListItem > items = new List< IDropDownListItem >( );
+ items.Add( new DropDownListItem( "10 days", "1" ) );
+
+ using ( _mockery.Record( ) ) {
+ Expect.Call( _task.GetInvoiceBy( invoiceId ) ).Return(
+ new DisplayInvoiceDto( invoiceId, "vendor", "number", "date", "total", "paymentTotal", "creditTotal", "terms",
+ "dueDate", "paymentDate" ) );
+ Expect.Call( _termTask.GetAll( ) ).Return( items );
+ _termsDropDown.BindTo( items );
+ _termsDropDown.SetSelectedItemTo( "terms" );
+ _view.VendorName = "vendor";
+ _view.InvoiceNumber = "number";
+ _view.InvoiceDate = "date";
+ _view.InvoiceTotal = "total";
+ _view.PaymentTotal = "paymentTotal";
+ _view.CreditTotal = "creditTotal";
+ _view.DueDate = "dueDate";
+ _view.PaymentDate = "paymentDate";
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSut( invoiceId ).Initialize( );
+ }
+ }
+
+ [Test]
+ public void Should_Update_Changes( ) {
+ const string invoiceId = "2";
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _view.InvoiceNumber ).Return( "QP58872" );
+ SetupResult.For( _view.InvoiceDate ).Return( "1/5/2007 12:00:00 AM" );
+ SetupResult.For( _view.InvoiceTotal ).Return( "116.54" );
+ SetupResult.For( _view.PaymentTotal ).Return( "116.54" );
+ SetupResult.For( _view.CreditTotal ).Return( "0.00" );
+ SetupResult.For( _view.DueDate ).Return( "3/4/2007 12:00:00 AM" );
+ SetupResult.For( _view.PaymentDate ).Return( "2/22/2007 12:00:00 AM" );
+ SetupResult.For( _termsDropDown.SelectedItem ).Return( new DropDownListItem( "10 days", "4" ) );
+
+ UpdateInvoiceDto dto =
+ new UpdateInvoiceDto( invoiceId, "QP58872", "1/5/2007 12:00:00 AM", "116.54", "116.54", "0.00",
+ "3/4/2007 12:00:00 AM",
+ "2/22/2007 12:00:00 AM", "4" );
+ _task.UpdateInvoice( dto );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSut( invoiceId ).UpdateInvoice( );
+ }
+ }
+
+ private EditInvoicePresenter CreateSut( string invoiceId ) {
+ return new EditInvoicePresenter( invoiceId, _view, _task, _termTask );
+ }
+ }
+}
\ No newline at end of file diff --git a/src/test/Cmpp298.Assignment3.Test/Presentation/InvoicesMainPresenterTest.cs b/src/test/Cmpp298.Assignment3.Test/Presentation/InvoicesMainPresenterTest.cs new file mode 100644 index 0000000..283445d --- /dev/null +++ b/src/test/Cmpp298.Assignment3.Test/Presentation/InvoicesMainPresenterTest.cs @@ -0,0 +1,68 @@ +using System.Collections.Generic;
+using Cmpp298.Assignment3.Dto;
+using Cmpp298.Assignment3.Presentation;
+using Cmpp298.Assignment3.Task;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Cmpp298.Assignment3.Test.Presentation {
+ [TestFixture]
+ public class InvoicesMainPresenterTest {
+ private MockRepository _mockery;
+ private IInvoicesMainView _view;
+ private IVendorTask _vendorsTask;
+ private IDropDownListAdapter _vendorNamesDropDown;
+ private IInvoiceTask _invoiceTask;
+
+ [SetUp]
+ public void SetUp( ) {
+ _mockery = new MockRepository( );
+ _view = _mockery.Stub< IInvoicesMainView >( );
+ _vendorsTask = _mockery.Stub< IVendorTask >( );
+ _invoiceTask = _mockery.Stub< IInvoiceTask >( );
+ _vendorNamesDropDown = _mockery.Stub< IDropDownListAdapter >( );
+
+ SetupResult.For( _view.VendorNames ).Return( _vendorNamesDropDown );
+ }
+
+ [Test]
+ public void Should_Load_List_Of_Vendor_Names_On_Load( ) {
+ IList< IDropDownListItem > vendors = new List< IDropDownListItem >( );
+ vendors.Add( new DropDownListItem( "US Postal Service", "1" ) );
+ vendors.Add( new DropDownListItem( "National Information Data Ctr", "2" ) );
+ vendors.Add( new DropDownListItem( "Register of Copyrights", "3" ) );
+
+ using ( _mockery.Record( ) ) {
+ Expect.Call( _vendorsTask.GetAllVendorNames( ) ).Return( vendors ).Repeat.Once( );
+ _vendorNamesDropDown.BindTo( vendors );
+ }
+ using ( _mockery.Playback( ) ) {
+ CreateSut( ).Initialize( );
+ }
+ }
+
+ [Test]
+ public void Should_Load_List_Of_Invoices_For_Vendor_On_Load( ) {
+ IList< DisplayInvoiceDto > invoices = new List< DisplayInvoiceDto >( );
+ const string forVendorId = "1";
+ invoices.Add(
+ new DisplayInvoiceDto( "1", "IBM", "QP58872", "1/5/2007 12:00:00 AM", "116.54", "116.5400", "0.0000",
+ "Net due 60 days",
+ "3/4/2007 12:00:00 AM", "2/22/2007 12:00:00 AM" ) );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _vendorNamesDropDown.SelectedItem ).Return( new DropDownListItem( "IBM", forVendorId ) );
+
+ Expect.Call( _invoiceTask.GetAllInvoices( forVendorId ) ).Return( invoices );
+ _view.BindTo( invoices );
+ }
+ using ( _mockery.Playback( ) ) {
+ CreateSut( ).LoadInvoices( );
+ }
+ }
+
+ private InvoicesMainPresenter CreateSut( ) {
+ return new InvoicesMainPresenter( _view, _vendorsTask, _invoiceTask );
+ }
+ }
+}
\ No newline at end of file diff --git a/src/test/Cmpp298.Assignment3.Test/Presentation/NewInvoicePresenterTest.cs b/src/test/Cmpp298.Assignment3.Test/Presentation/NewInvoicePresenterTest.cs new file mode 100644 index 0000000..2ccd4ca --- /dev/null +++ b/src/test/Cmpp298.Assignment3.Test/Presentation/NewInvoicePresenterTest.cs @@ -0,0 +1,114 @@ +using System.Collections.Generic;
+using Cmpp298.Assignment3.Dto;
+using Cmpp298.Assignment3.Presentation;
+using Cmpp298.Assignment3.Task;
+using MbUnit.Framework;
+using Rhino.Mocks;
+using Rhino.Mocks.Constraints;
+
+namespace Cmpp298.Assignment3.Test.Presentation {
+ [TestFixture]
+ public class NewInvoicePresenterTest {
+ private MockRepository _mockery;
+ private INewInvoiceView _view;
+ private IInvoiceTask _invoiceTask;
+ private IVendorTask _vendorTask;
+ private ITermTask _termTask;
+ private IDropDownListAdapter _termsDropDown;
+
+ [SetUp]
+ public void SetUp( ) {
+ _mockery = new MockRepository( );
+ _view = _mockery.Stub< INewInvoiceView >( );
+ _invoiceTask = _mockery.Stub< IInvoiceTask >( );
+ _vendorTask = _mockery.Stub< IVendorTask >( );
+ _termTask = _mockery.Stub< ITermTask >( );
+ _termsDropDown = _mockery.Stub< IDropDownListAdapter >( );
+
+ SetupResult.For( _view.Terms ).Return( _termsDropDown );
+ }
+
+ [Test]
+ public void Should_Load_Vendor_Names_On_Load( ) {
+ const string vendorId = "34";
+ using ( _mockery.Record( ) ) {
+ DisplayVendorNameDto displayVendorNameDto = new DisplayVendorNameDto( vendorId, "IBM" );
+ Expect.Call( _vendorTask.FindVendorNameBy( vendorId ) ).Return( displayVendorNameDto );
+ _view.BindTo( displayVendorNameDto );
+ }
+ using ( _mockery.Playback( ) ) {
+ CreateSut( vendorId ).Load( );
+ }
+ }
+
+ [Test]
+ public void Should_Load_Terms_On_Load( ) {
+ IList< IDropDownListItem > terms = new List< IDropDownListItem >( );
+ terms.Add( new DropDownListItem( "Net due 10 days", "1" ) );
+ terms.Add( new DropDownListItem( "Net due 20 days", "2" ) );
+ terms.Add( new DropDownListItem( "Net due 30 days", "3" ) );
+ terms.Add( new DropDownListItem( "Net due 60 days", "4" ) );
+ terms.Add( new DropDownListItem( "Net due 90 days", "5" ) );
+
+ using ( _mockery.Record( ) ) {
+ Expect.Call( _termTask.GetAll( ) ).Return( terms );
+ _termsDropDown.BindTo( terms );
+ }
+ using ( _mockery.Playback( ) ) {
+ const string vendorId = "34";
+ CreateSut( vendorId ).Load( );
+ }
+ }
+
+ [Test]
+ public void Should_Create_New_Invoice_Number_On_Load( ) {
+ using ( _mockery.Record( ) ) {}
+ using ( _mockery.Playback( ) ) {
+ CreateSut( "34" ).Load( );
+ Assert.IsTrue( _view.InvoiceNumber != null, "Invoice number should have been generated" );
+ }
+ }
+
+ [Test]
+ public void Should_Save_New_Invoice( ) {
+ const string vendorId = "34";
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _view.InvoiceDate ).Return( "1/5/2007 12:00:00 AM" );
+ SetupResult.For( _view.InvoiceTotal ).Return( "116.54" );
+ SetupResult.For( _view.PaymentTotal ).Return( "116.54" );
+ SetupResult.For( _view.CreditTotal ).Return( "0.00" );
+ SetupResult.For( _view.DueDate ).Return( "3/4/2007 12:00:00 AM" );
+ SetupResult.For( _view.PaymentDate ).Return( "2/22/2007 12:00:00 AM" );
+ Expect.Call( _termsDropDown.SelectedItem ).Return( new DropDownListItem( "Net due 60 days", "4" ) );
+
+ _invoiceTask.SaveNewInvoice(
+ new SaveInvoiceDto( vendorId, "QP58872", "1/5/2007 12:00:00 AM", "116.5400", "116.5400", "0.0000",
+ "3/4/2007 12:00:00 AM",
+ "2/22/2007 12:00:00 AM", "4" ) );
+ }
+ using ( _mockery.Playback( ) ) {
+ CreateSut( vendorId ).SaveInvoice( );
+ }
+ }
+
+ [Test]
+ public void Should_Check_For_Valid_Input( ) {
+ const string vendorId = "34";
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _view.InvoiceTotal ).Return( "abcd" );
+ SetupResult.For( _view.PaymentTotal ).Return( "abcd" );
+ SetupResult.For( _view.CreditTotal ).Return( "abcd" );
+
+ _view.ShowError( null );
+ LastCall.Constraints( Is.NotNull( ) );
+ }
+ using ( _mockery.Playback( ) ) {
+ CreateSut( vendorId ).SaveInvoice( );
+ }
+ }
+
+ private NewInvoicePresenter CreateSut( string vendorId ) {
+ return new NewInvoicePresenter( vendorId, _view, _invoiceTask, _vendorTask, _termTask );
+ }
+ }
+}
\ No newline at end of file diff --git a/src/test/Cmpp298.Assignment3.Test/Properties/AssemblyInfo.cs b/src/test/Cmpp298.Assignment3.Test/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0d1864f --- /dev/null +++ b/src/test/Cmpp298.Assignment3.Test/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection;
+using System.Runtime.CompilerServices;
+using 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.
+[assembly: AssemblyTitle("Cmpp298.Assignment3.Test")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Cmpp298.Assignment3.Test")]
+[assembly: AssemblyCopyright("Copyright © 2007")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("a2246f12-aa13-4e38-8c32-0ebb14a0d19e")]
+
+// 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.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/src/test/Cmpp298.Assignment3.Test/Task/InvoiceTaskTest.cs b/src/test/Cmpp298.Assignment3.Test/Task/InvoiceTaskTest.cs new file mode 100644 index 0000000..e789e4c --- /dev/null +++ b/src/test/Cmpp298.Assignment3.Test/Task/InvoiceTaskTest.cs @@ -0,0 +1,105 @@ +using System;
+using System.Collections.Generic;
+using Cmpp298.Assignment3.Dto;
+using Cmpp298.Assignment3.Task;
+using MbUnit.Framework;
+
+namespace Cmpp298.Assignment3.Test {
+ [TestFixture]
+ public class InvoiceTaskTest {
+ [Test]
+ [RollBack]
+ public void Should_Return_114( ) {
+ const string forVendorId = "122";
+ Assert.IsTrue( new List< DisplayInvoiceDto >( CreateSut( ).GetAllInvoices( forVendorId ) ).Count == 9 );
+ }
+
+ [Test]
+ [RollBack]
+ public void Should_Return_2( ) {
+ const string forVendorId = "34";
+ List< DisplayInvoiceDto > list = new List< DisplayInvoiceDto >( CreateSut( ).GetAllInvoices( forVendorId ) );
+ Assert.IsTrue( list.Count == 2, "should equal 2 but has " + list.Count );
+ }
+
+ [Test]
+ [RollBack]
+ public void Should_Save_New_Invoice( ) {
+ const string vendorId = "1";
+ const string termsId = "1";
+ SaveInvoiceDto saveInvoiceDto =
+ new SaveInvoiceDto( vendorId, Guid.NewGuid( ).ToString( ),
+ DateTime.Now.ToString( ), "123.48", "123.48", "0.00",
+ DateTime.Now.AddDays( 1 ).ToString( ),
+ DateTime.Now.ToString( ),
+ termsId );
+ InvoiceTask invoiceTask = CreateSut( );
+ string invoiceId = invoiceTask.SaveNewInvoice( saveInvoiceDto ).ToString( );
+
+ bool foundInvoice = false;
+ foreach ( DisplayInvoiceDto displayInvoiceDto in invoiceTask.GetAllInvoices( vendorId ) ) {
+ if ( displayInvoiceDto.InvoiceId == invoiceId ) {
+ foundInvoice = true;
+ }
+ }
+ Assert.IsTrue( foundInvoice, "Couldn't find the inserted invoice record" );
+ }
+
+ [Test]
+ [RollBack]
+ public void Should_Be_Able_To_Find_Invoice_By_Id( ) {
+ InvoiceTask task = CreateSut( );
+ string invoiceNumber = Guid.NewGuid( ).ToString( );
+ int id = task.SaveNewInvoice(
+ new SaveInvoiceDto( "34", invoiceNumber, DateTime.Today.ToString( ), "1.00", "1.00", "0.00",
+ DateTime.Today.ToString( ),
+ DateTime.Today.ToString( ), "1" ) );
+
+ DisplayInvoiceDto dto = task.GetInvoiceBy( id.ToString( ) );
+
+ Assert.IsTrue( dto.CreditTotal == "0.0000", "Credit Total Actual: " + dto.CreditTotal );
+ Assert.IsTrue( dto.DueDate == DateTime.Today.ToString( ), "Due Date Actual: " + dto.DueDate );
+ Assert.IsTrue( dto.InvoiceDate == DateTime.Today.ToString( ), "Invoice Date Actual: " + dto.InvoiceDate );
+ Assert.IsTrue( dto.InvoiceId == id.ToString( ), "Invoice Id Actual: " + dto.InvoiceId );
+ Assert.IsTrue( dto.InvoiceNumber == invoiceNumber, "Invoice Number Actual: " + dto.InvoiceNumber );
+ Assert.IsTrue( dto.InvoiceTotal == "1.0000", "Invoice Total Actual: " + dto.InvoiceTotal );
+ Assert.IsTrue( dto.PaymentDate == DateTime.Today.ToString( ), "Payment Date Actual: " + dto.PaymentDate );
+ Assert.IsTrue( dto.PaymentTotal == "1.0000", "Payment Total Actual: " + dto.PaymentTotal );
+ }
+
+ [Test]
+ [RollBack]
+ public void Should_Be_Able_To_Delete_Invoice( ) {
+ InvoiceTask task = CreateSut( );
+ int id = task.SaveNewInvoice(
+ new SaveInvoiceDto( "34", Guid.NewGuid( ).ToString( ), DateTime.Today.ToString( ), "1.00", "1.00", "0.00",
+ DateTime.Today.ToString( ),
+ DateTime.Today.ToString( ), "1" ) );
+
+ task.DeleteInvoice( id.ToString( ) );
+ Assert.IsTrue( task.GetInvoiceBy( id.ToString( ) ) == null );
+ }
+
+ [Test]
+ [RollBack]
+ public void Should_Be_Able_To_Update_Invoice_Details( ) {
+ InvoiceTask task = CreateSut( );
+ int id = task.SaveNewInvoice(
+ new SaveInvoiceDto( "34", Guid.NewGuid( ).ToString( ), DateTime.Today.ToString( ), "1.00", "1.00", "0.00",
+ DateTime.Today.ToString( ),
+ DateTime.Today.ToString( ), "1" ) );
+
+ DisplayInvoiceDto dto = task.GetInvoiceBy( id.ToString( ) );
+ task.UpdateInvoice(
+ new UpdateInvoiceDto( id.ToString( ), dto.InvoiceNumber, dto.InvoiceDate, dto.InvoiceTotal, "123.45",
+ dto.CreditTotal, dto.DueDate, dto.PaymentDate, "1" ) );
+
+ dto = task.GetInvoiceBy( id.ToString( ) );
+ Assert.IsTrue( dto.PaymentTotal == "123.4500" );
+ }
+
+ private static InvoiceTask CreateSut( ) {
+ return new InvoiceTask( );
+ }
+ }
+}
\ No newline at end of file diff --git a/src/test/Cmpp298.Assignment3.Test/Task/VendorTaskTest.cs b/src/test/Cmpp298.Assignment3.Test/Task/VendorTaskTest.cs new file mode 100644 index 0000000..2b76674 --- /dev/null +++ b/src/test/Cmpp298.Assignment3.Test/Task/VendorTaskTest.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic;
+using Cmpp298.Assignment3.Dto;
+using Cmpp298.Assignment3.Task;
+using MbUnit.Framework;
+
+namespace Cmpp298.Assignment3.Test {
+ [TestFixture]
+ public class VendorTaskTest {
+ [Test]
+ public void Should_Be_Able_To_Find_Vendor_By_Id( ) {
+ IVendorTask task = CreateSut( );
+ const string vendorId = "1";
+ DisplayVendorNameDto dto = task.FindVendorNameBy( vendorId );
+ Assert.IsTrue( dto.VendorId == vendorId );
+ Assert.IsTrue( dto.VendorName == "US Postal Service" );
+ }
+
+ [Test]
+ public void Should_Be_Able_To_Get_All_Vendor_Names( ) {
+ IVendorTask task = CreateSut( );
+ IList< IDropDownListItem > list = new List< IDropDownListItem >( task.GetAllVendorNames( ) );
+ Assert.IsTrue( list.Count > 0, "Should have at least 1 vendor name but has: " + list.Count );
+ }
+
+ private static IVendorTask CreateSut( ) {
+ return new VendorTask( );
+ }
+ }
+}
\ No newline at end of file |
