This repository has been archived by the owner on Apr 18, 2023. It is now read-only.
/
InvoiceTest.cs
96 lines (78 loc) · 3.16 KB
/
InvoiceTest.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using iloire_Facturacion.Controllers;
using MvcPaging;
using System.Data.Entity.Infrastructure;
namespace iloire_Facturacion_Tests
{
[TestFixture]
public class InvoiceTest
{
[TestFixtureSetUp]
public void TestSetup()
{
}
[Test]
public void TestListInvoices()
{
InvoiceController ic = new InvoiceController();
System.Web.Mvc.ViewResult result = ic.Index(null);
Assert.IsNotNull(result.ViewData.Model);
Assert.IsInstanceOf(typeof(IPagedList<Invoice>), result.ViewData.Model);
}
[Test]
public void TestAddInvoice()
{
InvoiceController ic = new InvoiceController();
//load first customer by calling DBcontext
InvoiceDB db = new InvoiceDB();
Customer c = db.Customers.First();
((IObjectContextAdapter)db).ObjectContext.Detach(c); //http://stackoverflow.com/questions/4168073/entity-framework-code-first-no-detach-method-on-dbcontext
Assert.NotNull(c);
Invoice i = new Invoice();
i.CustomerID = c.CustomerID;
i.Customer = c;
i.AdvancePaymentTax = 10;
i.Notes = "Invoice notes";
i.TimeStamp = DateTime.Now;
i.DueDate = DateTime.Now.AddDays(90);
i.Paid = false;
i.Name = "Test invoice";
System.Web.Mvc.ActionResult resultAdd = ic.Create(i);
Assert.IsInstanceOf(typeof(System.Web.Mvc.ViewResult), resultAdd);
}
[Test]
public void TestEditInvoice()
{
InvoiceController ic = new InvoiceController();
System.Web.Mvc.ViewResult result = ic.Index(null);
Invoice i = ((IPagedList<Invoice>)result.ViewData.Model).First();
System.Web.Mvc.ActionResult invoiceEdition = ic.Edit(i.InvoiceID);
//post edited
i.Name = "Change invoice name test";
//get
System.Web.Mvc.ActionResult resultEditionView = ic.Edit(i.InvoiceID);
Assert.IsInstanceOf(typeof(System.Web.Mvc.ViewResult), resultEditionView);
//post
System.Web.Mvc.ActionResult resultEdition = ic.Edit(i);
Assert.IsInstanceOf(typeof(System.Web.Mvc.RedirectToRouteResult), resultEdition);
}
[Test]
public void TestDeleteInvoice()
{
InvoiceController ic = new InvoiceController();
System.Web.Mvc.ViewResult result = ic.Index(null);
Invoice i = ((IPagedList<Invoice>)result.ViewData.Model).First();
Assert.NotNull(i);
//ask deletion action
System.Web.Mvc.ActionResult invoiceAskDeletion = ic.Delete(i.InvoiceID);
Assert.IsInstanceOf(typeof(System.Web.Mvc.ViewResult), invoiceAskDeletion);
//delete action
System.Web.Mvc.ActionResult invoiceDeletion = ic.DeleteConfirmed(i.InvoiceID);
Assert.IsInstanceOf(typeof(System.Web.Mvc.RedirectToRouteResult), invoiceDeletion);
}
}
}