| 1 | using System;
|
|---|
| 2 | using System.Linq;
|
|---|
| 3 | using adMoto.Payments.Core.Data;
|
|---|
| 4 | using adMoto.Payments.Test.Fakes;
|
|---|
| 5 | using adMoto.Payments.Core;
|
|---|
| 6 | using adMoto.Payments.Core.Interfaces;
|
|---|
| 7 | using WatiN.Core;
|
|---|
| 8 |
|
|---|
| 9 | namespace adMoto.Payments.Test.UI
|
|---|
| 10 | {
|
|---|
| 11 | public class UIHelper
|
|---|
| 12 | {
|
|---|
| 13 | private readonly TestDataHelper _testDataHelper = new TestDataHelper();
|
|---|
| 14 | private IRepository<FAKTURY> _repInvoices = new Repository<FAKTURY>(new DataContext());
|
|---|
| 15 | private IRepository<FAKTURA_DETAIL> _repInvoiceDetails = new Repository<FAKTURA_DETAIL>(new DataContext());
|
|---|
| 16 | private IRepository<PlatnosciEcard> _repPayment;
|
|---|
| 17 | private UIData uiData;
|
|---|
| 18 | private string nip = "test"; //testowy klient o id 76131
|
|---|
| 19 | private string numer_faktury = "1/SLJ/1";
|
|---|
| 20 | public static string LoginSite = "http://localhost:3646/pl/Account/LogOn";
|
|---|
| 21 | public static string ConfirmForm = "http://localhost:3646/pl/Platnosc/Form";
|
|---|
| 22 |
|
|---|
| 23 | public UIData CreateAndAddTestRecordToRepository(int amount)
|
|---|
| 24 | {
|
|---|
| 25 | var invoices = new FAKTURY
|
|---|
| 26 | {
|
|---|
| 27 | NUMER = 1,
|
|---|
| 28 | NUMER_ROZ = "SLJ",
|
|---|
| 29 | NUMER_ROK = 1,
|
|---|
| 30 | NABYWCA_NIP = nip,
|
|---|
| 31 | ID_SPRZEDAWCY = 2,
|
|---|
| 32 | ID_NABYWCY = 76131, //testowy klient
|
|---|
| 33 | waluta_brutto = Convert.ToDouble(amount),
|
|---|
| 34 | waluta_miano = "EUR"
|
|---|
| 35 | };
|
|---|
| 36 | _repInvoices.Insert(invoices);
|
|---|
| 37 | var invoice = _repInvoices.Find(p => p.NUMER == 1 && p.NUMER_ROK == 1 && p.NUMER_ROZ == "SLJ" && p.ID_NABYWCY == 76131).FirstOrDefault();
|
|---|
| 38 |
|
|---|
| 39 | if (invoice != null)
|
|---|
| 40 | {
|
|---|
| 41 | var invoiceDetails = new FAKTURA_DETAIL
|
|---|
| 42 | {
|
|---|
| 43 | ID_FAKTURY = invoice.ID_FAKTURY,
|
|---|
| 44 | SYMBOL_SWW = "TEST"
|
|---|
| 45 | };
|
|---|
| 46 | _repInvoiceDetails.Insert(invoiceDetails);
|
|---|
| 47 |
|
|---|
| 48 | var invoiceDetails2 = _repInvoiceDetails.Find(p => p.ID_FAKTURY == invoiceDetails.ID_FAKTURY && p.SYMBOL_SWW == "TEST").FirstOrDefault();
|
|---|
| 49 |
|
|---|
| 50 | if (invoiceDetails2 != null)
|
|---|
| 51 | {
|
|---|
| 52 | uiData = new UIData
|
|---|
| 53 | {
|
|---|
| 54 | FAKTURA_ID = Convert.ToInt32(invoiceDetails2.ID_FAKTURY),
|
|---|
| 55 | FAKTURA_DETAIL_ID = invoiceDetails2.ID_FAKTURA_DETAILS,
|
|---|
| 56 | Test_nip = nip,
|
|---|
| 57 | Test_numer_faktury = numer_faktury
|
|---|
| 58 | };
|
|---|
| 59 | }
|
|---|
| 60 | }
|
|---|
| 61 | return uiData;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | public void DeleteTestRecordsFromRepository(UIData uiData)
|
|---|
| 65 | {
|
|---|
| 66 | var invoice = _repInvoices.Find(p => p.ID_FAKTURY == uiData.FAKTURA_ID).FirstOrDefault();
|
|---|
| 67 | if (invoice != null)
|
|---|
| 68 | _repInvoices.Delete(invoice);
|
|---|
| 69 |
|
|---|
| 70 | var invoiceDetails = _repInvoiceDetails.Find(p => p.ID_FAKTURA_DETAILS == uiData.FAKTURA_DETAIL_ID).FirstOrDefault();
|
|---|
| 71 | if (invoiceDetails != null)
|
|---|
| 72 | _repInvoiceDetails.Delete(invoiceDetails);
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | public void DeleteTestPaymentFromRepository(UIData uiData)
|
|---|
| 76 | {
|
|---|
| 77 | _repPayment = new Repository<PlatnosciEcard>(new DataContext());
|
|---|
| 78 | var payment = _repPayment.Find(p => p.IDFaktury == uiData.FAKTURA_ID &&
|
|---|
| 79 | p.NAME == uiData.Test_firstname &&
|
|---|
| 80 | p.SURNAME == uiData.Test_surname &&
|
|---|
| 81 | p.ORDERDESCRIPTION == uiData.Test_numer_faktury &&
|
|---|
| 82 | p.nip == uiData.Test_nip).FirstOrDefault();
|
|---|
| 83 |
|
|---|
| 84 | if (payment != null)
|
|---|
| 85 | _repPayment.Delete(payment);
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | public void SearchAndClean()
|
|---|
| 89 | {
|
|---|
| 90 | var invoices = _repInvoices.FindAll(p => p.NUMER == 1 && p.NUMER_ROK == 1 && p.NUMER_ROZ == "SLJ" && p.ID_NABYWCY == 76131);
|
|---|
| 91 | for (int i = 0; i < invoices.Count; i++)
|
|---|
| 92 | {
|
|---|
| 93 | var id_faktury = invoices[i].ID_FAKTURY;
|
|---|
| 94 | if (invoices[i] != null)
|
|---|
| 95 | _repInvoices.Delete(invoices[i]);
|
|---|
| 96 |
|
|---|
| 97 | var invoiceDetails = _repInvoiceDetails.FindOne(p => p.ID_FAKTURY == id_faktury);
|
|---|
| 98 | if (invoiceDetails != null)
|
|---|
| 99 | _repInvoiceDetails.Delete(invoiceDetails);
|
|---|
| 100 | }
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | public void CloseWebBrowser(IE ie)
|
|---|
| 104 | {
|
|---|
| 105 | ie.ForceClose();
|
|---|
| 106 | ie.Close();
|
|---|
| 107 | ie.Dispose();
|
|---|
| 108 | }
|
|---|
| 109 | }
|
|---|
| 110 | }
|
|---|