root/trunk/eCard/eCardMVC/adMoto.Payments.Test/UI/UIHelper.cs @ 992

Wersja 992, 5.0 KB (wprowadzona przez alina, 16 years temu)

re #215

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