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

Wersja 877, 4.8 KB (wprowadzona przez alina, 16 years temu)

re #215 rozdzielenie testow, modyfikacja testu dotycząca dodania potwierdzenia i edycji statusu platnosci,
zmiana wysłania formularza do eCardu

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            if (i == 1)
51            {
52                listaPlatnosci.Add(DodajPlatnosc(1000, "abcd", "12345"));
53                listaPl.Add(createNewPayment(9999, true, DateTime.Now, 1000));
54                listaPotwierdzenia.Add(DodajPotwierdzenie("000", 9999));
55            }
56            else if (i == 2)
57            {
58                listaPl.Add(createNewPayment(9999, true, DateTime.Now, 1000));
59            }
60        }
61        public IQueryable<T> GetTable<T>() where T : class
62        {
63            var query = from objects in lista   
64                    where typeof(T).IsAssignableFrom(objects.GetType())
65                    select objects;
66                return query.Select(o => (T)o).AsQueryable();
67        }
68        public void Insert<T>(T item) where T : class
69        {
70            lista.Add(item);
71        }
72        public void Delete<T>(T item) where T : class
73        {
74            lista.Remove(item);
75        }
76        public IQueryable<vPlatnosciEcard> FindInvoiceById(int id)
77            {
78            List<object> lp = lista;
79            for (int i = 0; i < lp.Count(); i++)
80            {
81                if (lp[i].GetType() == typeof(vPlatnosciEcard))
82                {
83                    listaPlatnosci.Add((vPlatnosciEcard)lp[i]);
84                }
85            }
86            lista.Clear();
87
88            var query = from l in listaPlatnosci
89                        where l.ID_faktury == id
90                            select l;
91               
92            return query.AsQueryable();
93            }
94        public IQueryable<vPlatnosciEcard> FindInvoiceByNipNumber(string nip, string numer)
95        {
96            List<object> lp = lista;
97            for (int i = 0; i < lp.Count(); i++)
98            {
99                if (lp[i].GetType() == typeof(vPlatnosciEcard))
100                {
101                    listaPlatnosci.Add((vPlatnosciEcard)lp[i]);
102                }
103            }
104            lista.Clear();
105
106            var query = from l in listaPlatnosci
107                        where l.nip == nip && l.Faktura_Numer == numer
108                        select l;
109
110            return query.AsQueryable();
111        }
112        public List<PotwierdzeniaEcard> FindItemsByIdFaktury(int idFaktury)
113        {
114            List<PotwierdzeniaEcard> listazaplaconych = new List<PotwierdzeniaEcard>();
115            for (int j = 0; j < listaPl.Count(); j++)
116            {
117                for (int i = 0; i < listaPotwierdzenia.Count(); i++)
118                {
119                    if (listaPl[j].IDFaktury == idFaktury && listaPl[j].ORDERNUMBER == listaPotwierdzenia[i].ORDERNUMBER && listaPotwierdzenia[i].VALIDATIONCODE == "000") listazaplaconych.Add(listaPotwierdzenia[i]);
120                }
121            }
122            return listazaplaconych;
123        }
124        public IQueryable<PlatnosciEcard> FindPaymentByOrdernumber(int ordernumber)
125        {
126            var query = from l in listaPl
127                        where l.ORDERNUMBER == ordernumber
128                        select l;
129
130            return query.AsQueryable();
131        }
132        public void SubmitChanges()
133        {
134           
135        }
136       
137    }
138}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.