summaryrefslogtreecommitdiff
path: root/src/test/Cmpp298.Assignment3.Test/Presentation
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2007-08-26 20:10:42 -0600
committermo khan <mo@mokhan.ca>2007-08-26 20:10:42 -0600
commit330be9feefb6394479553be0e078b4c4df3cbff1 (patch)
tree55618c8af0d36583cde0ea5b4b193b98815a35aa /src/test/Cmpp298.Assignment3.Test/Presentation
import from svntrunk
Diffstat (limited to 'src/test/Cmpp298.Assignment3.Test/Presentation')
-rw-r--r--src/test/Cmpp298.Assignment3.Test/Presentation/DeleteInvoicePresenterTest.cs59
-rw-r--r--src/test/Cmpp298.Assignment3.Test/Presentation/EditInvoicePresenterTest.cs85
-rw-r--r--src/test/Cmpp298.Assignment3.Test/Presentation/InvoicesMainPresenterTest.cs68
-rw-r--r--src/test/Cmpp298.Assignment3.Test/Presentation/NewInvoicePresenterTest.cs114
4 files changed, 326 insertions, 0 deletions
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