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