| [866] | 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.Linq;
|
|---|
| 4 | using System.Text;
|
|---|
| 5 | using System.Web.Mvc;
|
|---|
| 6 |
|
|---|
| 7 | using NUnit.Framework;
|
|---|
| 8 | using MvcContrib.TestHelper;
|
|---|
| 9 | using Platnosci.Controllers;
|
|---|
| 10 |
|
|---|
| 11 | using Platnosci.Core.Interface;
|
|---|
| 12 | using Platnosci.Core.Linq;
|
|---|
| [871] | 13 | using WatiN.Core;
|
|---|
| 14 | using System.Threading;
|
|---|
| 15 | using Platnosci.Models;
|
|---|
| [872] | 16 | using Moq;
|
|---|
| [866] | 17 |
|
|---|
| 18 | namespace Platnosci.Tests.Web
|
|---|
| 19 | {
|
|---|
| [880] | 20 | [TestFixture]
|
|---|
| [866] | 21 | class PlatnosciControllerTests
|
|---|
| 22 | {
|
|---|
| [871] | 23 | private string merchantNumber = "123";
|
|---|
| [877] | 24 | private int orderNumber = 9999;
|
|---|
| [883] | 25 | private string code_Ok = "payment_deposited"; //transakcja potwierdzona do rozliczenia
|
|---|
| 26 | private string code_Bad = "payment_declined"; //transakcja odrzucona
|
|---|
| [877] | 27 | private DateTime data = DateTime.Now;
|
|---|
| [896] | 28 |
|
|---|
| [888] | 29 | private int test = 1; //oznacza, ze nie ustawiamy tlumaczen poprzez funkcje ustawTlumaczenia()
|
|---|
| 30 | //w controllerze Platnosci, tylko poprzez funkcje setXXXXXXX()
|
|---|
| [866] | 31 |
|
|---|
| [877] | 32 | private Function _f = new Function();
|
|---|
| [896] | 33 |
|
|---|
| [871] | 34 | [Test]
|
|---|
| 35 | [Category("Unit")]
|
|---|
| 36 | public void Status_Saves_Correct_Transaction()
|
|---|
| 37 | {
|
|---|
| [896] | 38 | var repository = new Repository<PlatnosciEcard>(new FakeDataContext());
|
|---|
| 39 | var platnosci = _f.createNewPayment(orderNumber, false, DateTime.Now, 12345);
|
|---|
| 40 | repository.Insert(platnosci);
|
|---|
| 41 | repository.SubmitChanges();
|
|---|
| [888] | 42 |
|
|---|
| [896] | 43 | IRepository<PotwierdzeniaEcard> rep = new Repository<PotwierdzeniaEcard>(new FakeDataContext());
|
|---|
| [877] | 44 |
|
|---|
| [896] | 45 | var builder = new TestControllerBuilder();
|
|---|
| 46 | var controller = new PlatnoscController(null, repository, rep, test);
|
|---|
| 47 | builder.InitializeController(controller);
|
|---|
| 48 | builder.Form.Add("MERCHANTNUMBER", merchantNumber.ToString());
|
|---|
| 49 | builder.Form.Add("AUTHTIME", DateTime.Now.ToString());
|
|---|
| 50 | builder.Form.Add("DATATRANSMISJI", DateTime.Now.ToString());
|
|---|
| 51 | builder.Form.Add("ORDERNUMBER", orderNumber.ToString());
|
|---|
| 52 | builder.Form.Add("CURRENTSTATE", code_Ok);
|
|---|
| [888] | 53 |
|
|---|
| [896] | 54 | var result = controller.Status();
|
|---|
| 55 |
|
|---|
| 56 | System.Diagnostics.Debug.WriteLine("rep:" + rep.Count() + " repPl: " + repository.Count() );
|
|---|
| [871] | 57 |
|
|---|
| [896] | 58 | var potwierdzeniaEcard = rep.Find(o => o.ORDERNUMBER == orderNumber).SingleOrDefault();
|
|---|
| 59 | Assert.That(potwierdzeniaEcard.MERCHANTNUMBER, Is.EqualTo(merchantNumber));
|
|---|
| 60 | PlatnosciEcard payment_after_update = repository.FindOne(orderNumber);
|
|---|
| 61 | System.Diagnostics.Debug.WriteLine("Status musi byc 'true'. Jest " + payment_after_update.Status);
|
|---|
| 62 | Assert.That(payment_after_update.Status, Is.EqualTo(true));
|
|---|
| [871] | 63 | }
|
|---|
| [870] | 64 | [Test]
|
|---|
| [871] | 65 | [Category("Unit")]
|
|---|
| [880] | 66 | public void Status_Saves_Correct_Transaction_IncorrectUpdate()
|
|---|
| [877] | 67 | {
|
|---|
| [896] | 68 | var repPayment = new Repository<PlatnosciEcard>(new FakeDataContext());
|
|---|
| 69 | var platnosci = _f.createNewPayment(orderNumber, false, DateTime.Now, 12345);
|
|---|
| 70 | repPayment.Insert(platnosci);
|
|---|
| 71 | repPayment.SubmitChanges();
|
|---|
| 72 | IRepository<PotwierdzeniaEcard> repConfirm = new Repository<PotwierdzeniaEcard>(new FakeDataContext());
|
|---|
| 73 |
|
|---|
| [877] | 74 | var builder = new TestControllerBuilder();
|
|---|
| [896] | 75 | var controller = new PlatnoscController(null, repPayment, repConfirm, test);
|
|---|
| [877] | 76 | builder.InitializeController(controller);
|
|---|
| 77 | builder.Form.Add("MERCHANTNUMBER", merchantNumber.ToString());
|
|---|
| 78 | builder.Form.Add("AUTHTIME", DateTime.Now.ToString());
|
|---|
| 79 | builder.Form.Add("DATATRANSMISJI", DateTime.Now.ToString());
|
|---|
| 80 | builder.Form.Add("ORDERNUMBER", orderNumber.ToString());
|
|---|
| [883] | 81 | builder.Form.Add("CURRENTSTATE", code_Bad);
|
|---|
| [877] | 82 |
|
|---|
| [896] | 83 | var result = controller.Status();
|
|---|
| [877] | 84 |
|
|---|
| [896] | 85 | var potwierdzeniaEcard = repConfirm.Find(o => o.ORDERNUMBER == orderNumber).SingleOrDefault();
|
|---|
| [877] | 86 | Assert.That(potwierdzeniaEcard.MERCHANTNUMBER, Is.EqualTo(merchantNumber));
|
|---|
| [888] | 87 |
|
|---|
| [896] | 88 | PlatnosciEcard payment_after_update = repPayment.FindOne(orderNumber);
|
|---|
| 89 | System.Diagnostics.Debug.WriteLine("Status musi byc 'false'. Jest " + payment_after_update.Status);
|
|---|
| 90 | Assert.That(payment_after_update.Status, Is.EqualTo(false));
|
|---|
| [877] | 91 | }
|
|---|
| [896] | 92 |
|
|---|
| [877] | 93 | [Test]
|
|---|
| 94 | [Category("Unit")]
|
|---|
| [871] | 95 | public void StatusIsUpdated()
|
|---|
| 96 | {
|
|---|
| [896] | 97 | IRepository<PlatnosciEcard> repPayment = new Repository<PlatnosciEcard>(new FakeDataContext());
|
|---|
| 98 | PlatnosciEcard platnosc = _f.createNewPayment(orderNumber, false, data, 1);
|
|---|
| 99 | repPayment.Insert(platnosc);
|
|---|
| [872] | 100 |
|
|---|
| [896] | 101 | var controller = new PlatnoscController(null, repPayment, null, test);
|
|---|
| [877] | 102 | controller.UpdateStatus(orderNumber, code_Ok);
|
|---|
| 103 |
|
|---|
| [871] | 104 | PlatnosciEcard payment_after_update = new PlatnosciEcard();
|
|---|
| [896] | 105 | payment_after_update = repPayment.FindOne(orderNumber);
|
|---|
| 106 | System.Diagnostics.Debug.WriteLine("Status musi byc 'true'. Jest " + payment_after_update.Status);
|
|---|
| [888] | 107 | Assert.That(payment_after_update.Status, Is.EqualTo(true));
|
|---|
| [871] | 108 | }
|
|---|
| 109 | [Test]
|
|---|
| 110 | [Category("Unit")]
|
|---|
| 111 | public void StatusIsNotUpdated()
|
|---|
| 112 | {
|
|---|
| [896] | 113 | IRepository<PlatnosciEcard> repPayment = new Repository<PlatnosciEcard>(new FakeDataContext());
|
|---|
| [871] | 114 |
|
|---|
| [896] | 115 | PlatnosciEcard platnosc = _f.createNewPayment(orderNumber, false, data, 1);
|
|---|
| 116 | repPayment.Insert(platnosc);
|
|---|
| [871] | 117 |
|
|---|
| [896] | 118 | var controller = new PlatnoscController(null, repPayment, null, test);
|
|---|
| [877] | 119 | controller.UpdateStatus(orderNumber, code_Bad);
|
|---|
| [871] | 120 |
|
|---|
| 121 | PlatnosciEcard payment_after_update = new PlatnosciEcard();
|
|---|
| [896] | 122 | payment_after_update = repPayment.FindOne(i => i.ORDERNUMBER == orderNumber);
|
|---|
| 123 | System.Diagnostics.Debug.WriteLine("Status musi byc 'false'. Jest " + payment_after_update.Status);
|
|---|
| 124 | Assert.That(payment_after_update.Status, Is.EqualTo(false));
|
|---|
| [872] | 125 | }
|
|---|
| [871] | 126 | [Test]
|
|---|
| 127 | [Category("Unit")]
|
|---|
| [872] | 128 | public void ActionShowPayment_IncorrectUserIdentity_ReturnErrorView()
|
|---|
| [871] | 129 | {
|
|---|
| [896] | 130 | IRepository<vPlatnosciEcard> repVPayment = new Repository<vPlatnosciEcard>(new FakeDataContext());
|
|---|
| 131 | vPlatnosciEcard platnosc = _f.createInvoice(123, "nip1", "", 0, 0);
|
|---|
| 132 | repVPayment.Insert(platnosc);
|
|---|
| [871] | 133 |
|
|---|
| [896] | 134 | var controller = new PlatnoscController(repVPayment, null, null, test);
|
|---|
| 135 | controller.ControllerContext = _f.createControllerContext("nip2");
|
|---|
| [877] | 136 | controller.setWeryfikacja("Niepoprawny nip");
|
|---|
| [872] | 137 |
|
|---|
| [896] | 138 | var result = controller.Show("123","pl") as ViewResult;
|
|---|
| [871] | 139 | var error = (ErrorViewData)result.ViewData.Model;
|
|---|
| [896] | 140 |
|
|---|
| [872] | 141 | Assert.That(error.error, Is.EqualTo("Niepoprawny nip"));
|
|---|
| 142 | Assert.That(result.ViewName, Is.EqualTo("Error1"));
|
|---|
| [871] | 143 | }
|
|---|
| 144 | [Test]
|
|---|
| 145 | [Category("Unit")]
|
|---|
| [872] | 146 | public void ActionShowPayment_PaymentNotFound_ReturnErrorView()
|
|---|
| [871] | 147 | {
|
|---|
| [896] | 148 | IRepository<vPlatnosciEcard> repVPayment = new Repository<vPlatnosciEcard>(new FakeDataContext());
|
|---|
| 149 | vPlatnosciEcard platnosc = _f.createInvoice(123, "", "", 0, 0);
|
|---|
| 150 | repVPayment.Insert(platnosc);
|
|---|
| [871] | 151 |
|
|---|
| [896] | 152 | var controller = new PlatnoscController(repVPayment, null, null, test);
|
|---|
| [872] | 153 | controller.setBrakDanych("Platnosc o takim id nie istnieje");
|
|---|
| [871] | 154 |
|
|---|
| [896] | 155 | var result = controller.Show("1234", "pl") as ViewResult;
|
|---|
| [872] | 156 | var error = (ErrorViewData)result.ViewData.Model;
|
|---|
| [871] | 157 |
|
|---|
| [872] | 158 | Assert.That(error.error, Is.EqualTo("Platnosc o takim id nie istnieje"));
|
|---|
| 159 | Assert.That(result.ViewName, Is.EqualTo("Error1"));
|
|---|
| [871] | 160 | }
|
|---|
| 161 | [Test]
|
|---|
| 162 | [Category("Unit")]
|
|---|
| [896] | 163 | public void ActionShowPayment_PaymentIsPaid()
|
|---|
| 164 | {
|
|---|
| [872] | 165 | //Tworzymy takie dane aby platnosc o danym id byla juz zaplacona
|
|---|
| [896] | 166 | var repVPayment = new Repository<vPlatnosciEcard>(new FakeDataContext());
|
|---|
| 167 | var invoice = _f.createInvoice(123, "nip1", "aaa", 0, 0);
|
|---|
| 168 | repVPayment.Insert(invoice);
|
|---|
| 169 | repVPayment.SubmitChanges();
|
|---|
| [872] | 170 |
|
|---|
| [896] | 171 | var repConfirm = new Repository<PotwierdzeniaEcard>(new FakeDataContext());
|
|---|
| 172 | var confirm = _f.createConfirm(code_Ok, 123456);
|
|---|
| 173 | repConfirm.Insert(confirm);
|
|---|
| 174 | repConfirm.SubmitChanges();
|
|---|
| 175 |
|
|---|
| 176 | var controller = new PlatnoscController(repVPayment, null, repConfirm, test);
|
|---|
| 177 | controller.ControllerContext = _f.createControllerContext("nip1");
|
|---|
| [872] | 178 | controller.setZaplacono("Platnosc zostala uregulowana");
|
|---|
| 179 |
|
|---|
| [896] | 180 | var result = controller.Show("123", "pl") as ViewResult;
|
|---|
| [888] | 181 | var view = (InvoiceDetailsViewData)result.ViewData.Model;
|
|---|
| [872] | 182 |
|
|---|
| [888] | 183 | Assert.That(result.ViewName, Is.EqualTo("Paid"));
|
|---|
| 184 | Assert.That(view.info, Is.EqualTo("Platnosc zostala uregulowana"));
|
|---|
| [872] | 185 | }
|
|---|
| 186 | [Test]
|
|---|
| 187 | [Category("Unit")]
|
|---|
| 188 | public void ActionShowPayment_CorrectData_ReturnViewForPayment()
|
|---|
| [871] | 189 | {
|
|---|
| [896] | 190 | IRepository<vPlatnosciEcard> repVPayment = new Repository<vPlatnosciEcard>(new FakeDataContext());
|
|---|
| 191 | vPlatnosciEcard platnosc = _f.createInvoice(123, "nip1", "numer", 200, 0);
|
|---|
| 192 | repVPayment.Insert(platnosc);
|
|---|
| [871] | 193 |
|
|---|
| [896] | 194 | var repConfirm = new Repository<PotwierdzeniaEcard>(new FakeDataContext());
|
|---|
| 195 | var confirm = _f.createConfirm(code_Ok, 1);
|
|---|
| 196 | repConfirm.Insert(confirm);
|
|---|
| 197 | repConfirm.SubmitChanges();
|
|---|
| [871] | 198 |
|
|---|
| [896] | 199 | var controller = new PlatnoscController(repVPayment, null, repConfirm, test);
|
|---|
| 200 | controller.ControllerContext = _f.createControllerContext("nip1");
|
|---|
| 201 |
|
|---|
| 202 | var result = controller.Show("123", "pl") as ViewResult;
|
|---|
| 203 |
|
|---|
| [872] | 204 | var view = (InvoiceDetailsViewData)result.ViewData.Model;
|
|---|
| [896] | 205 | System.Diagnostics.Debug.WriteLine("Brutto 200: " + view.vPlatnosciEcard.Brutto);
|
|---|
| 206 | System.Diagnostics.Debug.WriteLine("Nr Faktury musi byc 'numer'. Jest " + view.vPlatnosciEcard.Faktura_Numer);
|
|---|
| 207 | Assert.That(view.vPlatnosciEcard.Brutto, Is.EqualTo(200));
|
|---|
| 208 | Assert.That(view.vPlatnosciEcard.Faktura_Numer, Is.EqualTo("numer"));
|
|---|
| [871] | 209 | }
|
|---|
| 210 | [Test]
|
|---|
| 211 | [Category("Unit")]
|
|---|
| [872] | 212 | public void AfterPay_PaymentIsNotValid()
|
|---|
| [871] | 213 | {
|
|---|
| [896] | 214 | IRepository<vPlatnosciEcard> repVPayment = new Repository<vPlatnosciEcard>(new FakeDataContext());
|
|---|
| 215 | vPlatnosciEcard platnosc = _f.createInvoice(123, "nip1", "numer", 200, 0);
|
|---|
| 216 | repVPayment.Insert(platnosc);
|
|---|
| [871] | 217 |
|
|---|
| [896] | 218 | var controller = new PlatnoscController(repVPayment, null, null, test);
|
|---|
| 219 | controller.ControllerContext = _f.createControllerContext("nip1");
|
|---|
| [872] | 220 |
|
|---|
| [896] | 221 | Payer payer = _f.createPayer(123, "", "test"); //Brak imienia
|
|---|
| [872] | 222 | controller.Show(payer, "pl");
|
|---|
| 223 | Assert.That(controller.ModelState.IsValid, Is.False);
|
|---|
| [871] | 224 | }
|
|---|
| 225 | [Test]
|
|---|
| 226 | [Category("Unit")]
|
|---|
| [872] | 227 | public void AfterPay_PaymentIsValid()
|
|---|
| [871] | 228 | {
|
|---|
| [896] | 229 | IRepository<vPlatnosciEcard> repVPayment = new Repository<vPlatnosciEcard>(new FakeDataContext());
|
|---|
| 230 | vPlatnosciEcard platnosc = _f.createInvoice(123, "nip1", "numer", 200, 0);
|
|---|
| 231 | repVPayment.Insert(platnosc);
|
|---|
| [871] | 232 |
|
|---|
| [896] | 233 | var controller = new PlatnoscController(repVPayment, null, null, test);
|
|---|
| 234 | controller.ControllerContext = _f.createControllerContext("nip1");
|
|---|
| [871] | 235 |
|
|---|
| [896] | 236 | Payer payer = _f.createPayer(123, "test", "test");
|
|---|
| [877] | 237 | var result = controller.Show(payer, "pl") as ViewResult;
|
|---|
| [871] | 238 |
|
|---|
| [896] | 239 | System.Diagnostics.Debug.WriteLine("Model powinien byc 'true'. Jest " + controller.ModelState.IsValid);
|
|---|
| 240 | Assert.That(controller.ModelState.IsValid, Is.True);
|
|---|
| [880] | 241 | }
|
|---|
| [866] | 242 | }
|
|---|
| 243 | }
|
|---|
| [870] | 244 |
|
|---|