| 1 | using System;
|
|---|
| 2 | using NUnit.Framework;
|
|---|
| 3 | using Platnosci.Models;
|
|---|
| 4 | using Platnosci.Core.Linq;
|
|---|
| 5 |
|
|---|
| 6 | namespace Platnosci.Tests.Web
|
|---|
| 7 | {
|
|---|
| 8 | [TestFixture]
|
|---|
| 9 | class eCardDataTests
|
|---|
| 10 | {
|
|---|
| 11 | private readonly Function _function = new Function();
|
|---|
| 12 |
|
|---|
| 13 | [Test]
|
|---|
| 14 | [Category("Unit")]
|
|---|
| 15 | public void SetHash_Returns_zlyHash_When_Passing_Invalid_Merchant()
|
|---|
| 16 | {
|
|---|
| 17 | //Arrange
|
|---|
| 18 | var repPayment = new Repository<PlatnosciEcard>(new FakeDataContext());
|
|---|
| 19 | var platnosc = _function.CreateNewPayment(123, true, DateTime.Now, 1);
|
|---|
| 20 | repPayment.Insert(platnosc);
|
|---|
| 21 |
|
|---|
| 22 | var ecarddata = new eCardData(repPayment);
|
|---|
| 23 |
|
|---|
| 24 | var merchant = new Merchant(){
|
|---|
| 25 | Payment = platnosc,
|
|---|
| 26 | Id = "171485000",
|
|---|
| 27 | Password = "ashSeth2",
|
|---|
| 28 | };
|
|---|
| 29 |
|
|---|
| 30 | //Act
|
|---|
| 31 | var result = ecarddata.SetHash(merchant);
|
|---|
| 32 |
|
|---|
| 33 | //Assert
|
|---|
| 34 | Assert.That(result, Is.EqualTo(Merchant.BAD_HASH));
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | [Test]
|
|---|
| 38 | [Category("Unit")]
|
|---|
| 39 | public void SetHash_Returns_PaymentErrorInfo_When_Passing_Invalid_Payment()
|
|---|
| 40 | {
|
|---|
| 41 | //Arrange
|
|---|
| 42 | var repPayment = new Repository<PlatnosciEcard>(new FakeDataContext());
|
|---|
| 43 | var platnosc = _function.CreateNewPayment(123, true, DateTime.Now, 1);
|
|---|
| 44 |
|
|---|
| 45 | repPayment.Insert(platnosc);
|
|---|
| 46 |
|
|---|
| 47 | var ecarddata = new eCardData(repPayment);
|
|---|
| 48 |
|
|---|
| 49 | var merchant = new Merchant()
|
|---|
| 50 | {
|
|---|
| 51 | Payment = new PlatnosciEcard(){
|
|---|
| 52 | ORDERDESCRIPTION = "dd",
|
|---|
| 53 | IDFaktury = 21,
|
|---|
| 54 | Data = DateTime.Now
|
|---|
| 55 | },
|
|---|
| 56 | Id = "171485000",
|
|---|
| 57 | Password = "ashSeth2",
|
|---|
| 58 | };
|
|---|
| 59 |
|
|---|
| 60 | //Act
|
|---|
| 61 | var result = ecarddata.SetHash(merchant);
|
|---|
| 62 |
|
|---|
| 63 | //Assert
|
|---|
| 64 | Assert.That(result, Is.EqualTo(Merchant.HASH_ERROR_INFO));
|
|---|
| 65 | }
|
|---|
| 66 | [Test]
|
|---|
| 67 | [Category("Unit")]
|
|---|
| 68 | public void SetHash_Returns_Correct_Hash_When_Passing_Valid_Data()
|
|---|
| 69 | {
|
|---|
| 70 | //Arrange
|
|---|
| 71 | var repPayment = new Repository<PlatnosciEcard>(new FakeDataContext());
|
|---|
| 72 | var platnosc = _function.CreateNewPayment(123, true, DateTime.Now, 1);
|
|---|
| 73 | platnosc.AMOUNT = 229;
|
|---|
| 74 | platnosc.CURRENCY = FunkcjePlatnosci.PLN;
|
|---|
| 75 |
|
|---|
| 76 | repPayment.Insert(platnosc);
|
|---|
| 77 |
|
|---|
| 78 | var ecarddata = new eCardData(repPayment);
|
|---|
| 79 |
|
|---|
| 80 | var merchant = new Merchant()
|
|---|
| 81 | {
|
|---|
| 82 | Payment = platnosc,
|
|---|
| 83 | Id = "171485000",
|
|---|
| 84 | Password = "ashSeth2",
|
|---|
| 85 | };
|
|---|
| 86 |
|
|---|
| 87 | //Act
|
|---|
| 88 | var result = ecarddata.SetHash(merchant);
|
|---|
| 89 |
|
|---|
| 90 | //Assert
|
|---|
| 91 | Assert.That(result.Length, Is.GreaterThan(30));
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | [Test]
|
|---|
| 95 | [Category("Unit")]
|
|---|
| 96 | public void SetHash_Returns_BAD_HASH_When_Invoice_Amount_Is_Zero()
|
|---|
| 97 | {
|
|---|
| 98 | //Arrange
|
|---|
| 99 | var repPayment = new Repository<PlatnosciEcard>(new FakeDataContext());
|
|---|
| 100 | var platnosc = _function.CreateNewPayment(123, true, DateTime.Now, 1);
|
|---|
| 101 | platnosc.AMOUNT = 0;
|
|---|
| 102 | platnosc.CURRENCY = FunkcjePlatnosci.PLN;
|
|---|
| 103 |
|
|---|
| 104 | repPayment.Insert(platnosc);
|
|---|
| 105 |
|
|---|
| 106 | var ecarddata = new eCardData(repPayment);
|
|---|
| 107 |
|
|---|
| 108 | var merchant = new Merchant()
|
|---|
| 109 | {
|
|---|
| 110 | Payment = platnosc,
|
|---|
| 111 | Id = "171485000",
|
|---|
| 112 | Password = "ashSeth2",
|
|---|
| 113 | };
|
|---|
| 114 |
|
|---|
| 115 | //Act
|
|---|
| 116 | var result = ecarddata.SetHash(merchant);
|
|---|
| 117 |
|
|---|
| 118 | //Assert
|
|---|
| 119 | Assert.That(result, Is.EqualTo(Merchant.BAD_HASH));
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | [Test]
|
|---|
| 123 | [Category("Unit")]
|
|---|
| 124 | public void SetHash_Returns_BAD_HASH_When_Password_Is_Wrong()
|
|---|
| 125 | {
|
|---|
| 126 | //Arrange
|
|---|
| 127 | var repPayment = new Repository<PlatnosciEcard>(new FakeDataContext());
|
|---|
| 128 | var platnosc = _function.CreateNewPayment(123, true, DateTime.Now, 1);
|
|---|
| 129 | platnosc.AMOUNT = 229;
|
|---|
| 130 | platnosc.CURRENCY = FunkcjePlatnosci.PLN;
|
|---|
| 131 |
|
|---|
| 132 | repPayment.Insert(platnosc);
|
|---|
| 133 |
|
|---|
| 134 | var ecarddata = new eCardData(repPayment);
|
|---|
| 135 |
|
|---|
| 136 | var merchant = new Merchant()
|
|---|
| 137 | {
|
|---|
| 138 | Payment = platnosc,
|
|---|
| 139 | Id = "TEST",
|
|---|
| 140 | Password = "test",
|
|---|
| 141 | };
|
|---|
| 142 |
|
|---|
| 143 | //Act
|
|---|
| 144 | var result = ecarddata.SetHash(merchant);
|
|---|
| 145 |
|
|---|
| 146 | //Assert
|
|---|
| 147 | Assert.That(result, Is.EqualTo(Merchant.BAD_HASH));
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | [Test]
|
|---|
| 151 | [Category("Unit")]
|
|---|
| 152 | public void SetHash_Returns_Correct_Hash_When_Payment_Amount_Is_Less_Then_100()
|
|---|
| 153 | {
|
|---|
| 154 | //Arrange
|
|---|
| 155 | var repPayment = new Repository<PlatnosciEcard>(new FakeDataContext());
|
|---|
| 156 | var platnosc = _function.CreateNewPayment(123, true, DateTime.Now, 1);
|
|---|
| 157 | platnosc.AMOUNT = 11;
|
|---|
| 158 | platnosc.CURRENCY = FunkcjePlatnosci.PLN;
|
|---|
| 159 |
|
|---|
| 160 | repPayment.Insert(platnosc);
|
|---|
| 161 |
|
|---|
| 162 | var ecarddata = new eCardData(repPayment);
|
|---|
| 163 |
|
|---|
| 164 | var merchant = new Merchant()
|
|---|
| 165 | {
|
|---|
| 166 | Payment = platnosc,
|
|---|
| 167 | Id = "171485000",
|
|---|
| 168 | Password = "ashSeth2",
|
|---|
| 169 | };
|
|---|
| 170 |
|
|---|
| 171 | //Act
|
|---|
| 172 | var result = ecarddata.SetHash(merchant);
|
|---|
| 173 |
|
|---|
| 174 | //Assert
|
|---|
| 175 | System.Diagnostics.Debug.WriteLine(result.Length);
|
|---|
| 176 | Assert.That(result.Length, Is.GreaterThan(30));
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | [Test]
|
|---|
| 180 | [Category("Unit")]
|
|---|
| 181 | public void Create_Merchant_Data_Returns_Invoice_Correct_Amount_When_Merchant_Is_Valid()
|
|---|
| 182 | {
|
|---|
| 183 | //Arrange
|
|---|
| 184 | var idFaktury = 12345;
|
|---|
| 185 | var amountPL = 5000;
|
|---|
| 186 | var amountEUR = 1300;
|
|---|
| 187 |
|
|---|
| 188 | var repVPayment = new Repository<vPlatnosciEcard>(new FakeDataContext());
|
|---|
| 189 | var invoice = _function.CreateForeignInvoice(idFaktury, "nip1", "abc/2009", amountPL, 0, amountEUR, "EUR");
|
|---|
| 190 | repVPayment.Insert(invoice);
|
|---|
| 191 |
|
|---|
| 192 | var payer = _function.CreatePayer(idFaktury, "test", "test");
|
|---|
| 193 | var repPayment = new Repository<PlatnosciEcard>(new FakeDataContext());
|
|---|
| 194 | var eCardData = new eCardData(repPayment);
|
|---|
| 195 |
|
|---|
| 196 | //Act
|
|---|
| 197 | var result = eCardData.CreateMerchantData(invoice, payer, "pl", "ahaah");
|
|---|
| 198 | var payment = repPayment.FindOne(i => i.IDFaktury == idFaktury);
|
|---|
| 199 |
|
|---|
| 200 | //Assert
|
|---|
| 201 | System.Diagnostics.Debug.WriteLine("Faktura jest w EUR.");
|
|---|
| 202 | System.Diagnostics.Debug.WriteLine("PLN:" + amountPL + "," + " EUR:" + amountEUR);
|
|---|
| 203 | Assert.That(payment.AMOUNT, Is.EqualTo(amountEUR * 100));
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | [Test]
|
|---|
| 207 | [Category("Unit")]
|
|---|
| 208 | public void Create_Merchant_Data_Returns_BAD_HASH_When_Invoice_Amount_Is_Zero()
|
|---|
| 209 | {
|
|---|
| 210 | //Arrange
|
|---|
| 211 | var ecarddata = new eCardData(new Repository<PlatnosciEcard>(new FakeDataContext()));
|
|---|
| 212 | var invoice = _function.CreateInvoice(123, "nip", "abc/2009", 0, 2);
|
|---|
| 213 |
|
|---|
| 214 | var payer = _function.CreatePayer(123, "test", "test");
|
|---|
| 215 |
|
|---|
| 216 | //Act
|
|---|
| 217 | var result = ecarddata.CreateMerchantData(invoice, payer, "PL", "abcd");
|
|---|
| 218 |
|
|---|
| 219 | //Assert
|
|---|
| 220 | System.Diagnostics.Debug.WriteLine("Error: " + result.Error + " is not valid.");
|
|---|
| 221 | Assert.That(result.Error, Is.EqualTo("hash")); //dla wartosci amount=0 eCard zwroci hash o wartości "zlyHash"
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | [Test]
|
|---|
| 225 | [Category("Unit")]
|
|---|
| 226 | public void Create_Merchant_Data_Returns_Error_When_Orderdescription_Is_Not_Valid()
|
|---|
| 227 | {
|
|---|
| 228 | //Arrange
|
|---|
| 229 | var ecarddata = new eCardData(new Repository<PlatnosciEcard>(new FakeDataContext()));
|
|---|
| 230 | var invoice = _function.CreateInvoice(123, "nip", "", 200, 2);
|
|---|
| 231 |
|
|---|
| 232 | var payer = _function.CreatePayer(123, "test", "test");
|
|---|
| 233 |
|
|---|
| 234 | //Act
|
|---|
| 235 | var result = ecarddata.CreateMerchantData(invoice, payer, "PL", "abcd");
|
|---|
| 236 |
|
|---|
| 237 | //Assert
|
|---|
| 238 | System.Diagnostics.Debug.WriteLine("Error: " + result.Error + " is not valid.");
|
|---|
| 239 | Assert.That(result.Error, Is.EqualTo("orderdescription"));
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | [Test]
|
|---|
| 243 | [Category("Unit")]
|
|---|
| 244 | public void Create_Merchant_Data_Returns_Error_When_Name_Is_Not_Valid()
|
|---|
| 245 | {
|
|---|
| 246 | //Arrange
|
|---|
| 247 | var ecarddata = new eCardData(new Repository<PlatnosciEcard>(new FakeDataContext()));
|
|---|
| 248 | var invoice = _function.CreateInvoice(123, "nip", "abc/2009", 200, 2);
|
|---|
| 249 |
|
|---|
| 250 | var payer = _function.CreatePayer(123, "", "test");
|
|---|
| 251 |
|
|---|
| 252 | //Act
|
|---|
| 253 | var result = ecarddata.CreateMerchantData(invoice, payer, "PL", "abcd");
|
|---|
| 254 |
|
|---|
| 255 | //Assert
|
|---|
| 256 | System.Diagnostics.Debug.WriteLine("Error: " + result.Error + " is not valid.");
|
|---|
| 257 | Assert.That(result.Error, Is.EqualTo("name"));
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 | [Test]
|
|---|
| 261 | [Category("Unit")]
|
|---|
| 262 | public void Create_Merchant_Data_Returns_Error_When_Surname_Is_Not_Valid()
|
|---|
| 263 | {
|
|---|
| 264 | //Arrange
|
|---|
| 265 | var ecarddata = new eCardData(new Repository<PlatnosciEcard>(new FakeDataContext()));
|
|---|
| 266 | var invoice = _function.CreateInvoice(123, "nip", "abc/2009", 200, 2);
|
|---|
| 267 |
|
|---|
| 268 | var payer = _function.CreatePayer(123, "test", "");
|
|---|
| 269 |
|
|---|
| 270 | //Act
|
|---|
| 271 | var result = ecarddata.CreateMerchantData(invoice, payer, "PL", "abcd");
|
|---|
| 272 |
|
|---|
| 273 | //Assert
|
|---|
| 274 | System.Diagnostics.Debug.WriteLine("Error: " + result.Error + " is not valid.");
|
|---|
| 275 | Assert.That(result.Error, Is.EqualTo("surname"));
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | [Test]
|
|---|
| 279 | [Category("Unit")]
|
|---|
| 280 | public void Create_Merchant_Data_Returns_Valid_Merchnt_When_All_Data_Are_Correct()
|
|---|
| 281 | {
|
|---|
| 282 | //Arrange
|
|---|
| 283 | var ecarddata = new eCardData(new Repository<PlatnosciEcard>(new FakeDataContext()));
|
|---|
| 284 | var invoice = _function.CreateInvoice(123, "nip", "abc/2009", 200, 2);
|
|---|
| 285 |
|
|---|
| 286 | var payer = _function.CreatePayer(123, "test", "test");
|
|---|
| 287 |
|
|---|
| 288 | //Act
|
|---|
| 289 | var result2 = ecarddata.CreateMerchantData(invoice, payer, "PL", "abcd");
|
|---|
| 290 |
|
|---|
| 291 | //Assert
|
|---|
| 292 | System.Diagnostics.Debug.WriteLine("Wszystkie dane sa poprawne!!");
|
|---|
| 293 | Assert.That(result2.Error, Is.EqualTo(null));
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | [Test]
|
|---|
| 297 | [Category("Unit")]
|
|---|
| 298 | public void Get_Url_Returns_Correct_eCard_Url()
|
|---|
| 299 | {
|
|---|
| 300 | //Arrange
|
|---|
| 301 | var pl = new PlatnosciEcard() {ORDERDESCRIPTION = "abc/2009"};
|
|---|
| 302 | var m = new Merchant(){Payment = pl, Id = "ABCD" };
|
|---|
| 303 | var eCardData = new eCardData(new Repository<PlatnosciEcard>(new FakeDataContext()));
|
|---|
| 304 |
|
|---|
| 305 | //Act
|
|---|
| 306 | var result = eCardData.GetUrl(m);
|
|---|
| 307 |
|
|---|
| 308 | //Assert
|
|---|
| 309 | System.Diagnostics.Debug.WriteLine("eCard url:" + result + " " + m);
|
|---|
| 310 | Assert.That(result, Is.Not.EqualTo(""));
|
|---|
| 311 | }
|
|---|
| 312 | }
|
|---|
| 313 | }
|
|---|