| 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.Web.Controllers;
|
|---|
| 7 | using adMoto.Payments.Web.Models;
|
|---|
| 8 | using NUnit.Framework;
|
|---|
| 9 |
|
|---|
| 10 | namespace adMoto.Payments.Test.Web
|
|---|
| 11 | {
|
|---|
| 12 | [TestFixture]
|
|---|
| 13 | public class PlatnosciControllerTests
|
|---|
| 14 | {
|
|---|
| 15 | private readonly ITranslateManager _translateManager = new FakeTranslation();
|
|---|
| 16 | private const string MERCHANT_NUMBER = "123";
|
|---|
| 17 | private readonly int _orderNumber = 9999;
|
|---|
| 18 | private const string CODE_OK = "payment_deposited"; //transakcja potwierdzona do rozliczenia
|
|---|
| 19 | private const string CODE_BAD = "payment_declined"; //transakcja odrzucona
|
|---|
| 20 | private readonly DateTime _data = DateTime.Now;
|
|---|
| 21 | private readonly Function _function = new Function();
|
|---|
| 22 |
|
|---|
| 23 | //[Test]
|
|---|
| 24 | //[Category("Unit")]
|
|---|
| 25 | //public void Status_Action_Saves_Correct_Transaction()
|
|---|
| 26 | //{
|
|---|
| 27 | // //Arrange
|
|---|
| 28 | // var repository = new Repository<PlatnosciEcard>(new FakeDataContext());
|
|---|
| 29 | // var platnosci = _function.CreateNewPayment(_orderNumber, false, DateTime.Now, 12345);
|
|---|
| 30 | // repository.Insert(platnosci);
|
|---|
| 31 | // repository.SubmitChanges();
|
|---|
| 32 |
|
|---|
| 33 | // IRepository<PotwierdzeniaEcard> rep = new Repository<PotwierdzeniaEcard>(new FakeDataContext());
|
|---|
| 34 |
|
|---|
| 35 | // var builder = new TestControllerBuilder();
|
|---|
| 36 | // var controller = new PlatnoscController(null, repository, rep, _translateManager);
|
|---|
| 37 | // builder.InitializeController(controller);
|
|---|
| 38 | // builder.QueryString.Add("MERCHANTNUMBER", MERCHANT_NUMBER);
|
|---|
| 39 | // builder.QueryString.Add("AUTHTIME", DateTime.Now.ToString());
|
|---|
| 40 | // builder.QueryString.Add("DATATRANSMISJI", DateTime.Now.ToString());
|
|---|
| 41 | // builder.QueryString.Add("ORDERNUMBER", _orderNumber.ToString());
|
|---|
| 42 | // builder.QueryString.Add("CURRENTSTATE", CODE_OK);
|
|---|
| 43 |
|
|---|
| 44 | // //Act
|
|---|
| 45 | // controller.Status();
|
|---|
| 46 | // System.Diagnostics.Debug.WriteLine("rep:" + rep.Count() + " repPl: " + repository.Count() );
|
|---|
| 47 | // var potwierdzeniaEcard = rep.Find(o => o.ORDERNUMBER == _orderNumber).SingleOrDefault();
|
|---|
| 48 |
|
|---|
| 49 | // //Assert
|
|---|
| 50 | // Assert.That(potwierdzeniaEcard.MERCHANTNUMBER, Is.EqualTo(MERCHANT_NUMBER));
|
|---|
| 51 |
|
|---|
| 52 | // //Act
|
|---|
| 53 | // var paymentAfterUpdate = repository.FindOne(_orderNumber);
|
|---|
| 54 | // System.Diagnostics.Debug.WriteLine("Status musi byc 'true'. Jest " + paymentAfterUpdate.Status);
|
|---|
| 55 |
|
|---|
| 56 | // //Assert
|
|---|
| 57 | // Assert.That(paymentAfterUpdate.Status, Is.EqualTo(true));
|
|---|
| 58 | //}
|
|---|
| 59 |
|
|---|
| 60 | //[Test]
|
|---|
| 61 | //[Category("Unit")]
|
|---|
| 62 | //public void Status_Action_Payment_Is_Not_Update_When_Currentstate_Is_CODE_BAD()
|
|---|
| 63 | //{
|
|---|
| 64 | // //Arrange
|
|---|
| 65 | // var repPayment = new Repository<PlatnosciEcard>(new FakeDataContext());
|
|---|
| 66 | // var platnosci = _function.CreateNewPayment(_orderNumber, false, DateTime.Now, 12345);
|
|---|
| 67 | // repPayment.Insert(platnosci);
|
|---|
| 68 | // repPayment.SubmitChanges();
|
|---|
| 69 | // IRepository<PotwierdzeniaEcard> repConfirm = new Repository<PotwierdzeniaEcard>(new FakeDataContext());
|
|---|
| 70 |
|
|---|
| 71 | // var builder = new TestControllerBuilder();
|
|---|
| 72 | // var controller = new PlatnoscController(null, repPayment, repConfirm, _translateManager);
|
|---|
| 73 | // builder.InitializeController(controller);
|
|---|
| 74 | // builder.QueryString.Add("MERCHANTNUMBER", MERCHANT_NUMBER);
|
|---|
| 75 | // builder.QueryString.Add("AUTHTIME", DateTime.Now.ToString());
|
|---|
| 76 | // builder.QueryString.Add("DATATRANSMISJI", DateTime.Now.ToString());
|
|---|
| 77 | // builder.QueryString.Add("ORDERNUMBER", _orderNumber.ToString());
|
|---|
| 78 | // builder.QueryString.Add("CURRENTSTATE", CODE_BAD);
|
|---|
| 79 |
|
|---|
| 80 | // //Act
|
|---|
| 81 | // controller.Status();
|
|---|
| 82 | // var potwierdzeniaEcard = repConfirm.Find(o => o.ORDERNUMBER == _orderNumber).SingleOrDefault();
|
|---|
| 83 |
|
|---|
| 84 | // //Assert
|
|---|
| 85 | // Assert.That(potwierdzeniaEcard.MERCHANTNUMBER, Is.EqualTo(MERCHANT_NUMBER));
|
|---|
| 86 |
|
|---|
| 87 | // //Act
|
|---|
| 88 | // var paymentAfterUpdate = repPayment.FindOne(_orderNumber);
|
|---|
| 89 | // System.Diagnostics.Debug.WriteLine("Status musi byc 'false'. Jest " + paymentAfterUpdate.Status);
|
|---|
| 90 |
|
|---|
| 91 | // //Assert
|
|---|
| 92 | // Assert.That(paymentAfterUpdate.Status, Is.EqualTo(false));
|
|---|
| 93 | //}
|
|---|
| 94 |
|
|---|
| 95 | [Test]
|
|---|
| 96 | [Category("Unit")]
|
|---|
| 97 | public void Update_Status_Payment_Is_Update_When_Currentstate_Is_CODE_OK()
|
|---|
| 98 | {
|
|---|
| 99 | //Arrange
|
|---|
| 100 | IRepository<PlatnosciEcard> repPayment = new Repository<PlatnosciEcard>(new FakeDataContext());
|
|---|
| 101 | PlatnosciEcard platnosc = _function.CreateNewPayment(_orderNumber, false, _data, 1);
|
|---|
| 102 | repPayment.Insert(platnosc);
|
|---|
| 103 |
|
|---|
| 104 | //Act
|
|---|
| 105 | var controller = new PlatnoscController(null, repPayment, null, _translateManager);
|
|---|
| 106 | controller.UpdateStatus(_orderNumber, CODE_OK);
|
|---|
| 107 |
|
|---|
| 108 | var paymentAfterUpdate = repPayment.FindOne(_orderNumber);
|
|---|
| 109 |
|
|---|
| 110 | //Assert
|
|---|
| 111 | System.Diagnostics.Debug.WriteLine("Status musi byc 'true'. Jest " + paymentAfterUpdate.Status);
|
|---|
| 112 | Assert.That(paymentAfterUpdate.Status, Is.EqualTo(true));
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | [Test]
|
|---|
| 116 | [Category("Unit")]
|
|---|
| 117 | public void Update_Status_Payment_Is_Not_Update_When_Currentstate_Is_CODE_BAD()
|
|---|
| 118 | {
|
|---|
| 119 | //Arrange
|
|---|
| 120 | IRepository<PlatnosciEcard> repPayment = new Repository<PlatnosciEcard>(new FakeDataContext());
|
|---|
| 121 | var platnosc = _function.CreateNewPayment(_orderNumber, false, _data, 1);
|
|---|
| 122 | repPayment.Insert(platnosc);
|
|---|
| 123 |
|
|---|
| 124 | var controller = new PlatnoscController(null, repPayment, null, _translateManager);
|
|---|
| 125 |
|
|---|
| 126 | //Act
|
|---|
| 127 | controller.UpdateStatus(_orderNumber, CODE_BAD);
|
|---|
| 128 | var paymentAfterUpdate = repPayment.FindOne(i => i.ORDERNUMBER == _orderNumber);
|
|---|
| 129 |
|
|---|
| 130 | //Assert
|
|---|
| 131 | System.Diagnostics.Debug.WriteLine("Status musi byc 'false'. Jest " + paymentAfterUpdate.Status);
|
|---|
| 132 | Assert.That(paymentAfterUpdate.Status, Is.EqualTo(false));
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | [Test]
|
|---|
| 136 | [Category("Unit")]
|
|---|
| 137 | public void Show_Action_Returns_Error_View_When_Passing_Incorrect_User_Identity()
|
|---|
| 138 | {
|
|---|
| 139 | //Arrange
|
|---|
| 140 | IRepository<Invoice> repVPayment = new Repository<Invoice>(new FakeDataContext());
|
|---|
| 141 | var platnosc = _function.CreateInvoice(123, "nip1", "", 0, 0);
|
|---|
| 142 | repVPayment.Insert(platnosc);
|
|---|
| 143 |
|
|---|
| 144 | var controller = new PlatnoscController(repVPayment, null, null, _translateManager);
|
|---|
| 145 | controller.ControllerContext = _function.CreateControllerContext("nip2");
|
|---|
| 146 |
|
|---|
| 147 | //Act
|
|---|
| 148 | var result = controller.Show("123","pl") as ViewResult;
|
|---|
| 149 | var error = (ErrorViewData)result.ViewData.Model;
|
|---|
| 150 |
|
|---|
| 151 | //Assert
|
|---|
| 152 | Assert.That(error.Error, Is.EqualTo("weryfikacja"));
|
|---|
| 153 | Assert.That(result.ViewName, Is.EqualTo("Error1"));
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | [Test]
|
|---|
| 157 | [Category("Unit")]
|
|---|
| 158 | public void Show_Action_Returns_Error_View_When_Payment_Is_Not_Found()
|
|---|
| 159 | {
|
|---|
| 160 | //Arrange
|
|---|
| 161 | IRepository<Invoice> repVPayment = new Repository<Invoice>(new FakeDataContext());
|
|---|
| 162 | var platnosc = _function.CreateInvoice(123, "nip2", "", 0, 0);
|
|---|
| 163 | repVPayment.Insert(platnosc);
|
|---|
| 164 |
|
|---|
| 165 | var controller = new PlatnoscController(repVPayment, null, null, _translateManager);
|
|---|
| 166 | controller.ControllerContext = _function.CreateControllerContext("nip2");
|
|---|
| 167 |
|
|---|
| 168 | //Act
|
|---|
| 169 | var result = controller.Show("1234", "pl") as ViewResult;
|
|---|
| 170 | var error = (ErrorViewData)result.ViewData.Model;
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 | //Assert
|
|---|
| 174 | Assert.That(error.Error, Is.EqualTo("brakdanych"));
|
|---|
| 175 | Assert.That(result.ViewName, Is.EqualTo("Error1"));
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | [Test]
|
|---|
| 179 | [Category("Unit")]
|
|---|
| 180 | public void Show_Action_Returns_Paid_View_When_Payment_Is_Paid()
|
|---|
| 181 | {
|
|---|
| 182 | //Arrange
|
|---|
| 183 | //Tworzymy takie dane aby platnosc o danym id byla juz zaplacona
|
|---|
| 184 | var repVPayment = new Repository<Invoice>(new FakeDataContext());
|
|---|
| 185 | var invoice = _function.CreateInvoice(123, "nip1", "aaa", 0, 0);
|
|---|
| 186 | repVPayment.Insert(invoice);
|
|---|
| 187 | repVPayment.SubmitChanges();
|
|---|
| 188 |
|
|---|
| 189 | var repConfirm = new Repository<PotwierdzeniaEcard>(new FakeDataContext());
|
|---|
| 190 | var confirm = _function.CreateConfirm(CODE_OK, 123456);
|
|---|
| 191 | repConfirm.Insert(confirm);
|
|---|
| 192 | repConfirm.SubmitChanges();
|
|---|
| 193 |
|
|---|
| 194 | var controller = new PlatnoscController(repVPayment, null, repConfirm, _translateManager);
|
|---|
| 195 | controller.ControllerContext = _function.CreateControllerContext("nip1");
|
|---|
| 196 |
|
|---|
| 197 | //Act
|
|---|
| 198 | var result = controller.Show("123", "pl") as ViewResult;
|
|---|
| 199 | var view = (InvoiceDetailsViewData)result.ViewData.Model;
|
|---|
| 200 |
|
|---|
| 201 | //Assert
|
|---|
| 202 | Assert.That(result.ViewName, Is.EqualTo("Paid"));
|
|---|
| 203 | Assert.That(view.Info, Is.EqualTo("zaplacono"));
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | [Test]
|
|---|
| 207 | [Category("Unit")]
|
|---|
| 208 | public void Show_Action_Returns_View_For_Payment_When_Payment_is_Outstanding()
|
|---|
| 209 | {
|
|---|
| 210 | //Arrange
|
|---|
| 211 | IRepository<Invoice> repVPayment = new Repository<Invoice>(new FakeDataContext());
|
|---|
| 212 | var platnosc = _function.CreateInvoice(123, "nip1", "numer", 200, 0);
|
|---|
| 213 | repVPayment.Insert(platnosc);
|
|---|
| 214 |
|
|---|
| 215 | var repConfirm = new Repository<PotwierdzeniaEcard>(new FakeDataContext());
|
|---|
| 216 | var confirm = _function.CreateConfirm(CODE_OK, 1);
|
|---|
| 217 | repConfirm.Insert(confirm);
|
|---|
| 218 | repConfirm.SubmitChanges();
|
|---|
| 219 |
|
|---|
| 220 | var controller = new PlatnoscController(repVPayment, null, repConfirm, _translateManager);
|
|---|
| 221 | controller.ControllerContext = _function.CreateControllerContext("nip1");
|
|---|
| 222 |
|
|---|
| 223 | //Act
|
|---|
| 224 | var result = controller.Show("123", "pl") as ViewResult;
|
|---|
| 225 | var view = (InvoiceDetailsViewData)result.ViewData.Model;
|
|---|
| 226 | System.Diagnostics.Debug.WriteLine("Brutto 200: " + view.Invoice.Brutto);
|
|---|
| 227 | System.Diagnostics.Debug.WriteLine("Nr Faktury musi byc 'numer'. Jest " + view.Invoice.Faktura_Numer);
|
|---|
| 228 |
|
|---|
| 229 | //Assert
|
|---|
| 230 | Assert.That(view.Invoice.Brutto, Is.EqualTo(200));
|
|---|
| 231 | Assert.That(view.Invoice.Faktura_Numer, Is.EqualTo("numer"));
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | [Test]
|
|---|
| 235 | [Category("Unit")]
|
|---|
| 236 | public void AfterPay_Show_Action_Returns_Error_When_Name_Is_Null()
|
|---|
| 237 | {
|
|---|
| 238 | //Arrange
|
|---|
| 239 | IRepository<Invoice> repVPayment = new Repository<Invoice>(new FakeDataContext());
|
|---|
| 240 | var platnosc = _function.CreateInvoice(123, "nip1", "numer", 200, 0);
|
|---|
| 241 | repVPayment.Insert(platnosc);
|
|---|
| 242 |
|
|---|
| 243 | var controller = new PlatnoscController(repVPayment, null, null, _translateManager);
|
|---|
| 244 | controller.ControllerContext = _function.CreateControllerContext("nip1");
|
|---|
| 245 |
|
|---|
| 246 | Payer payer = _function.CreatePayer(123, "", "test"); //Brak imienia
|
|---|
| 247 |
|
|---|
| 248 | //Act
|
|---|
| 249 | controller.Show(payer, "pl");
|
|---|
| 250 |
|
|---|
| 251 | //Assert
|
|---|
| 252 | Assert.That(controller.ModelState.IsValid, Is.False);
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | [Test]
|
|---|
| 256 | [Category("Unit")]
|
|---|
| 257 | public void AfterPay_Show_Action_Returns_Error_When_Surname_Is_Null()
|
|---|
| 258 | {
|
|---|
| 259 | //Arrange
|
|---|
| 260 | IRepository<Invoice> repVPayment = new Repository<Invoice>(new FakeDataContext());
|
|---|
| 261 | var platnosc = _function.CreateInvoice(123, "nip1", "numer", 200, 0);
|
|---|
| 262 | repVPayment.Insert(platnosc);
|
|---|
| 263 |
|
|---|
| 264 | var controller = new PlatnoscController(repVPayment, null, null, _translateManager);
|
|---|
| 265 | controller.ControllerContext = _function.CreateControllerContext("nip1");
|
|---|
| 266 |
|
|---|
| 267 | Payer payer = _function.CreatePayer(123, "test", ""); //Brak nazwiska
|
|---|
| 268 |
|
|---|
| 269 | //Act
|
|---|
| 270 | controller.Show(payer, "pl");
|
|---|
| 271 |
|
|---|
| 272 | //Assert
|
|---|
| 273 | Assert.That(controller.ModelState.IsValid, Is.False);
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 | [Test]
|
|---|
| 277 | [Category("Unit")]
|
|---|
| 278 | public void AfterPay_Show_Action_Returns_Error_When_Name_Is_Too_Long()
|
|---|
| 279 | {
|
|---|
| 280 | //Arrange
|
|---|
| 281 | IRepository<Invoice> repVPayment = new Repository<Invoice>(new FakeDataContext());
|
|---|
| 282 | var platnosc = _function.CreateInvoice(123, "nip1", "numer", 200, 0);
|
|---|
| 283 | repVPayment.Insert(platnosc);
|
|---|
| 284 |
|
|---|
| 285 | var controller = new PlatnoscController(repVPayment, null, null, _translateManager);
|
|---|
| 286 | controller.ControllerContext = _function.CreateControllerContext("nip1");
|
|---|
| 287 | var name = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
|---|
| 288 | var payer = _function.CreatePayer(123, name, "test");
|
|---|
| 289 |
|
|---|
| 290 | //Act
|
|---|
| 291 | controller.Show(payer, "pl");
|
|---|
| 292 |
|
|---|
| 293 | //Assert
|
|---|
| 294 | Assert.That(controller.ModelState.IsValid, Is.False);
|
|---|
| 295 | }
|
|---|
| 296 |
|
|---|
| 297 | [Test]
|
|---|
| 298 | [Category("Unit")]
|
|---|
| 299 | public void AfterPay_Show_Action_Returns_Error_When_Surname_Is_Too_Long()
|
|---|
| 300 | {
|
|---|
| 301 | //Arrange
|
|---|
| 302 | IRepository<Invoice> repVPayment = new Repository<Invoice>(new FakeDataContext());
|
|---|
| 303 | var platnosc = _function.CreateInvoice(123, "nip1", "numer", 200, 0);
|
|---|
| 304 | repVPayment.Insert(platnosc);
|
|---|
| 305 |
|
|---|
| 306 | var controller = new PlatnoscController(repVPayment, null, null, _translateManager);
|
|---|
| 307 | controller.ControllerContext = _function.CreateControllerContext("nip1");
|
|---|
| 308 | var surname = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
|---|
| 309 | var payer = _function.CreatePayer(123, "test", surname);
|
|---|
| 310 |
|
|---|
| 311 | //Act
|
|---|
| 312 | controller.Show(payer, "pl");
|
|---|
| 313 |
|
|---|
| 314 | //Assert
|
|---|
| 315 | Assert.That(controller.ModelState.IsValid, Is.False);
|
|---|
| 316 | }
|
|---|
| 317 |
|
|---|
| 318 | [Test]
|
|---|
| 319 | [Category("Unit")]
|
|---|
| 320 | public void AfterPay_Show_Action_Returns_Error_When_Name_And_Surname_Is_Not_Null()
|
|---|
| 321 | {
|
|---|
| 322 | //Arrange
|
|---|
| 323 | IRepository<Invoice> repVPayment = new Repository<Invoice>(new FakeDataContext());
|
|---|
| 324 | var platnosc = _function.CreateInvoice(123, "nip1", "numer", 200, 0);
|
|---|
| 325 | repVPayment.Insert(platnosc);
|
|---|
| 326 |
|
|---|
| 327 | var controller = new PlatnoscController(repVPayment, null, null, _translateManager);
|
|---|
| 328 | controller.ControllerContext = _function.CreateControllerContext("nip1");
|
|---|
| 329 |
|
|---|
| 330 | var payer = _function.CreatePayer(123, "test", "test");
|
|---|
| 331 |
|
|---|
| 332 | //Act
|
|---|
| 333 | controller.Show(payer, "pl");
|
|---|
| 334 |
|
|---|
| 335 | //Assert
|
|---|
| 336 | System.Diagnostics.Debug.WriteLine("Model powinien byc 'true'. Jest " + controller.ModelState.IsValid);
|
|---|
| 337 | Assert.That(controller.ModelState.IsValid, Is.True);
|
|---|
| 338 | }
|
|---|
| 339 | }
|
|---|
| 340 | }
|
|---|
| 341 |
|
|---|