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

Wersja 872, 4.1 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
16        public vPlatnosciEcard DodajPlatnosc(int id, string numer, string nip)
17        {
18            vPlatnosciEcard p = new vPlatnosciEcard();
19            p.ID_faktury = id;
20            p.Faktura_Numer = numer;
21            p.nip = nip;
22           
23            return p;
24        }
25        public PotwierdzeniaEcard DodajPotwierdzenie(string code, int ordernumber)
26        {
27            PotwierdzeniaEcard potwierdzenie = new PotwierdzeniaEcard();
28            potwierdzenie.VALIDATIONCODE = code;
29            potwierdzenie.ORDERNUMBER = ordernumber;
30
31            return potwierdzenie;
32        }
33        public PlatnosciEcard createNewPayment(int ordernumber, bool status, DateTime data, int id_faktury)
34        {
35            PlatnosciEcard platnosc = new PlatnosciEcard();
36            platnosc.ORDERNUMBER = ordernumber;
37            platnosc.Status = status;
38            platnosc.Status_data = data;
39            platnosc.IDFaktury = id_faktury;
40
41            return platnosc;
42        }
43        public FakeDataContext()
44        {
45            listaPlatnosci.Add(DodajPlatnosc(1,"1","123"));
46            listaPlatnosci.Add(DodajPlatnosc(2, "2", "aaa"));
47        }
48        public FakeDataContext(int i)
49        {
50            listaPlatnosci.Add(DodajPlatnosc(128, "numerfaktury", "nip"));
51            listaPl.Add(createNewPayment(158, true, DateTime.Now, 128));           
52            listaPotwierdzenia.Add(DodajPotwierdzenie("000", 158));
53        }
54        public IQueryable<T> GetTable<T>() where T : class
55        {
56            var query = from objects in lista   
57                    where typeof(T).IsAssignableFrom(objects.GetType())
58                    select objects;
59                return query.Select(o => (T)o).AsQueryable();
60        }
61        public void Insert<T>(T item) where T : class
62        {
63            lista.Add(item);
64        }
65        public void Delete<T>(T item) where T : class
66        {
67            lista.Remove(item);
68        }
69        public IQueryable<vPlatnosciEcard> FindInvoiceById(int id)
70            {
71            List<object> lp = lista;
72            for (int i = 0; i < lp.Count(); i++)
73            {
74                if (lp[i].GetType() == typeof(vPlatnosciEcard))
75                {
76                    listaPlatnosci.Add((vPlatnosciEcard)lp[i]);
77                }
78            }
79            lista.Clear();
80
81            var query = from l in listaPlatnosci
82                        where l.ID_faktury == id
83                            select l;
84               
85            return query.AsQueryable();
86            }
87        public IQueryable<vPlatnosciEcard> FindInvoiceByNipNumber(string nip, string numer)
88        {
89            var query = from l in listaPlatnosci
90                        where l.nip == nip && l.Faktura_Numer == numer
91                        select l;
92
93            return query.AsQueryable();
94        }
95        public List<PotwierdzeniaEcard> FindItemsByIdFaktury(int idFaktury)
96        {
97            List<PotwierdzeniaEcard> listazaplaconych = new List<PotwierdzeniaEcard>();
98            for (int j = 0; j < listaPl.Count(); j++)
99            {
100                for (int i = 0; i < listaPotwierdzenia.Count(); i++)
101                {
102                    if (listaPl[j].IDFaktury == idFaktury && listaPl[j].ORDERNUMBER == listaPotwierdzenia[i].ORDERNUMBER && listaPotwierdzenia[i].VALIDATIONCODE == "000") listazaplaconych.Add(listaPotwierdzenia[i]);
103                }
104            }
105            return listazaplaconych;
106        }
107        public void SubmitChanges()
108        {
109           
110        }
111       
112    }
113}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.