| 1 | using System;
|
|---|
| 2 | using System.Web.Mvc;
|
|---|
| 3 | using adMoto.Payments.Core;
|
|---|
| 4 | using adMoto.Payments.Core.Data;
|
|---|
| 5 | using adMoto.Payments.Core.Interfaces;
|
|---|
| 6 | using adMoto.Payments.Test.Fakes;
|
|---|
| 7 | using adMoto.Payments.Web.Controllers;
|
|---|
| 8 | using adMoto.Payments.Web.Models;
|
|---|
| 9 | using NUnit.Framework;
|
|---|
| 10 |
|
|---|
| 11 | namespace adMoto.Payments.Test.Controllers
|
|---|
| 12 | {
|
|---|
| 13 | [TestFixture]
|
|---|
| 14 | public class PlatnosciControllerTests
|
|---|
| 15 | {
|
|---|
| 16 | private readonly ITranslateManager _translateManager = new FakeTranslation();
|
|---|
| 17 | private const string MERCHANT_NUMBER = "123";
|
|---|
| 18 | private readonly int _orderNumber = 9999;
|
|---|
| 19 | private const string CODE_OK = "payment_deposited"; //transakcja potwierdzona do rozliczenia
|
|---|
| 20 | private const string CODE_BAD = "payment_declined"; //transakcja odrzucona
|
|---|
| 21 | private readonly DateTime _data = DateTime.Now;
|
|---|
| 22 | private readonly TestDataHelper _testDataHelper = new TestDataHelper();
|
|---|
| 23 |
|
|---|
| 24 | [Test]
|
|---|
| 25 | [Category("Unit")]
|
|---|
| 26 | public void Update_Status_Payment_Is_Update_When_Currentstate_Is_CODE_OK()
|
|---|
| 27 | {
|
|---|
| 28 | //Arrange
|
|---|
| 29 | IRepository<PlatnosciEcard> repPayment = new Repository<PlatnosciEcard>(new FakeDataContext());
|
|---|
| 30 | PlatnosciEcard payment = _testDataHelper.CreateNewPayment(_orderNumber, false, _data, 1);
|
|---|
| 31 | repPayment.Insert(payment);
|
|---|
| 32 |
|
|---|
| 33 | //Act
|
|---|
| 34 | var controller = new PlatnoscController(null, repPayment, null, _translateManager);
|
|---|
| 35 | controller.UpdateStatus(_orderNumber, CODE_OK);
|
|---|
| 36 |
|
|---|
| 37 | var paymentAfterUpdate = repPayment.FindOne(_orderNumber);
|
|---|
| 38 |
|
|---|
| 39 | //Assert
|
|---|
| 40 | System.Diagnostics.Debug.WriteLine("Status musi byc 'true'. Jest " + paymentAfterUpdate.Status);
|
|---|
| 41 | Assert.That(paymentAfterUpdate.Status, Is.EqualTo(true));
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | [Test]
|
|---|
| 45 | [Category("Unit")]
|
|---|
| 46 | public void Update_Status_Payment_Is_Not_Update_When_Currentstate_Is_CODE_BAD()
|
|---|
| 47 | {
|
|---|
| 48 | //Arrange
|
|---|
| 49 | IRepository<PlatnosciEcard> repPayment = new Repository<PlatnosciEcard>(new FakeDataContext());
|
|---|
| 50 | var payment= _testDataHelper.CreateNewPayment(_orderNumber, false, _data, 1);
|
|---|
| 51 | repPayment.Insert(payment);
|
|---|
| 52 |
|
|---|
| 53 | var controller = new PlatnoscController(null, repPayment, null, _translateManager);
|
|---|
| 54 |
|
|---|
| 55 | //Act
|
|---|
| 56 | controller.UpdateStatus(_orderNumber, CODE_BAD);
|
|---|
| 57 | var paymentAfterUpdate = repPayment.FindOne(i => i.ORDERNUMBER == _orderNumber);
|
|---|
| 58 |
|
|---|
| 59 | //Assert
|
|---|
| 60 | System.Diagnostics.Debug.WriteLine("Status musi byc 'false'. Jest " + paymentAfterUpdate.Status);
|
|---|
| 61 | Assert.That(paymentAfterUpdate.Status, Is.EqualTo(false));
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | [Test]
|
|---|
| 65 | [Category("Unit")]
|
|---|
| 66 | public void Show_Action_Returns_Error_View_When_Passing_Incorrect_User_Identity()
|
|---|
| 67 | {
|
|---|
| 68 | //Arrange
|
|---|
| 69 | IRepository<Invoice> repVPayment = new Repository<Invoice>(new FakeDataContext());
|
|---|
| 70 | var invoice = _testDataHelper.CreateInvoice(123, "nip1", "", 0, 0);
|
|---|
| 71 | repVPayment.Insert(invoice);
|
|---|
| 72 |
|
|---|
| 73 | var controller = new PlatnoscController(repVPayment, null, null, _translateManager);
|
|---|
| 74 | controller.ControllerContext = _testDataHelper.CreateControllerContext("nip2");
|
|---|
| 75 |
|
|---|
| 76 | //Act
|
|---|
| 77 | var result = controller.Show("123","pl") as ViewResult;
|
|---|
| 78 | var error = (ErrorViewData)result.ViewData.Model;
|
|---|
| 79 |
|
|---|
| 80 | //Assert
|
|---|
| 81 | Assert.That(error.Error, Is.EqualTo("weryfikacja"));
|
|---|
| 82 | Assert.That(result.ViewName, Is.EqualTo("Error1"));
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | [Test]
|
|---|
| 86 | [Category("Unit")]
|
|---|
| 87 | public void Show_Action_Returns_Error_View_When_Payment_Is_Not_Found()
|
|---|
| 88 | {
|
|---|
| 89 | //Arrange
|
|---|
| 90 | IRepository<Invoice> repVPayment = new Repository<Invoice>(new FakeDataContext());
|
|---|
| 91 | var invoice = _testDataHelper.CreateInvoice(123, "nip2", "", 0, 0);
|
|---|
| 92 | repVPayment.Insert(invoice);
|
|---|
| 93 |
|
|---|
| 94 | var controller = new PlatnoscController(repVPayment, null, null, _translateManager);
|
|---|
| 95 | controller.ControllerContext = _testDataHelper.CreateControllerContext("nip2");
|
|---|
| 96 |
|
|---|
| 97 | //Act
|
|---|
| 98 | var result = controller.Show("1234", "pl") as ViewResult;
|
|---|
| 99 | var error = (ErrorViewData)result.ViewData.Model;
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 | //Assert
|
|---|
| 103 | Assert.That(error.Error, Is.EqualTo("brakdanych"));
|
|---|
| 104 | Assert.That(result.ViewName, Is.EqualTo("Error1"));
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | [Test]
|
|---|
| 108 | [Category("Unit")]
|
|---|
| 109 | public void Show_Action_Returns_Paid_View_When_Payment_Is_Paid()
|
|---|
| 110 | {
|
|---|
| 111 | //Arrange
|
|---|
| 112 | //Tworzymy takie dane aby platnosc o danym id byla juz zaplacona
|
|---|
| 113 | var repVPayment = new Repository<Invoice>(new FakeDataContext());
|
|---|
| 114 | var invoice = _testDataHelper.CreateInvoice(123, "nip1", "aaa", 0, 0);
|
|---|
| 115 | repVPayment.Insert(invoice);
|
|---|
| 116 | repVPayment.SubmitChanges();
|
|---|
| 117 |
|
|---|
| 118 | var repConfirm = new Repository<PotwierdzeniaEcard>(new FakeDataContext());
|
|---|
| 119 | var confirm = _testDataHelper.CreateConfirm(CODE_OK, 123456);
|
|---|
| 120 | repConfirm.Insert(confirm);
|
|---|
| 121 | repConfirm.SubmitChanges();
|
|---|
| 122 |
|
|---|
| 123 | var controller = new PlatnoscController(repVPayment, null, repConfirm, _translateManager);
|
|---|
| 124 | controller.ControllerContext = _testDataHelper.CreateControllerContext("nip1");
|
|---|
| 125 |
|
|---|
| 126 | //Act
|
|---|
| 127 | var result = controller.Show("123", "pl") as ViewResult;
|
|---|
| 128 | var view = (InvoiceDetailsViewData)result.ViewData.Model;
|
|---|
| 129 |
|
|---|
| 130 | //Assert
|
|---|
| 131 | Assert.That(result.ViewName, Is.EqualTo("Paid"));
|
|---|
| 132 | Assert.That(view.Info, Is.EqualTo("zaplacono"));
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | [Test]
|
|---|
| 136 | [Category("Unit")]
|
|---|
| 137 | public void Show_Action_Returns_View_For_Payment_When_Payment_is_Outstanding()
|
|---|
| 138 | {
|
|---|
| 139 | //Arrange
|
|---|
| 140 | IRepository<Invoice> repVPayment = new Repository<Invoice>(new FakeDataContext());
|
|---|
| 141 | var invoice = _testDataHelper.CreateInvoice(123, "nip1", "numer", 200, 0);
|
|---|
| 142 | repVPayment.Insert(invoice);
|
|---|
| 143 |
|
|---|
| 144 | var repConfirm = new Repository<PotwierdzeniaEcard>(new FakeDataContext());
|
|---|
| 145 | var confirm = _testDataHelper.CreateConfirm(CODE_OK, 1);
|
|---|
| 146 | repConfirm.Insert(confirm);
|
|---|
| 147 | repConfirm.SubmitChanges();
|
|---|
| 148 |
|
|---|
| 149 | var controller = new PlatnoscController(repVPayment, null, repConfirm, _translateManager);
|
|---|
| 150 | controller.ControllerContext = _testDataHelper.CreateControllerContext("nip1");
|
|---|
| 151 |
|
|---|
| 152 | //Act
|
|---|
| 153 | var result = controller.Show("123", "pl") as ViewResult;
|
|---|
| 154 | var view = (InvoiceDetailsViewData)result.ViewData.Model;
|
|---|
| 155 | System.Diagnostics.Debug.WriteLine("Brutto 200: " + view.Invoice.Brutto);
|
|---|
| 156 | System.Diagnostics.Debug.WriteLine("Nr Faktury musi byc 'numer'. Jest " + view.Invoice.Faktura_Numer);
|
|---|
| 157 |
|
|---|
| 158 | //Assert
|
|---|
| 159 | Assert.That(view.Invoice.Brutto, Is.EqualTo(200));
|
|---|
| 160 | Assert.That(view.Invoice.Faktura_Numer, Is.EqualTo("numer"));
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | [Test]
|
|---|
| 164 | [Category("Unit")]
|
|---|
| 165 | public void AfterPay_Show_Action_Returns_Error_When_Name_Is_Null()
|
|---|
| 166 | {
|
|---|
| 167 | //Arrange
|
|---|
| 168 | IRepository<Invoice> repVPayment = new Repository<Invoice>(new FakeDataContext());
|
|---|
| 169 | var invoice = _testDataHelper.CreateInvoice(123, "nip1", "numer", 200, 0);
|
|---|
| 170 | repVPayment.Insert(invoice);
|
|---|
| 171 |
|
|---|
| 172 | var controller = new PlatnoscController(repVPayment, null, null, _translateManager);
|
|---|
| 173 | controller.ControllerContext = _testDataHelper.CreateControllerContext("nip1");
|
|---|
| 174 |
|
|---|
| 175 | Payer payer = _testDataHelper.CreatePayer(123, "", "test"); //Brak imienia
|
|---|
| 176 |
|
|---|
| 177 | //Act
|
|---|
| 178 | controller.Show(payer, "pl");
|
|---|
| 179 |
|
|---|
| 180 | //Assert
|
|---|
| 181 | Assert.That(controller.ModelState.IsValid, Is.False);
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | [Test]
|
|---|
| 185 | [Category("Unit")]
|
|---|
| 186 | public void AfterPay_Show_Action_Returns_Error_When_Surname_Is_Null()
|
|---|
| 187 | {
|
|---|
| 188 | //Arrange
|
|---|
| 189 | IRepository<Invoice> repVPayment = new Repository<Invoice>(new FakeDataContext());
|
|---|
| 190 | var invoice = _testDataHelper.CreateInvoice(123, "nip1", "numer", 200, 0);
|
|---|
| 191 | repVPayment.Insert(invoice);
|
|---|
| 192 |
|
|---|
| 193 | var controller = new PlatnoscController(repVPayment, null, null, _translateManager);
|
|---|
| 194 | controller.ControllerContext = _testDataHelper.CreateControllerContext("nip1");
|
|---|
| 195 |
|
|---|
| 196 | Payer payer = _testDataHelper.CreatePayer(123, "test", ""); //Brak nazwiska
|
|---|
| 197 |
|
|---|
| 198 | //Act
|
|---|
| 199 | controller.Show(payer, "pl");
|
|---|
| 200 |
|
|---|
| 201 | //Assert
|
|---|
| 202 | Assert.That(controller.ModelState.IsValid, Is.False);
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | [Test]
|
|---|
| 206 | [Category("Unit")]
|
|---|
| 207 | public void AfterPay_Show_Action_Returns_Error_When_Name_Is_Too_Long()
|
|---|
| 208 | {
|
|---|
| 209 | //Arrange
|
|---|
| 210 | IRepository<Invoice> repVPayment = new Repository<Invoice>(new FakeDataContext());
|
|---|
| 211 | var invoice = _testDataHelper.CreateInvoice(123, "nip1", "numer", 200, 0);
|
|---|
| 212 | repVPayment.Insert(invoice);
|
|---|
| 213 |
|
|---|
| 214 | var controller = new PlatnoscController(repVPayment, null, null, _translateManager);
|
|---|
| 215 | controller.ControllerContext = _testDataHelper.CreateControllerContext("nip1");
|
|---|
| 216 | var firstname = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
|---|
| 217 | var payer = _testDataHelper.CreatePayer(123, firstname, "test");
|
|---|
| 218 |
|
|---|
| 219 | //Act
|
|---|
| 220 | controller.Show(payer, "pl");
|
|---|
| 221 |
|
|---|
| 222 | //Assert
|
|---|
| 223 | Assert.That(controller.ModelState.IsValid, Is.False);
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | [Test]
|
|---|
| 227 | [Category("Unit")]
|
|---|
| 228 | public void AfterPay_Show_Action_Returns_Error_When_Surname_Is_Too_Long()
|
|---|
| 229 | {
|
|---|
| 230 | //Arrange
|
|---|
| 231 | IRepository<Invoice> repVPayment = new Repository<Invoice>(new FakeDataContext());
|
|---|
| 232 | var invoice = _testDataHelper.CreateInvoice(123, "nip1", "numer", 200, 0);
|
|---|
| 233 | repVPayment.Insert(invoice);
|
|---|
| 234 |
|
|---|
| 235 | var controller = new PlatnoscController(repVPayment, null, null, _translateManager);
|
|---|
| 236 | controller.ControllerContext = _testDataHelper.CreateControllerContext("nip1");
|
|---|
| 237 | var surname = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
|---|
| 238 | var payer = _testDataHelper.CreatePayer(123, "test", surname);
|
|---|
| 239 |
|
|---|
| 240 | //Act
|
|---|
| 241 | controller.Show(payer, "pl");
|
|---|
| 242 |
|
|---|
| 243 | //Assert
|
|---|
| 244 | Assert.That(controller.ModelState.IsValid, Is.False);
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | [Test]
|
|---|
| 248 | [Category("Unit")]
|
|---|
| 249 | public void AfterPay_Show_Action_Returns_Error_When_Name_And_Surname_Is_Not_Null()
|
|---|
| 250 | {
|
|---|
| 251 | //Arrange
|
|---|
| 252 | IRepository<Invoice> repVPayment = new Repository<Invoice>(new FakeDataContext());
|
|---|
| 253 | var invoice = _testDataHelper.CreateInvoice(123, "nip1", "numer", 200, 0);
|
|---|
| 254 | repVPayment.Insert(invoice);
|
|---|
| 255 |
|
|---|
| 256 | var controller = new PlatnoscController(repVPayment, null, null, _translateManager);
|
|---|
| 257 | controller.ControllerContext = _testDataHelper.CreateControllerContext("nip1");
|
|---|
| 258 |
|
|---|
| 259 | var payer = _testDataHelper.CreatePayer(123, "test", "test");
|
|---|
| 260 |
|
|---|
| 261 | //Act
|
|---|
| 262 | controller.Show(payer, "pl");
|
|---|
| 263 |
|
|---|
| 264 | //Assert
|
|---|
| 265 | System.Diagnostics.Debug.WriteLine("Model powinien byc 'true'. Jest " + controller.ModelState.IsValid);
|
|---|
| 266 | Assert.That(controller.ModelState.IsValid, Is.True);
|
|---|
| 267 | }
|
|---|
| 268 | }
|
|---|
| 269 | } |
|---|