Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using GestDepLib.Persistence;
  7. using GestDepLib.Entities;
  8. using GestDepLib.Services;
  9.  
  10.  
  11. namespace BusinessLogicTestApp
  12. {
  13. class Program
  14. {
  15. static void Main(string[] args)
  16. {
  17. try
  18. {
  19. IGestDepService service = new GestDepService(new EntityFrameworkDAL(new GestDepDbContext()));
  20.  
  21. new Program(service);
  22. }
  23. catch (Exception e)
  24. {
  25. printError(e);
  26. }
  27.  
  28. }
  29.  
  30. private IGestDepService service;
  31.  
  32. Program(IGestDepService service)
  33. {
  34. this.service = service;
  35.  
  36. service.removeAllData();
  37.  
  38. // Adding Pool and Lanes
  39. addPoolAndLanes();
  40. Console.WriteLine("Press any key to continue...");
  41. Console.ReadKey();
  42.  
  43. // Adding Courses
  44. addCourses();
  45. Console.WriteLine("Press any key to continue...");
  46. Console.ReadKey();
  47.  
  48.  
  49. // Adding Monitor
  50. addMonitor();
  51. Console.WriteLine("Press any key to continue...");
  52. Console.ReadKey();
  53.  
  54.  
  55. // Adding Users and Enrollments
  56. addUsers();
  57. Console.WriteLine("Press any key to continue...");
  58. Console.ReadKey();
  59.  
  60. // Adding payments
  61. addPayments();
  62. Console.WriteLine("Press any key to continue...");
  63. Console.ReadKey();
  64.  
  65. // Testing Free Lanes
  66. testingFreeLanes();
  67. Console.Out.WriteLine("\nPress any key to finish.");
  68. Console.In.ReadLine();
  69.  
  70. }
  71.  
  72.  
  73. static void printError(Exception e)
  74. {
  75. while (e != null)
  76. {
  77. Console.WriteLine("ERROR: " + e.Message);
  78. e = e.InnerException;
  79. }
  80. }
  81.  
  82. void addPoolAndLanes()
  83. {
  84. Console.WriteLine();
  85. Console.WriteLine("ADDING POOL AND LANES...");
  86.  
  87. try
  88. {
  89. // Pool(int id, DateTime OpeningHour, DateTime ClosingHour, int ZipCode, int discountLocal, int discountRetired, double freeSwimPrice)
  90. // Id is not autogenerated
  91. Pool pool = new Pool( Convert.ToDateTime("08:00:00"), Convert.ToDateTime("14:00:00"), 46122, 1, 5, 5, 2);
  92. for (int i = 1; i < 7; i++)
  93. {
  94. pool.addLane(new Lane(i));
  95. }
  96. service.addPool(pool);
  97.  
  98. foreach(Pool p in service.getAllPools())
  99. {
  100. Console.WriteLine(" Pool " + p.Id);
  101. foreach (Lane l in p.Lanes)
  102. Console.WriteLine(" Lane " + l.Number);
  103. }
  104.  
  105. }
  106. catch(Exception e)
  107. {
  108. printError(e);
  109. }
  110. }
  111.  
  112. void addCourses()
  113. {
  114. Console.WriteLine();
  115. Console.WriteLine("ADDING COURSES AND ASSIGNING LANES...");
  116.  
  117. try
  118. {
  119. // Course(String description, DateTime startDate, DateTime finishDate, DateTime startHour, TimeSpan duration, Days courseDays, int minimunEnrollments, int maximunEnrollments, bool cancelled, double price)
  120. Course c = new Course(false, Days.Monday | Days.Wednesday | Days.Friday, "Learning with M. Phelps", new TimeSpan(0, 45, 0), new DateTime(2018, 6, 29), 20, 6, 100, new DateTime(2017, 9, 4), Convert.ToDateTime("09:30:00")
  121.  
  122. );
  123. service.addCourse(c);
  124.  
  125. Console.WriteLine(" Course days: " + c.CourseDays);
  126. if ((c.CourseDays & Days.Friday) == Days.Friday)
  127. Console.WriteLine(" Course on Friday");
  128. else
  129. Console.WriteLine(" Course is NOT on Friday");
  130.  
  131. // Adding lanes for a Course
  132. Pool p = service.findPoolById(1); // ¡¡¡¡¡¡¡ Assuming that Id is not autogenerated !!!!!!
  133. c.addLane(p.findLane(3));
  134. c.addLane(p.findLane(4));
  135. c.addLane(p.findLane(5));
  136. service.saveChanges();
  137.  
  138.  
  139. // Testing Lanes assigned
  140. Console.WriteLine("\n Lanes assigned");
  141. foreach (Lane la in c.Lanes)
  142. Console.WriteLine(" " + la.Number + " assigned");
  143.  
  144. // Adding another Course
  145. c = new Course(false, Days.Monday | Days.Wednesday | Days.Friday, "201 - Swimming", new TimeSpan(0, 45, 0), new DateTime(2018, 3, 30), 20, 6, 100, new DateTime(2018, 1, 6), Convert.ToDateTime("09:30:00")
  146.  
  147. );
  148. service.addCourse(c);
  149.  
  150. // Adding lanes for a Course
  151. p = service.findPoolById(1); // ¡¡¡¡¡¡¡ Assuming that Id is not autogenerated !!!!!!
  152. c.addLane(p.findLane(1));
  153. c.addLane(p.findLane(6));
  154. service.saveChanges();
  155.  
  156. }
  157. catch (Exception e)
  158. {
  159. printError(e);
  160. }
  161.  
  162. }
  163.  
  164. void addMonitor()
  165. {
  166. Console.WriteLine();
  167. Console.WriteLine("ADDING MONITOR...");
  168.  
  169. try
  170. {
  171. // Monitor(string id, string Name, string Address, int ZipCode, string IBAN, string Ssn)
  172. Monitor m = new Monitor(" Michael Phelps'address", "ES891234121234567890", "X-00000001", "Michael Phelps", 46001, "SSN01010101");
  173. service.addMonitor(m);
  174.  
  175. Course c = service.findCourseByName("Learning with M. Phelps");
  176. c.setMonitor(m);
  177. service.saveChanges();
  178. Console.WriteLine(" " + c.Monitor.Name + " assigned to " + c.Description + " course");
  179.  
  180. // Add the same monitor to another course with collision dates
  181. // Must fails by collision dates
  182. c = service.findCourseByName("201 - Swimming");
  183. c.setMonitor(m);
  184. service.saveChanges();
  185. Console.WriteLine(" " + c.Monitor.Name + " assigned to " + c.Description + " course");
  186.  
  187.  
  188. }
  189. catch (Exception e)
  190. {
  191. printError(e);
  192. }
  193. }
  194.  
  195. void addUsers()
  196. {
  197. Console.WriteLine();
  198. Console.WriteLine("ADDING USERS...");
  199.  
  200. try
  201. {
  202. Course c = service.findCourseByName("Learning with M. Phelps");
  203.  
  204. // User(string id, string name, string address, int zipCode, string IBAN, DateTime birthDate, bool retired)
  205. User u = new User("Ona Carbonell's address", "ES891234121234567890", "1234567890", "Ona Carbonell", 46002, new DateTime(1990, 6, 5), false);
  206. service.enrollUserToCourse(new DateTime(2017, 08, 16), u, c);
  207.  
  208. u = new User("Gemma Mengual's address","ES891234121234567890", "2345678901", "Gemma Mengual", 46002, new DateTime(1977, 4, 12), false);
  209. service.enrollUserToCourse(new DateTime(2017, 07, 26), u, c);
  210.  
  211. u = new User("Mireia Belmonte's address", "ES891234121234567890", "3456789012", "Mireia Belmonte", 46003, new DateTime(1990, 11, 10), false);
  212. service.enrollUserToCourse(new DateTime(2017, 08, 28), u, c);
  213.  
  214. u = new User("Rigoberto's address", "ES891234121234567890", "4567890123", "Rigoberto", 46122, new DateTime(1995, 2, 28), false);
  215. service.enrollUserToCourse(new DateTime(2017, 08, 28), u, c);
  216.  
  217. u = new User("Lázaro's address", "ES891234121234567890", "5678901234", "Lázaro", 46122, new DateTime(1900, 1, 1), true);
  218. service.enrollUserToCourse(new DateTime(2017, 08, 29), u, c);
  219.  
  220. // Checking Users enrolled
  221. Console.WriteLine(" Users enrolled in course with monitor " + c.Monitor.Name);
  222. foreach (Enrollment en in c.Enrollments)
  223. Console.WriteLine(" " + en.User.Name + " enrolled");
  224.  
  225. }
  226. catch (Exception e)
  227. {
  228. printError(e);
  229. }
  230. }
  231.  
  232. void addPayments()
  233. {
  234. Console.WriteLine();
  235. Console.WriteLine("ADDING PAYMENTS...");
  236.  
  237. try
  238. {
  239.  
  240. service.addFreeSwimPayment(new DateTime(2017, 8, 10, 18, 12, 5));
  241.  
  242. service.addFreeSwimPayment(new DateTime(2017, 8, 20, 18, 12, 5));
  243.  
  244. service.addFreeSwimPayment(new DateTime(2017, 8, 20, 18, 13, 5));
  245.  
  246. // Adding Payments
  247. Course c = service.findCourseByName("Learning with M. Phelps");
  248.  
  249. Enrollment e = c.findEnrollment("1234567890");
  250. service.addPayment(e, new DateTime(2017, 8, 16, 12, 30, 0));
  251. service.addPayment(e, new DateTime(2017, 8, 17, 13, 30, 1));
  252.  
  253.  
  254. e = c.findEnrollment("5678901234");
  255. service.addPayment(e, new DateTime(2017, 09, 29));
  256.  
  257.  
  258.  
  259. // Testing Payments
  260. foreach (Enrollment en in service.getAllEnrollments())
  261. {
  262. Console.WriteLine("\n Payments attached to " + en.User.Name);
  263. foreach (Payment moO in en.Payments)
  264. Console.WriteLine(" " + moO.Description + " " + moO.Quantity);
  265. }
  266.  
  267. Console.WriteLine("\n Free Swim payments");
  268. foreach (Payment p in service.getAllFreeSwimPayments())
  269. Console.WriteLine(" " + p.Quantity + " " + p.Date );
  270.  
  271. }
  272. catch (Exception e)
  273. {
  274. printError(e);
  275. }
  276. }
  277.  
  278. void testingFreeLanes()
  279. {
  280. Console.WriteLine();
  281. Console.WriteLine("TESTING FREE LANES");
  282.  
  283. try
  284. {
  285. // Test free lanes week 2018, 1, 29
  286. Pool p = service.findPoolById(1);
  287.  
  288. int freeLanes = p.getFreeLanes(new DateTime(2018, 1, 29, 8, 00, 0), Days.Monday);
  289. Console.WriteLine(" Free lanes at 8:00 - " + freeLanes);
  290.  
  291. freeLanes = p.getFreeLanes(new DateTime(2018, 1, 29, 9, 30, 0), Days.Monday);
  292. Console.WriteLine(" Free lanes at 9:30 - " + freeLanes);
  293.  
  294. }
  295. catch (Exception e)
  296. {
  297. printError(e);
  298. }
  299. }
  300.  
  301.  
  302.  
  303.  
  304. }
  305.  
  306. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement