| 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 Rhino.Mocks;
|
|---|
| 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 |
|
|---|
| 41 | [Test]
|
|---|
| 42 | [Category("Unit")]
|
|---|
| 43 | public void Status_Saves_Correct_Transaction()
|
|---|
| 44 | {
|
|---|
| 45 | var orderNumber = 9999;
|
|---|
| 46 | FakeDataContext fake = new FakeDataContext();
|
|---|
| 47 | var builder = new TestControllerBuilder();
|
|---|
| 48 | var controller = new PlatnoscController(fake);
|
|---|
| 49 | builder.InitializeController(controller);
|
|---|
| 50 | builder.Form.Add("MERCHANTNUMBER", merchantNumber.ToString());
|
|---|
| 51 | builder.Form.Add("AUTHTIME", DateTime.Now.ToString());
|
|---|
| 52 | builder.Form.Add("DATATRANSMISJI", DateTime.Now.ToString());
|
|---|
| 53 | builder.Form.Add("ORDERNUMBER", orderNumber.ToString());
|
|---|
| 54 |
|
|---|
| 55 | var result = controller.Status();
|
|---|
| 56 |
|
|---|
| 57 | IRepository<PotwierdzeniaEcard> _rep = new Repository<PotwierdzeniaEcard>(fake);
|
|---|
| 58 | var potwierdzeniaEcard = _rep.Find(p => p.ORDERNUMBER == orderNumber).First();
|
|---|
| 59 | Assert.That(potwierdzeniaEcard.MERCHANTNUMBER, Is.EqualTo(merchantNumber));
|
|---|
| 60 | }
|
|---|
| 61 | [Test]
|
|---|
| 62 | [Category("Unit")]
|
|---|
| 63 | public void StatusIsUpdated()
|
|---|
| 64 | {
|
|---|
| 65 | FakeDataContext fake = new FakeDataContext();
|
|---|
| 66 | IRepository<PlatnosciEcard> _rep = new Repository<PlatnosciEcard>(fake);
|
|---|
| 67 |
|
|---|
| 68 | DateTime data = DateTime.Now;
|
|---|
| 69 |
|
|---|
| 70 | PlatnosciEcard platnosc = new PlatnosciEcard();
|
|---|
| 71 | platnosc.ORDERNUMBER = 1;
|
|---|
| 72 | platnosc.Status = true;
|
|---|
| 73 | platnosc.Status_data = data;
|
|---|
| 74 | _rep.Insert(platnosc);
|
|---|
| 75 |
|
|---|
| 76 | var builder = new TestControllerBuilder();
|
|---|
| 77 | var controller = new PlatnoscController(fake);
|
|---|
| 78 | builder.InitializeController(controller);
|
|---|
| 79 |
|
|---|
| 80 | controller.UpdateStatus(1, "000"); //000 - płatność poprawna
|
|---|
| 81 |
|
|---|
| 82 | PlatnosciEcard payment_after_update = new PlatnosciEcard();
|
|---|
| 83 | payment_after_update = _rep.FindOne(i => i.ORDERNUMBER == 1);
|
|---|
| 84 | Assert.That(payment_after_update.Status_data, Is.GreaterThan(data));
|
|---|
| 85 | }
|
|---|
| 86 | [Test]
|
|---|
| 87 | [Category("Unit")]
|
|---|
| 88 | public void StatusIsNotUpdated()
|
|---|
| 89 | {
|
|---|
| 90 | FakeDataContext fake = new FakeDataContext();
|
|---|
| 91 | IRepository<PlatnosciEcard> _rep = new Repository<PlatnosciEcard>(fake);
|
|---|
| 92 |
|
|---|
| 93 | DateTime data = DateTime.Now;
|
|---|
| 94 |
|
|---|
| 95 | PlatnosciEcard platnosc = new PlatnosciEcard();
|
|---|
| 96 | platnosc.ORDERNUMBER = 1;
|
|---|
| 97 | platnosc.Status = true;
|
|---|
| 98 | platnosc.Status_data = data;
|
|---|
| 99 | _rep.Insert(platnosc);
|
|---|
| 100 |
|
|---|
| 101 | var builder = new TestControllerBuilder();
|
|---|
| 102 | var controller = new PlatnoscController(fake);
|
|---|
| 103 | builder.InitializeController(controller);
|
|---|
| 104 |
|
|---|
| 105 | controller.UpdateStatus(1, "111"); //111 - płatność niepoprawna, ze wzgledu na zly numer karty
|
|---|
| 106 |
|
|---|
| 107 | PlatnosciEcard payment_after_update = new PlatnosciEcard();
|
|---|
| 108 | payment_after_update = _rep.FindOne(i => i.ORDERNUMBER == 1);
|
|---|
| 109 | Assert.That(payment_after_update.Status_data, Is.EqualTo(data));
|
|---|
| 110 |
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | [Test]
|
|---|
| 114 | [Category("Unit")]
|
|---|
| 115 | public void NumerFaktury()
|
|---|
| 116 | {
|
|---|
| 117 | FakeDataContext fake = new FakeDataContext();
|
|---|
| 118 | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake);
|
|---|
| 119 |
|
|---|
| 120 | vPlatnosciEcard platnosc = new vPlatnosciEcard();
|
|---|
| 121 | platnosc = _rep.FindInvoiceById(1).SingleOrDefault();
|
|---|
| 122 | Assert.That(platnosc.Faktura_Numer, Is.EqualTo("1"));
|
|---|
| 123 | }
|
|---|
| 124 | [Test]
|
|---|
| 125 | [Category("Unit")]
|
|---|
| 126 | public void AddPayment()
|
|---|
| 127 | {
|
|---|
| 128 | FakeDataContext fake = new FakeDataContext();
|
|---|
| 129 | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake);
|
|---|
| 130 |
|
|---|
| 131 | vPlatnosciEcard platnosc = new vPlatnosciEcard();
|
|---|
| 132 | platnosc.ID_faktury = 13;
|
|---|
| 133 | platnosc.nip = "nipek";
|
|---|
| 134 | _rep.Insert(platnosc);
|
|---|
| 135 |
|
|---|
| 136 | vPlatnosciEcard pl1 = new vPlatnosciEcard();
|
|---|
| 137 | pl1.ID_faktury = 14;
|
|---|
| 138 | pl1.nip = "vv";
|
|---|
| 139 | _rep.Insert(pl1);
|
|---|
| 140 |
|
|---|
| 141 | vPlatnosciEcard pl = _rep.FindInvoiceById(13).SingleOrDefault();
|
|---|
| 142 | Assert.That(pl.nip, Is.EqualTo("nipek"));
|
|---|
| 143 | }
|
|---|
| 144 | [Test]
|
|---|
| 145 | [Category("Unit")]
|
|---|
| 146 | public void ShowPayment_BadNip()
|
|---|
| 147 | {
|
|---|
| 148 | FakeDataContext fake = new FakeDataContext();
|
|---|
| 149 | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake);
|
|---|
| 150 |
|
|---|
| 151 | vPlatnosciEcard platnosc = new vPlatnosciEcard();
|
|---|
| 152 | platnosc.ID_faktury = 74828;
|
|---|
| 153 | platnosc.nip = "854956281";
|
|---|
| 154 | platnosc.Faktura_Numer = "27/ASZ/2009";
|
|---|
| 155 | _rep.Insert(platnosc);
|
|---|
| 156 |
|
|---|
| 157 | var builder = new TestControllerBuilder();
|
|---|
| 158 | var controller = new PlatnoscController(fake);
|
|---|
| 159 | controller.setUserIdentity("122");
|
|---|
| 160 | controller.setWeryfikacja("Niepoprawny nip");
|
|---|
| 161 | builder.InitializeController(controller);
|
|---|
| 162 |
|
|---|
| 163 | var result = controller.Show("74828","pl") as ViewResult;
|
|---|
| 164 | var error = (ErrorViewData)result.ViewData.Model;
|
|---|
| 165 |
|
|---|
| 166 | Assert.That(error.error, Is.EqualTo("Niepoprawny nip"));
|
|---|
| 167 |
|
|---|
| 168 | }
|
|---|
| 169 | [Test]
|
|---|
| 170 | [Category("Unit")]
|
|---|
| 171 | public void ShowPayment_CorrectData()
|
|---|
| 172 | {
|
|---|
| 173 | FakeDataContext fake = new FakeDataContext();
|
|---|
| 174 | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake);
|
|---|
| 175 |
|
|---|
| 176 | vPlatnosciEcard platnosc = new vPlatnosciEcard();
|
|---|
| 177 | platnosc.ID_faktury = 74828;
|
|---|
| 178 | platnosc.nip = "854956281";
|
|---|
| 179 | platnosc.Faktura_Numer = "27/ASZ/2009";
|
|---|
| 180 | platnosc.Brutto = 200;
|
|---|
| 181 | _rep.Insert(platnosc);
|
|---|
| 182 |
|
|---|
| 183 | var builder = new TestControllerBuilder();
|
|---|
| 184 | var controller = new PlatnoscController(fake);
|
|---|
| 185 | controller.setUserIdentity("854956281");
|
|---|
| 186 | builder.InitializeController(controller);
|
|---|
| 187 |
|
|---|
| 188 | var result = controller.Show("74828", "pl") as ViewResult;
|
|---|
| 189 | var view = (InvoiceDetailsViewData)result.ViewData.Model;
|
|---|
| 190 |
|
|---|
| 191 | Assert.That(view.vPlatnosciEcard.Brutto, Is.EqualTo(200));
|
|---|
| 192 | Assert.That(view.vPlatnosciEcard.Faktura_Numer, Is.EqualTo("27/ASZ/2009"));
|
|---|
| 193 |
|
|---|
| 194 | }
|
|---|
| 195 | [Test]
|
|---|
| 196 | [Category("Unit")]
|
|---|
| 197 | public void PaymentIsNotValid()
|
|---|
| 198 | {
|
|---|
| 199 | FakeDataContext fake = new FakeDataContext();
|
|---|
| 200 | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake);
|
|---|
| 201 |
|
|---|
| 202 | vPlatnosciEcard platnosc = new vPlatnosciEcard();
|
|---|
| 203 | platnosc.ID_faktury = 74828;
|
|---|
| 204 | platnosc.nip = "854956281";
|
|---|
| 205 | platnosc.Faktura_Numer = "27/ASZ/2009";
|
|---|
| 206 | platnosc.Brutto = 200;
|
|---|
| 207 | platnosc.SystemKsiegowyId = 2;
|
|---|
| 208 | _rep.Insert(platnosc);
|
|---|
| 209 |
|
|---|
| 210 | var builder = new TestControllerBuilder();
|
|---|
| 211 | var controller = new PlatnoscController(fake);
|
|---|
| 212 | controller.setUserIdentity("854956281");
|
|---|
| 213 | builder.InitializeController(controller);
|
|---|
| 214 |
|
|---|
| 215 | Payer payer = new Payer();
|
|---|
| 216 | payer.Id_faktury = 74828;
|
|---|
| 217 | payer.LastName = "test"; //Nie wprowadzono imienia
|
|---|
| 218 |
|
|---|
| 219 | controller.Show(payer, "pl");
|
|---|
| 220 | Assert.That(controller.ModelState.IsValid, Is.False);
|
|---|
| 221 | }
|
|---|
| 222 | [Test]
|
|---|
| 223 | [Category("Unit")]
|
|---|
| 224 | public void PaymentIsValid()
|
|---|
| 225 | {
|
|---|
| 226 | FakeDataContext fake = new FakeDataContext();
|
|---|
| 227 | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake);
|
|---|
| 228 |
|
|---|
| 229 | vPlatnosciEcard platnosc = new vPlatnosciEcard();
|
|---|
| 230 | platnosc.ID_faktury = 74828;
|
|---|
| 231 | platnosc.nip = "854956281";
|
|---|
| 232 | platnosc.Faktura_Numer = "27/ASZ/2009";
|
|---|
| 233 | platnosc.Brutto = 200;
|
|---|
| 234 | platnosc.SystemKsiegowyId = 2;
|
|---|
| 235 | _rep.Insert(platnosc);
|
|---|
| 236 |
|
|---|
| 237 | var builder = new TestControllerBuilder();
|
|---|
| 238 | var controller = new PlatnoscController(fake);
|
|---|
| 239 | controller.setUserIdentity("854956281");
|
|---|
| 240 | builder.InitializeController(controller);
|
|---|
| 241 |
|
|---|
| 242 | Payer payer = new Payer();
|
|---|
| 243 | payer.Id_faktury = 74828;
|
|---|
| 244 | payer.LastName = "test";
|
|---|
| 245 | payer.FirstName = "test";
|
|---|
| 246 |
|
|---|
| 247 | controller.Show(payer, "pl");
|
|---|
| 248 | Assert.That(controller.ModelState.IsValid, Is.True);
|
|---|
| 249 | }
|
|---|
| 250 | [Test]
|
|---|
| 251 | [Category("Unit")]
|
|---|
| 252 | public void ShowPayment_BadId()
|
|---|
| 253 | {
|
|---|
| 254 | FakeDataContext fake = new FakeDataContext();
|
|---|
| 255 | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake);
|
|---|
| 256 |
|
|---|
| 257 | vPlatnosciEcard platnosc = new vPlatnosciEcard();
|
|---|
| 258 | platnosc.ID_faktury = 74828;
|
|---|
| 259 | platnosc.nip = "854956281";
|
|---|
| 260 | platnosc.Faktura_Numer = "27/ASZ/2009";
|
|---|
| 261 | _rep.Insert(platnosc);
|
|---|
| 262 |
|
|---|
| 263 | var builder = new TestControllerBuilder();
|
|---|
| 264 | var controller = new PlatnoscController(fake);
|
|---|
| 265 | controller.setUserIdentity("1");
|
|---|
| 266 | controller.setWeryfikacja("Nie ma takiej platnosci.");
|
|---|
| 267 | builder.InitializeController(controller);
|
|---|
| 268 |
|
|---|
| 269 | var result = controller.Show("1", "pl") as ViewResult;
|
|---|
| 270 | var error = (ErrorViewData)result.ViewData.Model;
|
|---|
| 271 |
|
|---|
| 272 | Assert.That(error.error, Is.EqualTo("Nie ma takiej platnosci."));
|
|---|
| 273 |
|
|---|
| 274 | }
|
|---|
| 275 | [Test]
|
|---|
| 276 | [Category("UI")]
|
|---|
| 277 | public void checkLoginCorrect()
|
|---|
| 278 | {
|
|---|
| 279 | IE ie = new IE("http://localhost:3646/pl/Account/LogOn");
|
|---|
| 280 | ie.TextField(Find.ByName("numer_faktury")).TypeText("24/HOL/2009");
|
|---|
| 281 | ie.TextField(Find.ByName("nip")).TypeText("501379568");
|
|---|
| 282 | ie.Button(Find.ById("but")).Click();
|
|---|
| 283 |
|
|---|
| 284 | Assert.IsTrue(ie.ContainsText("została uregulowana"));
|
|---|
| 285 | }
|
|---|
| 286 | [Test]
|
|---|
| 287 | [Category("UI")]
|
|---|
| 288 | public void checkErrorLogin()
|
|---|
| 289 | {
|
|---|
| 290 | IE ie = new IE("http://localhost:3646/pl/Account/LogOn");
|
|---|
| 291 | ie.TextField(Find.ByName("numer_faktury")).TypeText("");
|
|---|
| 292 | ie.TextField(Find.ByName("nip")).TypeText("");
|
|---|
| 293 | ie.Button(Find.ById("but")).Click();
|
|---|
| 294 |
|
|---|
| 295 | Assert.IsTrue(ie.ContainsText("Logowanie nie powiodło się"));
|
|---|
| 296 | }
|
|---|
| 297 |
|
|---|
| 298 | }
|
|---|
| 299 | }
|
|---|
| 300 |
|
|---|