1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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( );
}
}
}
|