| 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;
|
|---|
| 13 | using WatiN.Core;
|
|---|
| 14 | using System.Threading;
|
|---|
| 15 | using Platnosci.Models;
|
|---|
| 16 | using Moq;
|
|---|
| 17 |
|
|---|
| 18 | namespace Platnosci.Tests.Web
|
|---|
| 19 | {
|
|---|
| 20 | [TestFixture]
|
|---|
| 21 |
|
|---|
| 22 | class PlatnosciControllerTests
|
|---|
| 23 | {
|
|---|
| 24 | private string merchantNumber = "123";
|
|---|
| 25 | private FunkcjePlatnosci _func = new FunkcjePlatnosci();
|
|---|
| 26 |
|
|---|
| 27 | /*[TearDown]
|
|---|
| 28 | public void TearDown()
|
|---|
| 29 | {
|
|---|
| 30 | IRepository<PotwierdzeniaEcard> _rep = new Repository<PotwierdzeniaEcard>();
|
|---|
| 31 | var potwierdzeniaEcard = _rep.Find(p => p.MERCHANTNUMBER == merchantNumber);
|
|---|
| 32 |
|
|---|
| 33 | foreach (var pe in potwierdzeniaEcard)
|
|---|
| 34 | {
|
|---|
| 35 | _rep.Delete(pe);
|
|---|
| 36 | }
|
|---|
| 37 | }
|
|---|
| 38 | */
|
|---|
| 39 |
|
|---|
| 40 | public vPlatnosciEcard createPayment(int id, string nip, string fak_numer, decimal brutto, byte SystemKsiegowy)
|
|---|
| 41 | {
|
|---|
| 42 |
|
|---|
| 43 | vPlatnosciEcard platnosc = new vPlatnosciEcard();
|
|---|
| 44 | platnosc.ID_faktury = id;
|
|---|
| 45 | platnosc.nip = nip;
|
|---|
| 46 | platnosc.Faktura_Numer = fak_numer;
|
|---|
| 47 | platnosc.Brutto = brutto;
|
|---|
| 48 | platnosc.SystemKsiegowyId = SystemKsiegowy;
|
|---|
| 49 |
|
|---|
| 50 | return platnosc;
|
|---|
| 51 | }
|
|---|
| 52 | public PlatnosciEcard createNewPayment(int ordernumber, bool status, DateTime data, int id_faktury)
|
|---|
| 53 | {
|
|---|
| 54 | PlatnosciEcard platnosc = new PlatnosciEcard();
|
|---|
| 55 | platnosc.ORDERNUMBER = ordernumber;
|
|---|
| 56 | platnosc.Status = status;
|
|---|
| 57 | platnosc.Status_data = data;
|
|---|
| 58 | platnosc.IDFaktury = id_faktury;
|
|---|
| 59 |
|
|---|
| 60 | return platnosc;
|
|---|
| 61 | }
|
|---|
| 62 | public Payer createPayer(int id, string name, string surname)
|
|---|
| 63 | {
|
|---|
| 64 | Payer payer = new Payer();
|
|---|
| 65 | payer.Id_faktury = id;
|
|---|
| 66 | payer.FirstName = name;
|
|---|
| 67 | payer.LastName = surname;
|
|---|
| 68 |
|
|---|
| 69 | return payer;
|
|---|
| 70 | }
|
|---|
| 71 | public ControllerContext createControllerContext(string UserIdentity)
|
|---|
| 72 | {
|
|---|
| 73 |
|
|---|
| 74 | var mock = new Mock<ControllerContext>();
|
|---|
| 75 | mock.SetupGet(m => m.HttpContext.User.Identity.Name).Returns(UserIdentity);
|
|---|
| 76 | mock.SetupGet(m => m.HttpContext.Request.IsAuthenticated).Returns(true);
|
|---|
| 77 |
|
|---|
| 78 | return mock.Object;
|
|---|
| 79 | }
|
|---|
| 80 | [Test]
|
|---|
| 81 | [Category("Unit")]
|
|---|
| 82 | public void Status_Saves_Correct_Transaction()
|
|---|
| 83 | {
|
|---|
| 84 | var orderNumber = 9999;
|
|---|
| 85 | FakeDataContext fake = new FakeDataContext();
|
|---|
| 86 | var builder = new TestControllerBuilder();
|
|---|
| 87 | var controller = new PlatnoscController(fake);
|
|---|
| 88 | builder.InitializeController(controller);
|
|---|
| 89 | builder.Form.Add("MERCHANTNUMBER", merchantNumber.ToString());
|
|---|
| 90 | builder.Form.Add("AUTHTIME", DateTime.Now.ToString());
|
|---|
| 91 | builder.Form.Add("DATATRANSMISJI", DateTime.Now.ToString());
|
|---|
| 92 | builder.Form.Add("ORDERNUMBER", orderNumber.ToString());
|
|---|
| 93 |
|
|---|
| 94 | var result = controller.Status();
|
|---|
| 95 |
|
|---|
| 96 | IRepository<PotwierdzeniaEcard> _rep = new Repository<PotwierdzeniaEcard>(fake);
|
|---|
| 97 | var potwierdzeniaEcard = _rep.Find(p => p.ORDERNUMBER == orderNumber).First();
|
|---|
| 98 | Assert.That(potwierdzeniaEcard.MERCHANTNUMBER, Is.EqualTo(merchantNumber));
|
|---|
| 99 | }
|
|---|
| 100 | [Test]
|
|---|
| 101 | [Category("Unit")]
|
|---|
| 102 | public void StatusIsUpdated()
|
|---|
| 103 | {
|
|---|
| 104 | FakeDataContext fake = new FakeDataContext();
|
|---|
| 105 | IRepository<PlatnosciEcard> _rep = new Repository<PlatnosciEcard>(fake);
|
|---|
| 106 |
|
|---|
| 107 | DateTime data = DateTime.Now;
|
|---|
| 108 | PlatnosciEcard platnosc = createNewPayment(1, true, data, 1);
|
|---|
| 109 | _rep.Insert(platnosc);
|
|---|
| 110 |
|
|---|
| 111 | var controller = new PlatnoscController(fake);
|
|---|
| 112 | controller.UpdateStatus(1, "000"); //000 - płatność poprawna
|
|---|
| 113 |
|
|---|
| 114 | PlatnosciEcard payment_after_update = new PlatnosciEcard();
|
|---|
| 115 | payment_after_update = _rep.FindOne(i => i.ORDERNUMBER == 1);
|
|---|
| 116 | Assert.That(payment_after_update.Status_data, Is.GreaterThan(data));
|
|---|
| 117 | }
|
|---|
| 118 | [Test]
|
|---|
| 119 | [Category("Unit")]
|
|---|
| 120 | public void StatusIsNotUpdated()
|
|---|
| 121 | {
|
|---|
| 122 | FakeDataContext fake = new FakeDataContext();
|
|---|
| 123 | IRepository<PlatnosciEcard> _rep = new Repository<PlatnosciEcard>(fake);
|
|---|
| 124 |
|
|---|
| 125 | DateTime data = DateTime.Now;
|
|---|
| 126 |
|
|---|
| 127 | PlatnosciEcard platnosc = createNewPayment(1, true, data, 1);
|
|---|
| 128 | _rep.Insert(platnosc);
|
|---|
| 129 |
|
|---|
| 130 | var controller = new PlatnoscController(fake);
|
|---|
| 131 | controller.UpdateStatus(1, "111"); //111 - płatność niepoprawna, ze wzgledu na zly numer karty
|
|---|
| 132 |
|
|---|
| 133 | PlatnosciEcard payment_after_update = new PlatnosciEcard();
|
|---|
| 134 | payment_after_update = _rep.FindOne(i => i.ORDERNUMBER == 1);
|
|---|
| 135 | Assert.That(payment_after_update.Status_data, Is.EqualTo(data));
|
|---|
| 136 | }
|
|---|
| 137 | [Test]
|
|---|
| 138 | [Category("Unit")]
|
|---|
| 139 | public void TestFindInvoiceByNumber()
|
|---|
| 140 | {
|
|---|
| 141 | FakeDataContext fake = new FakeDataContext();
|
|---|
| 142 | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake);
|
|---|
| 143 |
|
|---|
| 144 | vPlatnosciEcard platnosc = new vPlatnosciEcard();
|
|---|
| 145 | platnosc = _rep.FindInvoiceById(1).SingleOrDefault();
|
|---|
| 146 | Assert.That(platnosc.Faktura_Numer, Is.EqualTo("1"));
|
|---|
| 147 | }
|
|---|
| 148 | [Test]
|
|---|
| 149 | [Category("Unit")]
|
|---|
| 150 | public void TestInsertMethodForPayment()
|
|---|
| 151 | {
|
|---|
| 152 | FakeDataContext fake = new FakeDataContext();
|
|---|
| 153 | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake);
|
|---|
| 154 |
|
|---|
| 155 | vPlatnosciEcard platnosc = createPayment(13, "nipek", "", 0, 0);
|
|---|
| 156 | _rep.Insert(platnosc);
|
|---|
| 157 |
|
|---|
| 158 | vPlatnosciEcard pl1 = createPayment(14, "vv", "", 0, 0);
|
|---|
| 159 | _rep.Insert(pl1);
|
|---|
| 160 |
|
|---|
| 161 | vPlatnosciEcard pl = _rep.FindInvoiceById(13).SingleOrDefault();
|
|---|
| 162 | Assert.That(pl.nip, Is.EqualTo("nipek"));
|
|---|
| 163 | }
|
|---|
| 164 | [Test]
|
|---|
| 165 | [Category("Unit")]
|
|---|
| 166 | public void ActionShowPayment_IncorrectUserIdentity_ReturnErrorView()
|
|---|
| 167 | {
|
|---|
| 168 | FakeDataContext fake = new FakeDataContext();
|
|---|
| 169 | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake);
|
|---|
| 170 |
|
|---|
| 171 | vPlatnosciEcard platnosc = createPayment(74828, "854956281", "27/ASZ/2009", 0, 0);
|
|---|
| 172 | _rep.Insert(platnosc);
|
|---|
| 173 |
|
|---|
| 174 | var controller = new PlatnoscController(fake);
|
|---|
| 175 | controller.ControllerContext = createControllerContext("1");
|
|---|
| 176 | controller.setWeryfikacja("Niepoprawny nip");
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 | var result = controller.Show("74828","pl") as ViewResult;
|
|---|
| 180 | var error = (ErrorViewData)result.ViewData.Model;
|
|---|
| 181 |
|
|---|
| 182 | Assert.That(error.error, Is.EqualTo("Niepoprawny nip"));
|
|---|
| 183 | Assert.That(result.ViewName, Is.EqualTo("Error1"));
|
|---|
| 184 | }
|
|---|
| 185 | [Test]
|
|---|
| 186 | [Category("Unit")]
|
|---|
| 187 | public void ActionShowPayment_PaymentNotFound_ReturnErrorView()
|
|---|
| 188 | {
|
|---|
| 189 | FakeDataContext fake = new FakeDataContext();
|
|---|
| 190 | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake);
|
|---|
| 191 |
|
|---|
| 192 | vPlatnosciEcard platnosc = createPayment(74828, "854956281", "27/ASZ/2009", 0,0);
|
|---|
| 193 | _rep.Insert(platnosc);
|
|---|
| 194 |
|
|---|
| 195 | var controller = new PlatnoscController(fake);
|
|---|
| 196 |
|
|---|
| 197 | controller.ControllerContext = createControllerContext("854956281");
|
|---|
| 198 | controller.setBrakDanych("Platnosc o takim id nie istnieje");
|
|---|
| 199 |
|
|---|
| 200 | var result = controller.Show("123", "pl") as ViewResult;
|
|---|
| 201 | var error = (ErrorViewData)result.ViewData.Model;
|
|---|
| 202 |
|
|---|
| 203 | Assert.That(error.error, Is.EqualTo("Platnosc o takim id nie istnieje"));
|
|---|
| 204 | Assert.That(result.ViewName, Is.EqualTo("Error1"));
|
|---|
| 205 | }
|
|---|
| 206 | [Test]
|
|---|
| 207 | [Category("Unit")]
|
|---|
| 208 | public void ActionShowPayment_PaymentIsPayed(){
|
|---|
| 209 | //Tworzymy takie dane aby platnosc o danym id byla juz zaplacona
|
|---|
| 210 | FakeDataContext fake = new FakeDataContext(1);
|
|---|
| 211 | var controller = new PlatnoscController(fake);
|
|---|
| 212 |
|
|---|
| 213 | controller.ControllerContext = createControllerContext("nip");
|
|---|
| 214 | controller.setZaplacono("Platnosc zostala uregulowana");
|
|---|
| 215 |
|
|---|
| 216 | var result = controller.Show("128", "pl") as ViewResult;
|
|---|
| 217 | var error = (ErrorViewData)result.ViewData.Model;
|
|---|
| 218 |
|
|---|
| 219 | Assert.That(result.ViewName, Is.EqualTo("Error1"));
|
|---|
| 220 | Assert.That(error.error, Is.EqualTo("Platnosc zostala uregulowana"));
|
|---|
| 221 | }
|
|---|
| 222 | [Test]
|
|---|
| 223 | [Category("Unit")]
|
|---|
| 224 | public void ActionShowPayment_CorrectData_ReturnViewForPayment()
|
|---|
| 225 | {
|
|---|
| 226 | FakeDataContext fake = new FakeDataContext();
|
|---|
| 227 | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake);
|
|---|
| 228 |
|
|---|
| 229 | vPlatnosciEcard platnosc = createPayment(74828,"854956281","27/ASZ/2009",200,0);
|
|---|
| 230 | _rep.Insert(platnosc);
|
|---|
| 231 |
|
|---|
| 232 | var controller = new PlatnoscController(fake);
|
|---|
| 233 | controller.ControllerContext = createControllerContext("854956281");
|
|---|
| 234 |
|
|---|
| 235 | var result = controller.Show("74828", "pl") as ViewResult;
|
|---|
| 236 | Assert.IsInstanceOfType(typeof(InvoiceDetailsViewData), result.ViewData.Model);
|
|---|
| 237 |
|
|---|
| 238 | var view = (InvoiceDetailsViewData)result.ViewData.Model;
|
|---|
| 239 | Assert.That(view.vPlatnosciEcard.Brutto, Is.EqualTo(200));
|
|---|
| 240 | Assert.That(view.vPlatnosciEcard.Faktura_Numer, Is.EqualTo("27/ASZ/2009"));
|
|---|
| 241 | }
|
|---|
| 242 | [Test]
|
|---|
| 243 | [Category("Unit")]
|
|---|
| 244 | public void AfterPay_PaymentIsNotValid()
|
|---|
| 245 | {
|
|---|
| 246 | FakeDataContext fake = new FakeDataContext();
|
|---|
| 247 | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake);
|
|---|
| 248 |
|
|---|
| 249 | vPlatnosciEcard platnosc = createPayment(74828, "854956281", "27/ASZ/2009", 200, 2);
|
|---|
| 250 | _rep.Insert(platnosc);
|
|---|
| 251 |
|
|---|
| 252 | var controller = new PlatnoscController(fake);
|
|---|
| 253 | controller.ControllerContext = createControllerContext("854956281");
|
|---|
| 254 |
|
|---|
| 255 | Payer payer = createPayer(74828, "", "test"); //Brak imienia
|
|---|
| 256 | controller.Show(payer, "pl");
|
|---|
| 257 |
|
|---|
| 258 | Assert.That(controller.ModelState.IsValid, Is.False);
|
|---|
| 259 | }
|
|---|
| 260 | [Test]
|
|---|
| 261 | [Category("Unit")]
|
|---|
| 262 | public void AfterPay_PaymentIsValid()
|
|---|
| 263 | {
|
|---|
| 264 | FakeDataContext fake = new FakeDataContext();
|
|---|
| 265 | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake);
|
|---|
| 266 |
|
|---|
| 267 | vPlatnosciEcard platnosc = createPayment(74828, "854956281", "27/ASZ/2009", 200, 2);
|
|---|
| 268 | _rep.Insert(platnosc);
|
|---|
| 269 |
|
|---|
| 270 | var controller = new PlatnoscController(fake);
|
|---|
| 271 | controller.ControllerContext = createControllerContext("854956281");
|
|---|
| 272 |
|
|---|
| 273 | Payer payer = createPayer(74828, "test", "test");
|
|---|
| 274 | controller.Show(payer, "pl");
|
|---|
| 275 |
|
|---|
| 276 | Assert.That(controller.ModelState.IsValid, Is.True);
|
|---|
| 277 | }
|
|---|
| 278 | [Test]
|
|---|
| 279 | [Category("UI")]
|
|---|
| 280 | public void checkLoginCorrect()
|
|---|
| 281 | {
|
|---|
| 282 | IE ie = new IE("http://localhost:3646/pl/Account/LogOn");
|
|---|
| 283 | ie.TextField(Find.ByName("numer_faktury")).TypeText("24/HOL/2009");
|
|---|
| 284 | ie.TextField(Find.ByName("nip")).TypeText("501379568");
|
|---|
| 285 | ie.Button(Find.ById("but")).Click();
|
|---|
| 286 | Assert.IsTrue(ie.ContainsText("została uregulowana"));
|
|---|
| 287 | }
|
|---|
| 288 | [Test]
|
|---|
| 289 | [Category("UI")]
|
|---|
| 290 | public void checkErrorLogin()
|
|---|
| 291 | {
|
|---|
| 292 | IE ie = new IE("http://localhost:3646/pl/Account/LogOn");
|
|---|
| 293 | ie.TextField(Find.ByName("numer_faktury")).TypeText("");
|
|---|
| 294 | ie.TextField(Find.ByName("nip")).TypeText("");
|
|---|
| 295 | ie.Button(Find.ById("but")).Click();
|
|---|
| 296 | Assert.IsTrue(ie.ContainsText("Logowanie nie powiodło się"));
|
|---|
| 297 | }
|
|---|
| 298 |
|
|---|
| 299 | }
|
|---|
| 300 | }
|
|---|
| 301 |
|
|---|