root/trunk/eCard/eCardMVC/Platnosci.Tests/Web/FakeDataContext.cs @ 888

Wersja 888, 5.4 KB (wprowadzona przez alina, 16 years temu)

re #215

Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using Platnosci.Core.Interface;
6
7namespace Platnosci.Core.Linq
8{
9    public class FakeDataContext : IDataContext
10    {
11        private List<vPlatnosciEcard> listaPlatnosci = new List<vPlatnosciEcard>();
12        private List<PotwierdzeniaEcard> listaPotwierdzenia = new List<PotwierdzeniaEcard>();
13        private List<PlatnosciEcard> listaPl = new List<PlatnosciEcard>();
14        private List<object> lista = new List<object>();
15        private string code_Ok = "payment_deposited";        //transakcja potwierdzona do rozliczenia
16        private string code_Bad = "payment_declined";        //transakcja odrzucona
17
18        public vPlatnosciEcard DodajPlatnosc(int id, string numer, string nip)
19        {
20            vPlatnosciEcard p = new vPlatnosciEcard();
21            p.ID_faktury = id;
22            p.Faktura_Numer = numer;
23            p.nip = nip;
24           
25            return p;
26        }
27        public PotwierdzeniaEcard DodajPotwierdzenie(string code, int ordernumber)
28        {
29            PotwierdzeniaEcard potwierdzenie = new PotwierdzeniaEcard();
30            potwierdzenie.CURRENTSTATE = code;
31            potwierdzenie.ORDERNUMBER = ordernumber;
32
33            return potwierdzenie;
34        }
35        public PlatnosciEcard createNewPayment(int ordernumber, bool status, DateTime data, int id_faktury)
36        {
37            PlatnosciEcard platnosc = new PlatnosciEcard();
38            platnosc.ORDERNUMBER = ordernumber;
39            platnosc.Status = status;
40            platnosc.Status_data = data;
41            platnosc.IDFaktury = id_faktury;
42
43            return platnosc;
44        }
45        public FakeDataContext()
46        {
47            listaPlatnosci.Add(DodajPlatnosc(1,"1","123"));
48            listaPlatnosci.Add(DodajPlatnosc(2, "2", "aaa"));
49        }
50        //public FakeDataContext(int fake)
51        //{
52        //    if (fake == 1)
53        //    {
54        //        listaPlatnosci.Add(DodajPlatnosc(1000, "abcd", "12345"));
55        //        listaPl.Add(createNewPayment(9999, true, DateTime.Now, 1000));
56        //        listaPotwierdzenia.Add(DodajPotwierdzenie(code_Ok, 9999));
57        //    }
58        //    else if (fake == 2)
59        //    {
60        //        listaPl.Add(createNewPayment(9999, false, DateTime.Now, 1000));
61        //    }
62        //}
63
64
65        private readonly List<object> _dataStore = new List<object>();
66
67        public IQueryable<T> GetTable<T>() where T : class
68        {
69            var query = _dataStore.Where(objects => typeof(T).IsAssignableFrom(objects.GetType()));
70            return query.Select(o => (T)o).AsQueryable();
71        }
72
73        public void Insert<T>(T item) where T : class
74        {
75            _dataStore.Add(item);
76        }
77
78        public void Delete<T>(T item) where T : class
79        {
80            _dataStore.Remove(item);
81        }
82
83        public void SubmitChanges()
84        {
85            InvokeCompleted(EventArgs.Empty);
86        }
87
88        public event EventHandler Completed;
89
90        private void InvokeCompleted(EventArgs e)
91        {
92            var completedHandler = Completed;
93            if (completedHandler != null) completedHandler(this, e);
94        }
95
96        public void Dispose()
97        {
98        }
99
100        public IQueryable<vPlatnosciEcard> FindInvoiceById(int id)
101            {
102            List<object> lp = lista;
103            for (int i = 0; i < lp.Count(); i++)
104            {
105                if (lp[i].GetType() == typeof(vPlatnosciEcard))
106                {
107                    listaPlatnosci.Add((vPlatnosciEcard)lp[i]);
108                }
109            }
110            lista.Clear();
111
112            var query = from l in listaPlatnosci
113                        where l.ID_faktury == id
114                            select l;
115               
116            return query.AsQueryable();
117            }
118        public IQueryable<vPlatnosciEcard> FindInvoiceByNipNumber(string nip, string numer)
119        {
120            List<object> lp = lista;
121            for (int i = 0; i < lp.Count(); i++)
122            {
123                if (lp[i].GetType() == typeof(vPlatnosciEcard))
124                {
125                    listaPlatnosci.Add((vPlatnosciEcard)lp[i]);
126                }
127            }
128            lista.Clear();
129
130            var query = from l in listaPlatnosci
131                        where l.nip == nip && l.Faktura_Numer == numer
132                        select l;
133
134            return query.AsQueryable();
135        }
136        public List<PotwierdzeniaEcard> FindItemsByIdFaktury(int idFaktury)
137        {
138            List<PotwierdzeniaEcard> listazaplaconych = new List<PotwierdzeniaEcard>();
139            for (int j = 0; j < listaPl.Count(); j++)
140            {
141                for (int i = 0; i < listaPotwierdzenia.Count(); i++)
142                {
143                    if (listaPl[j].IDFaktury == idFaktury && listaPl[j].ORDERNUMBER == listaPotwierdzenia[i].ORDERNUMBER && listaPotwierdzenia[i].CURRENTSTATE == code_Ok) listazaplaconych.Add(listaPotwierdzenia[i]);
144                }
145            }
146            return listazaplaconych;
147        }
148        public IQueryable<PlatnosciEcard> FindPaymentByOrdernumber(int ordernumber)
149        {
150            var query = from l in listaPl
151                        where l.ORDERNUMBER == ordernumber
152                        select l;
153
154            return query.AsQueryable();
155        }
156    }
157}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.