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